summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorMady Mellor <madym@google.com>2015-06-01 16:16:16 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-01 16:16:20 +0000
commitef24bc00399ceb627e9780f05eb68f955e6bd495 (patch)
tree94854d767c14a511765769e4251750f1024fa406 /core/java
parentcac7b2b17505dd3d84966ff15abf5e5343783dee (diff)
parent68e280074dfdbce4329a3e1315d855a41dcb4e5e (diff)
downloadframeworks_base-ef24bc00399ceb627e9780f05eb68f955e6bd495.zip
frameworks_base-ef24bc00399ceb627e9780f05eb68f955e6bd495.tar.gz
frameworks_base-ef24bc00399ceb627e9780f05eb68f955e6bd495.tar.bz2
Merge "Update stylus button press recognition in View to use new MotionEvent APIs" into mnc-dev
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/View.java74
1 files changed, 36 insertions, 38 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 0c55632..3e621b1 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -3521,7 +3521,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* the stylus is touching the screen and the button has been pressed, this
* is false once the stylus has been lifted.
*/
- private boolean mInStylusButtonPress = false;
+ private boolean mInStylusButtonPress;
+
+ /**
+ * Whether the next up event should be ignored for the purposes of gesture recognition. This is
+ * true after a stylus button press has occured, when the next up event should not be recognized
+ * as a tap.
+ */
+ private boolean mIgnoreNextUpEvent;
/**
* The minimum height of the view. We'll try our best to have the height
@@ -5231,26 +5238,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * Checks for a stylus button press and calls the listener.
- *
- * @param event The event.
- * @return True if the event was consumed.
- */
- private boolean performStylusActionOnButtonPress(MotionEvent event) {
- if (isStylusButtonPressable() && !mInStylusButtonPress && !mHasPerformedLongPress
- && event.isButtonPressed(MotionEvent.BUTTON_STYLUS_SECONDARY)) {
- if (performStylusButtonPress()) {
- mInStylusButtonPress = true;
- setPressed(true, event.getX(), event.getY());
- removeTapCallback();
- removeLongPressCallback();
- return true;
- }
- }
- return false;
- }
-
- /**
* Performs button-related actions during a touch down event.
*
* @param event The event.
@@ -9380,6 +9367,29 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
return true;
}
+ switch (event.getActionMasked()) {
+ case MotionEvent.ACTION_BUTTON_PRESS:
+ if (isStylusButtonPressable() && !mInStylusButtonPress && !mHasPerformedLongPress
+ && event.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) {
+ if (performStylusButtonPress()) {
+ mInStylusButtonPress = true;
+ setPressed(true, event.getX(), event.getY());
+ removeTapCallback();
+ removeLongPressCallback();
+ return true;
+ }
+ }
+ break;
+
+ case MotionEvent.ACTION_BUTTON_RELEASE:
+ if (mInStylusButtonPress
+ && event.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) {
+ mInStylusButtonPress = false;
+ mIgnoreNextUpEvent = true;
+ }
+ break;
+ }
+
if (mInputEventConsistencyVerifier != null) {
mInputEventConsistencyVerifier.onUnhandledEvent(event, 0);
}
@@ -10240,10 +10250,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
(viewFlags & STYLUS_BUTTON_PRESSABLE) == STYLUS_BUTTON_PRESSABLE) {
switch (action) {
case MotionEvent.ACTION_UP:
- if (mInStylusButtonPress) {
- mInStylusButtonPress = false;
- mHasPerformedLongPress = false;
- }
boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0;
if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) {
// take focus if we don't have it already and we should in
@@ -10261,7 +10267,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
setPressed(true, x, y);
}
- if (!mHasPerformedLongPress) {
+ if (!mHasPerformedLongPress && !mIgnoreNextUpEvent) {
// This is a tap, so remove the longpress check
removeLongPressCallback();
@@ -10293,15 +10299,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
removeTapCallback();
}
+ mIgnoreNextUpEvent = false;
break;
case MotionEvent.ACTION_DOWN:
mHasPerformedLongPress = false;
- mInStylusButtonPress = false;
-
- if (performStylusActionOnButtonPress(event)) {
- break;
- }
if (performButtonActionOnTouchDown(event)) {
break;
@@ -10331,10 +10333,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
setPressed(false);
removeTapCallback();
removeLongPressCallback();
- if (mInStylusButtonPress) {
- mInStylusButtonPress = false;
- mHasPerformedLongPress = false;
- }
+ mInStylusButtonPress = false;
+ mHasPerformedLongPress = false;
+ mIgnoreNextUpEvent = false;
break;
case MotionEvent.ACTION_MOVE:
@@ -10350,9 +10351,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
setPressed(false);
}
- } else if (performStylusActionOnButtonPress(event)) {
- // Check for stylus button press if we're within the view.
- break;
}
break;
}