Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created October 7, 2014 16:36
Show Gist options
  • Save easternHong/a753a7dea50b82499f66 to your computer and use it in GitHub Desktop.
Save easternHong/a753a7dea50b82499f66 to your computer and use it in GitHub Desktop.
onTouch_DoubleTap
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (MotionEvent.ACTION_DOWN == event.getAction()) {
if (mCurrentDownEvent != null
&& mPreviousUpEvent != null
&& isConsiderAsDoubleTap(mCurrentDownEvent,
mPreviousUpEvent, event)) {
}
mCurrentDownEvent = MotionEvent.obtain(event);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
System.out.println("once ");
mPreviousUpEvent = MotionEvent.obtain(event);
}
return true;
}
private boolean isConsiderAsDoubleTap(MotionEvent firstDown,
MotionEvent firstUp, MotionEvent secondDown) {
// TODO Auto-generated method stub
if (secondDown.getEventTime() - firstUp.getEventTime() > DOUBLE_TAP_TIMEOUT) {
return false;
}
int deltaX = (int) firstUp.getX() - (int) secondDown.getX();
int deltaY = (int) firstUp.getY() - (int) secondDown.getY();
return deltaX * deltaX + deltaY * deltaY < 10000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment