summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMady Mellor <madym@google.com>2015-06-08 15:11:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-08 15:11:10 +0000
commita54a8626ed77c5641adfb3dbcfdc9bf463478101 (patch)
tree2f32da24191e2caa9a0fcf60a9f28d77c31504e9
parentaaf68f216327a8a2adaf72032904b50796b4aea7 (diff)
parent015020eb3abb212bf7f033416fbdec572287e092 (diff)
downloadframeworks_base-a54a8626ed77c5641adfb3dbcfdc9bf463478101.zip
frameworks_base-a54a8626ed77c5641adfb3dbcfdc9bf463478101.tar.gz
frameworks_base-a54a8626ed77c5641adfb3dbcfdc9bf463478101.tar.bz2
Merge "Change stylus button press to context click in GD - API review feedback" into mnc-dev
-rw-r--r--api/current.txt14
-rw-r--r--api/system-current.txt14
-rw-r--r--core/java/android/view/GestureDetector.java66
3 files changed, 45 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt
index 75cd2a1..6cda103 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -34769,9 +34769,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 {
@@ -34789,12 +34793,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);
@@ -34804,7 +34805,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 6d55448..dbb1dc0 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -37034,9 +37034,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 {
@@ -37054,12 +37058,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);
@@ -37069,7 +37070,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;
}