diff options
author | Mady Mellor <madym@google.com> | 2015-06-05 14:41:22 -0700 |
---|---|---|
committer | Mady Mellor <madym@google.com> | 2015-06-05 14:41:22 -0700 |
commit | 015020eb3abb212bf7f033416fbdec572287e092 (patch) | |
tree | e9d19a311770f0feb6f1dc00ed25c823631b9c4e | |
parent | e1352de673423264c00c71c0ec1597bbdad6fd03 (diff) | |
download | frameworks_base-015020eb3abb212bf7f033416fbdec572287e092.zip frameworks_base-015020eb3abb212bf7f033416fbdec572287e092.tar.gz frameworks_base-015020eb3abb212bf7f033416fbdec572287e092.tar.bz2 |
Change stylus button press to context click in GD - API review feedback
Based on API review feedback we should use onContextClick instead of
onStylusButtonPress. This CL updates associated methods and usage
in GestureDetector.
Additionally listens for mouse right clicks and calls the
onContextClick method for these as well.
Bug: 21572278
Change-Id: I4fa01997bff7265d5d2713353a93e07417a148e5
-rw-r--r-- | api/current.txt | 14 | ||||
-rw-r--r-- | api/system-current.txt | 14 | ||||
-rw-r--r-- | core/java/android/view/GestureDetector.java | 66 |
3 files changed, 45 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt index 7da4090..a19c314 100644 --- a/api/current.txt +++ b/api/current.txt @@ -34752,9 +34752,13 @@ package android.view { method public boolean isLongpressEnabled(); method public boolean onGenericMotionEvent(android.view.MotionEvent); method public boolean onTouchEvent(android.view.MotionEvent); + method public void setContextClickListener(android.view.GestureDetector.OnContextClickListener); method public void setIsLongpressEnabled(boolean); method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener); - method public void setOnStylusButtonPressListener(android.view.GestureDetector.OnStylusButtonPressListener); + } + + public static abstract interface GestureDetector.OnContextClickListener { + method public abstract boolean onContextClick(android.view.MotionEvent); } public static abstract interface GestureDetector.OnDoubleTapListener { @@ -34772,12 +34776,9 @@ package android.view { method public abstract boolean onSingleTapUp(android.view.MotionEvent); } - public static abstract interface GestureDetector.OnStylusButtonPressListener { - method public abstract boolean onStylusButtonPress(android.view.MotionEvent); - } - - public static class GestureDetector.SimpleOnGestureListener implements android.view.GestureDetector.OnDoubleTapListener android.view.GestureDetector.OnGestureListener android.view.GestureDetector.OnStylusButtonPressListener { + public static class GestureDetector.SimpleOnGestureListener implements android.view.GestureDetector.OnContextClickListener android.view.GestureDetector.OnDoubleTapListener android.view.GestureDetector.OnGestureListener { ctor public GestureDetector.SimpleOnGestureListener(); + method public boolean onContextClick(android.view.MotionEvent); method public boolean onDoubleTap(android.view.MotionEvent); method public boolean onDoubleTapEvent(android.view.MotionEvent); method public boolean onDown(android.view.MotionEvent); @@ -34787,7 +34788,6 @@ package android.view { method public void onShowPress(android.view.MotionEvent); method public boolean onSingleTapConfirmed(android.view.MotionEvent); method public boolean onSingleTapUp(android.view.MotionEvent); - method public boolean onStylusButtonPress(android.view.MotionEvent); } public class Gravity { diff --git a/api/system-current.txt b/api/system-current.txt index 319ad00..145a1bc 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -37017,9 +37017,13 @@ package android.view { method public boolean isLongpressEnabled(); method public boolean onGenericMotionEvent(android.view.MotionEvent); method public boolean onTouchEvent(android.view.MotionEvent); + method public void setContextClickListener(android.view.GestureDetector.OnContextClickListener); method public void setIsLongpressEnabled(boolean); method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener); - method public void setOnStylusButtonPressListener(android.view.GestureDetector.OnStylusButtonPressListener); + } + + public static abstract interface GestureDetector.OnContextClickListener { + method public abstract boolean onContextClick(android.view.MotionEvent); } public static abstract interface GestureDetector.OnDoubleTapListener { @@ -37037,12 +37041,9 @@ package android.view { method public abstract boolean onSingleTapUp(android.view.MotionEvent); } - public static abstract interface GestureDetector.OnStylusButtonPressListener { - method public abstract boolean onStylusButtonPress(android.view.MotionEvent); - } - - public static class GestureDetector.SimpleOnGestureListener implements android.view.GestureDetector.OnDoubleTapListener android.view.GestureDetector.OnGestureListener android.view.GestureDetector.OnStylusButtonPressListener { + public static class GestureDetector.SimpleOnGestureListener implements android.view.GestureDetector.OnContextClickListener android.view.GestureDetector.OnDoubleTapListener android.view.GestureDetector.OnGestureListener { ctor public GestureDetector.SimpleOnGestureListener(); + method public boolean onContextClick(android.view.MotionEvent); method public boolean onDoubleTap(android.view.MotionEvent); method public boolean onDoubleTapEvent(android.view.MotionEvent); method public boolean onDown(android.view.MotionEvent); @@ -37052,7 +37053,6 @@ package android.view { method public void onShowPress(android.view.MotionEvent); method public boolean onSingleTapConfirmed(android.view.MotionEvent); method public boolean onSingleTapUp(android.view.MotionEvent); - method public boolean onStylusButtonPress(android.view.MotionEvent); } public class Gravity { diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index ff0af6b..b705cf1 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -32,7 +32,7 @@ import android.os.Message; * <li>In the {@link View#onTouchEvent(MotionEvent)} method ensure you call * {@link #onTouchEvent(MotionEvent)}. The methods defined in your callback * will be executed when the events occur. - * <li>If listening for {@link OnStylusButtonPressListener#onStylusButtonPress(MotionEvent)} + * <li>If listening for {@link OnContextClickListener#onContextClick(MotionEvent)} * you must call {@link #onGenericMotionEvent(MotionEvent)} * in {@link View#onGenericMotionEvent(MotionEvent)}. * </ul> @@ -152,31 +152,28 @@ public class GestureDetector { } /** - * The listener that is used to notify when a stylus button press occurs. When listening for a - * stylus button press ensure that you call {@link #onGenericMotionEvent(MotionEvent)} in + * The listener that is used to notify when a context click occurs. When listening for a + * context click ensure that you call {@link #onGenericMotionEvent(MotionEvent)} in * {@link View#onGenericMotionEvent(MotionEvent)}. */ - public interface OnStylusButtonPressListener { + public interface OnContextClickListener { /** - * Notified when a stylus button press occurs. This is when the stylus - * is touching the screen and the {@value MotionEvent#BUTTON_STYLUS_PRIMARY} - * is pressed. + * Notified when a context click occurs. * - * @param e The motion event that occurred during the stylus button - * press. + * @param e The motion event that occurred during the context click. * @return true if the event is consumed, else false */ - boolean onStylusButtonPress(MotionEvent e); + boolean onContextClick(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}, {@link OnDoubleTapListener}, and {@link OnStylusButtonPressListener} + * {@link OnGestureListener}, {@link OnDoubleTapListener}, and {@link OnContextClickListener} * but does nothing and return {@code false} for all applicable methods. */ public static class SimpleOnGestureListener implements OnGestureListener, OnDoubleTapListener, - OnStylusButtonPressListener { + OnContextClickListener { public boolean onSingleTapUp(MotionEvent e) { return false; @@ -214,7 +211,7 @@ public class GestureDetector { return false; } - public boolean onStylusButtonPress(MotionEvent e) { + public boolean onContextClick(MotionEvent e) { return false; } } @@ -238,12 +235,12 @@ public class GestureDetector { private final Handler mHandler; private final OnGestureListener mListener; private OnDoubleTapListener mDoubleTapListener; - private OnStylusButtonPressListener mStylusButtonListener; + private OnContextClickListener mContextClickListener; private boolean mStillDown; private boolean mDeferConfirmSingleTap; private boolean mInLongPress; - private boolean mInStylusButtonPress; + private boolean mInContextClick; private boolean mAlwaysInTapRegion; private boolean mAlwaysInBiggerTapRegion; private boolean mIgnoreNextUpEvent; @@ -388,8 +385,8 @@ public class GestureDetector { if (listener instanceof OnDoubleTapListener) { setOnDoubleTapListener((OnDoubleTapListener) listener); } - if (listener instanceof OnStylusButtonPressListener) { - setOnStylusButtonPressListener((OnStylusButtonPressListener) listener); + if (listener instanceof OnContextClickListener) { + setContextClickListener((OnContextClickListener) listener); } init(context); } @@ -453,16 +450,13 @@ public class GestureDetector { } /** - * Sets the listener which will be called for stylus button related - * gestures. + * Sets the listener which will be called for context clicks. * - * @param onStylusButtonPressListener the listener invoked for all the - * callbacks, or null to stop listening for stylus button - * gestures. + * @param onContextClickListener the listener invoked for all the callbacks, or null to stop + * listening for context clicks. */ - public void setOnStylusButtonPressListener( - OnStylusButtonPressListener onStylusButtonPressListener) { - mStylusButtonListener = onStylusButtonPressListener; + public void setContextClickListener(OnContextClickListener onContextClickListener) { + mContextClickListener = onContextClickListener; } /** @@ -597,7 +591,7 @@ public class GestureDetector { break; case MotionEvent.ACTION_MOVE: - if (mInLongPress || mInStylusButtonPress) { + if (mInLongPress || mInContextClick) { break; } final float scrollX = mLastFocusX - focusX; @@ -698,12 +692,14 @@ public class GestureDetector { mInputEventConsistencyVerifier.onGenericMotionEvent(ev, 0); } + final int actionButton = ev.getActionButton(); switch (ev.getActionMasked()) { case MotionEvent.ACTION_BUTTON_PRESS: - if (mStylusButtonListener != null && !mInStylusButtonPress && !mInLongPress - && ev.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) { - if (mStylusButtonListener.onStylusButtonPress(ev)) { - mInStylusButtonPress = true; + if (mContextClickListener != null && !mInContextClick && !mInLongPress + && (actionButton == MotionEvent.BUTTON_STYLUS_PRIMARY + || actionButton == MotionEvent.BUTTON_SECONDARY)) { + if (mContextClickListener.onContextClick(ev)) { + mInContextClick = true; mHandler.removeMessages(LONG_PRESS); mHandler.removeMessages(TAP); return true; @@ -712,9 +708,9 @@ public class GestureDetector { break; case MotionEvent.ACTION_BUTTON_RELEASE: - if (mInStylusButtonPress - && ev.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) { - mInStylusButtonPress = false; + if (mInContextClick && (actionButton == MotionEvent.BUTTON_STYLUS_PRIMARY + || actionButton == MotionEvent.BUTTON_SECONDARY)) { + mInContextClick = false; mIgnoreNextUpEvent = true; } break; @@ -734,7 +730,7 @@ public class GestureDetector { mAlwaysInBiggerTapRegion = false; mDeferConfirmSingleTap = false; mInLongPress = false; - mInStylusButtonPress = false; + mInContextClick = false; mIgnoreNextUpEvent = false; } @@ -747,7 +743,7 @@ public class GestureDetector { mAlwaysInBiggerTapRegion = false; mDeferConfirmSingleTap = false; mInLongPress = false; - mInStylusButtonPress = false; + mInContextClick = false; mIgnoreNextUpEvent = false; } |