Skip to content

Instantly share code, notes, and snippets.

@d0minicw0ng
Created December 21, 2014 09:56
Show Gist options
  • Save d0minicw0ng/f69691f856e6a8076b87 to your computer and use it in GitHub Desktop.
Save d0minicw0ng/f69691f856e6a8076b87 to your computer and use it in GitHub Desktop.
Android DoubleTap Listener from codepath Android bootcamp
/*
Usage:
myView.setOnTouchListener(new OnDoubleTapListener(this) {
@Override
public void onDoubleTap(MotionEvent e) {
Toast.makeText(MainActivity.this, "Double Tap", Toast.LENGTH_SHORT).show();
}
});
*/
public class OnDoubleTapListener implements OnTouchListener {
private GestureDetector gestureDetector;
public OnDoubleTapListener(Context c) {
gestureDetector = new GestureDetector(c, new GestureListener());
}
public boolean onTouch(final View view, final MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent);
}
private final class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
OnDoubleTapListener.this.onDoubleTap(e);
return super.onDoubleTap(e);
}
}
public void onDoubleTap(MotionEvent e) {
// To be overridden when implementing listener
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment