Back to project page GreenGear.
The source code is released under:
MIT License
If you think the Android project GreenGear listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bradleycurran.viewquery; //from ww w . j a v a2 s.c o m import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.TextView; abstract class Operation<T extends View> { private static final String TAG = Operation.class.getSimpleName(); private Class<T> mClass; Operation(Class<T> cls) { mClass = cls; } void run(View view) { T t = get(view, mClass); if (t != null) { execute(t); } } abstract void execute(T view); static abstract class ViewOperation extends Operation<View> { public ViewOperation() { super(View.class); } } static abstract class ImageOperation extends Operation<ImageView> { public ImageOperation() { super(ImageView.class); } } static abstract class TextOperation extends Operation<TextView> { public TextOperation() { super(TextView.class); } } @SuppressWarnings("rawtypes") static abstract class AdapterOperation extends Operation<AdapterView> { AdapterOperation() { super(AdapterView.class); } } static <T extends View> T get(View view, Class<T> cls) { if (view == null) { Log.e(TAG, "View is null, cannot perform " + cls.getSimpleName()); return null; } if (!cls.isInstance(view)) { Log.e(TAG, "View is not a " + cls.getSimpleName()); return null; } return cls.cast(view); } }