1

I have done a lot of search over the topic and have even referred the official documentation from android developer website. But still not clear with the concept.

I have read that for implementing the touch gestures i need to use the GestureDetector and MotionEvent packages. But its implementation kept me confusing over the things.

What i simply want is, my layout includes a many of textviews along with two imageviews. I want to detect a double tap on my images and want to start a new fragment activity. In the new fragment activity i want to show the same image in full screen in landscape mode.

I have done ton of reading but it kept me confusing. Please help. Thank you

user3794646
  • 23
  • 1
  • 10

1 Answers1

2

Here is Double Tap Gesture ImageView.

public class CustomImageView extends ImageView {
    private Context context;
    private GestureListener mGestureListener;
    private GestureDetector mGestureDetector;

    public CustomImageView(Context context) {
        super(context);
        sharedConstructing(context);
    }

    public CustomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        sharedConstructing(context);
    }

    public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        sharedConstructing(context);
    }

    private void sharedConstructing(Context context) {
        super.setClickable(true);
        this.context = context;
        mGestureListener=new GestureListener();
        Log.e("Adding", "Listener:::");
        mGestureDetector = new GestureDetector(context, mGestureListener, null, true);
        setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mGestureDetector.onTouchEvent(event);
                //..my other code logic
                invalidate();
                return true; // indicate event was handled
            }

        });
    }

    public class GestureListener extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDoubleTap( MotionEvent e ) {
            // TODO DoubleTap Comparison 
            Log.e("onDoubleTap","onDoubleTap");
            return true;
        }
    }

}

Reference Link

Community
  • 1
  • 1
SilentKiller
  • 6,944
  • 6
  • 40
  • 75
  • i want to add it on specific imageview objects. will the above code work in desired direction? – user3794646 Aug 30 '14 at 05:54
  • I want to do something like android does in settings to go into Developer mode. How that can be implemented. If user taps 7 times on a imageview or any view. Then only do certain thing otherwise nothing. – soan saini Jan 30 '18 at 01:04