Created
October 7, 2014 16:36
-
-
Save easternHong/a753a7dea50b82499f66 to your computer and use it in GitHub Desktop.
onTouch_DoubleTap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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