diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 14:04:24 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 14:04:24 -0800 |
commit | 076357b8567458d4b6dfdcf839ef751634cd2bfb (patch) | |
tree | efbb2fd6f1dc67d2d606382fc3b82983e7cb2e1f /core/java/android/view/GestureDetector.java | |
parent | 3dec7d563a2f3e1eb967ce2054a00b6620e3558c (diff) | |
download | frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.zip frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.gz frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.bz2 |
auto import from //depot/cupcake/@132589
Diffstat (limited to 'core/java/android/view/GestureDetector.java')
-rw-r--r-- | core/java/android/view/GestureDetector.java | 91 |
1 files changed, 20 insertions, 71 deletions
diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index e0231a7..679c683 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -113,48 +113,20 @@ public class GestureDetector { } /** - * The listener that is used to notify when a double-tap or a confirmed - * single-tap occur. + * @hide pending API council */ public interface OnDoubleTapListener { - /** - * Notified when a single-tap occurs. - * <p> - * Unlike {@link OnGestureListener#onSingleTapUp(MotionEvent)}, this - * will only be called after the detector is confident that the user's - * first tap is not followed by a second tap leading to a double-tap - * gesture. - * - * @param e The down motion event of the single-tap. - * @return true if the event is consumed, else false - */ boolean onSingleTapConfirmed(MotionEvent e); - - /** - * Notified when a double-tap occurs. - * - * @param e The down motion event of the first tap of the double-tap. - * @return true if the event is consumed, else false - */ - boolean onDoubleTap(MotionEvent e); - - /** - * Notified when an event within a double-tap gesture occurs, including - * the down, move, and up events. - * - * @param e The motion event that occurred during the double-tap gesture. - * @return true if the event is consumed, else false - */ boolean onDoubleTapEvent(MotionEvent e); } - + /** - * A convenience class to extend when you only want to listen for a subset - * of all the gestures. This implements all methods in the - * {@link OnGestureListener} and {@link OnDoubleTapListener} but does - * nothing and return {@code false} for all applicable methods. + * A convenience class to extend when you only want to listen for a + * subset of all the gestures. This implements all methods in the + * {@link OnGestureListener} but does nothing and return {@code false} + * for all applicable methods. */ - public static class SimpleOnGestureListener implements OnGestureListener, OnDoubleTapListener { + public static class SimpleOnGestureListener implements OnGestureListener { public boolean onSingleTapUp(MotionEvent e) { return false; } @@ -178,25 +150,13 @@ public class GestureDetector { public boolean onDown(MotionEvent e) { return false; } - - public boolean onDoubleTap(MotionEvent e) { - return false; - } - - public boolean onDoubleTapEvent(MotionEvent e) { - return false; - } - - public boolean onSingleTapConfirmed(MotionEvent e) { - return false; - } } // TODO: ViewConfiguration private int mBiggerTouchSlopSquare = 20 * 20; - + private int mTouchSlopSquare; - private int mDoubleTapSlopSquare; + private int mDoubleTapSlopSquare; private int mMinimumFlingVelocity; private static final int LONGPRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout(); @@ -204,7 +164,7 @@ public class GestureDetector { // TODO make new double-tap timeout, and define its events (i.e. either time // between down-down or time between up-down) private static final int DOUBLE_TAP_TIMEOUT = ViewConfiguration.getDoubleTapTimeout(); - + // constants for Message.what used by GestureHandler below private static final int SHOW_PRESS = 1; private static final int LONG_PRESS = 2; @@ -221,13 +181,13 @@ public class GestureDetector { private MotionEvent mCurrentDownEvent; private MotionEvent mPreviousUpEvent; - + /** * True when the user is still touching for the second tap (down, move, and * up events). Can only be true if there is a double tap listener attached. */ private boolean mIsDoubleTapping; - + private float mLastMotionY; private float mLastMotionX; @@ -266,7 +226,7 @@ public class GestureDetector { break; default: - throw new RuntimeException("Unknown message " + msg); //never + throw new RuntimeException("Unknown message " + msg); //never } } } @@ -343,9 +303,6 @@ public class GestureDetector { mHandler = new GestureHandler(); } mListener = listener; - if (listener instanceof OnDoubleTapListener) { - setOnDoubleTapListener((OnDoubleTapListener) listener); - } init(context); } @@ -374,11 +331,8 @@ public class GestureDetector { } /** - * Sets the listener which will be called for double-tap and related - * gestures. - * - * @param onDoubleTapListener the listener invoked for all the callbacks, or - * null to stop listening for double-tap gestures. + * @hide pending API council + * @param onDoubleTapListener */ public void setOnDoubleTapListener(OnDoubleTapListener onDoubleTapListener) { mDoubleTapListener = onDoubleTapListener; @@ -433,10 +387,7 @@ public class GestureDetector { isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev)) { // This is a second tap mIsDoubleTapping = true; - // Give a callback with the first tap of the double-tap - handled |= mDoubleTapListener.onDoubleTap(mCurrentDownEvent); - // Give a callback with down event of the double-tap - handled |= mDoubleTapListener.onDoubleTapEvent(ev); + handled = mDoubleTapListener.onDoubleTapEvent(ev); } else { // This is a first tap mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT); @@ -467,8 +418,7 @@ public class GestureDetector { final float scrollX = mLastMotionX - x; final float scrollY = mLastMotionY - y; if (mIsDoubleTapping) { - // Give the move events of the double-tap - handled |= mDoubleTapListener.onDoubleTapEvent(ev); + handled = mDoubleTapListener.onDoubleTapEvent(ev); } else if (mAlwaysInTapRegion) { final int deltaX = (int) (x - mCurrentDownEvent.getX()); final int deltaY = (int) (y - mCurrentDownEvent.getY()); @@ -496,8 +446,7 @@ public class GestureDetector { mStillDown = false; MotionEvent currentUpEvent = MotionEvent.obtain(ev); if (mIsDoubleTapping) { - // Finally, give the up event of the double-tap - handled |= mDoubleTapListener.onDoubleTapEvent(ev); + handled = mDoubleTapListener.onDoubleTapEvent(ev); mIsDoubleTapping = false; break; } else if (mInLongPress) { @@ -546,7 +495,7 @@ public class GestureDetector { if (!mAlwaysInBiggerTapRegion) { return false; } - + if (secondDown.getEventTime() - firstUp.getEventTime() > DOUBLE_TAP_TIMEOUT) { return false; } @@ -555,7 +504,7 @@ public class GestureDetector { int deltaY = (int) firstDown.getY() - (int) secondDown.getY(); return (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare); } - + private void dispatchLongPress() { mHandler.removeMessages(TAP); mInLongPress = true; |