am ee8ac623: am 8c189479: am ef24bc00: Merge "Update stylus button press recognition in View to use new MotionEvent APIs" into mnc-dev
* commit 'ee8ac623edee9352fdbf2f653af564a9df8514d2': Update stylus button press recognition in View to use new MotionEvent APIs
This commit is contained in:
@@ -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
|
||||
@@ -5230,26 +5237,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user