Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c189479 authored by Mady Mellor's avatar Mady Mellor Committed by Android Git Automerger
Browse files

am ef24bc00: Merge "Update stylus button press recognition in View to use new...

am ef24bc00: Merge "Update stylus button press recognition in View to use new MotionEvent APIs" into mnc-dev

* commit 'ef24bc00':
  Update stylus button press recognition in View to use new MotionEvent APIs
parents ed836dec ef24bc00
Loading
Loading
Loading
Loading
+36 −38
Original line number Diff line number Diff line
@@ -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;
                    }
                    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;
            }