summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorMady Mellor <madym@google.com>2015-05-27 13:35:23 -0700
committerMady Mellor <madym@google.com>2015-05-27 13:35:23 -0700
commit68e280074dfdbce4329a3e1315d855a41dcb4e5e (patch)
tree00d19ffab9cc976d9a57b94546fc53c19a6b427a /core/java/android
parent5fa7b8bd8cbf6407ab88bdf5f3e3a6e40053b98c (diff)
downloadframeworks_base-68e280074dfdbce4329a3e1315d855a41dcb4e5e.zip
frameworks_base-68e280074dfdbce4329a3e1315d855a41dcb4e5e.tar.gz
frameworks_base-68e280074dfdbce4329a3e1315d855a41dcb4e5e.tar.bz2
Update stylus button press recognition in View to use new MotionEvent APIs
Button press events now occur in onGenericMotionEvent. This CL updates the button press detection code in View to recognize the gesture within onGenericMotionEvent rather than in onTouchEvent. Bug: 21148238 Change-Id: I6b5d6d6840e7cb6d3dabf8b138828ae862db8ed4
Diffstat (limited to 'core/java/android')
-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 3962b70..7070670 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
@@ -5218,26 +5225,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.
@@ -9358,6 +9345,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);
}
@@ -10218,10 +10228,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
@@ -10239,7 +10245,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();
@@ -10271,15 +10277,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;
@@ -10309,10 +10311,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:
@@ -10328,9 +10329,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;
}