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

Commit 6aced6ea authored by Nergi Rahardi's avatar Nergi Rahardi
Browse files

Add util method to check if MotionEvent is synthesized touchpad gesture

This check is being done in many places:
- WMShell MotionEvent extensions
- Settings DisplayTopologyPreferenceController
- MouseToTouchProcessor
- A11y

More might be added in the future. Ideally having this unified under
MotionEvent itself might be better, similar to isTouchEvent() or
isStylusPointer() check. If there's a new classification or new
condition in the future, it can be added here and all usages are updated

Bug: 436380669
Test: Manual test with touchpad
Flag: EXEMPT adding hidden util method
Change-Id: I2f8384ffa807a9516ba9dedfdee3e0d31caddda0
parent 8ab7c2db
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -2530,6 +2530,29 @@ public final class MotionEvent extends InputEvent implements Parcelable {
                || getActionMasked() == ACTION_HOVER_MOVE;
    }

    /**
     * Returns {@code true} if this motion event is a synthesized touchpad gesture.
     *
     * <p>Before using this method, consider whether you truly need to apply special treatment to
     * all synthesized touchpad gestures (including ones which may be added in future), or whether a
     * check for a specific classification (e.g. {@link #CLASSIFICATION_TWO_FINGER_SWIPE}) would
     * suffice instead.
     *
     * @see #CLASSIFICATION_TWO_FINGER_SWIPE
     * @see #CLASSIFICATION_PINCH
     * @see #CLASSIFICATION_MULTI_FINGER_SWIPE
     *
     * @hide
     */
    public boolean isSynthesizedTouchpadGesture() {
        int classification = getClassification();
        return isFromSource(InputDevice.SOURCE_MOUSE) && getToolType(0)
                == MotionEvent.TOOL_TYPE_FINGER && (
                classification == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE
                        || classification == MotionEvent.CLASSIFICATION_PINCH
                        || classification == MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE);
    }

    /**
     * Gets the motion event flags.
     *