From 7ef81116f49d0835175de0c277c1c4a72b7e74fb Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Tue, 20 Dec 2022 11:04:20 +0000 Subject: [PATCH] Add pinch classification and scale factor axis Bug: 251196347 Test: check events received by a custom tester app, and touches shown by pointer location overlay Test: atest inputflinger_tests Change-Id: I0cb7ade63139ab35025ff1e12609e2b411b1f5f8 --- core/api/current.txt | 2 ++ core/java/android/view/MotionEvent.java | 31 ++++++++++++++++++++++++- native/android/input.cpp | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/core/api/current.txt b/core/api/current.txt index 3d8491854c33a..d0e5ca628e98b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -50482,6 +50482,7 @@ package android.view { field public static final int AXIS_GENERIC_7 = 38; // 0x26 field public static final int AXIS_GENERIC_8 = 39; // 0x27 field public static final int AXIS_GENERIC_9 = 40; // 0x28 + field public static final int AXIS_GESTURE_PINCH_SCALE_FACTOR = 52; // 0x34 field public static final int AXIS_GESTURE_SCROLL_X_DISTANCE = 50; // 0x32 field public static final int AXIS_GESTURE_SCROLL_Y_DISTANCE = 51; // 0x33 field public static final int AXIS_GESTURE_X_OFFSET = 48; // 0x30 @@ -50522,6 +50523,7 @@ package android.view { field public static final int CLASSIFICATION_AMBIGUOUS_GESTURE = 1; // 0x1 field public static final int CLASSIFICATION_DEEP_PRESS = 2; // 0x2 field public static final int CLASSIFICATION_NONE = 0; // 0x0 + field public static final int CLASSIFICATION_PINCH = 5; // 0x5 field public static final int CLASSIFICATION_TWO_FINGER_SWIPE = 3; // 0x3 field @NonNull public static final android.os.Parcelable.Creator CREATOR; field public static final int EDGE_BOTTOM = 2; // 0x2 diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index a36fd8d99e3ce..2235663f7706b 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -1283,6 +1283,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { * swipe gesture starts at X = 500 then moves to X = 400, this axis would have a value of * -0.1. * + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. */ public static final int AXIS_GESTURE_X_OFFSET = 48; @@ -1300,6 +1302,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { *
  • For a touch pad, reports the distance that should be scrolled in the X axis as a result * of the user's two-finger scroll gesture, in display pixels. * + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. */ public static final int AXIS_GESTURE_SCROLL_X_DISTANCE = 50; @@ -1310,6 +1314,19 @@ public final class MotionEvent extends InputEvent implements Parcelable { */ public static final int AXIS_GESTURE_SCROLL_Y_DISTANCE = 51; + /** + * Axis constant: pinch scale factor of a motion event. + *

    + *

      + *
    • For a touch pad, reports the change in distance between the fingers when the user is + * making a pinch gesture, as a proportion of the previous distance. For example, if the fingers + * were 50 units apart and are now 52 units apart, the scale factor would be 1.04. + *
    + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. + */ + public static final int AXIS_GESTURE_PINCH_SCALE_FACTOR = 52; + // NOTE: If you add a new axis here you must also add it to: // frameworks/native/include/android/input.h // frameworks/native/libs/input/InputEventLabels.cpp @@ -1369,6 +1386,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { names.append(AXIS_GESTURE_Y_OFFSET, "AXIS_GESTURE_Y_OFFSET"); names.append(AXIS_GESTURE_SCROLL_X_DISTANCE, "AXIS_GESTURE_SCROLL_X_DISTANCE"); names.append(AXIS_GESTURE_SCROLL_Y_DISTANCE, "AXIS_GESTURE_SCROLL_Y_DISTANCE"); + names.append(AXIS_GESTURE_PINCH_SCALE_FACTOR, "AXIS_GESTURE_PINCH_SCALE_FACTOR"); } /** @@ -1522,11 +1540,22 @@ public final class MotionEvent extends InputEvent implements Parcelable { */ public static final int CLASSIFICATION_MULTI_FINGER_SWIPE = 4; + /** + * Classification constant: touchpad pinch. + * + * The current event stream represents the user pinching with two fingers on a touchpad. The + * gesture is centered around the current cursor position. + * + * @see #getClassification + */ + public static final int CLASSIFICATION_PINCH = 5; + /** @hide */ @Retention(SOURCE) @IntDef(prefix = { "CLASSIFICATION" }, value = { CLASSIFICATION_NONE, CLASSIFICATION_AMBIGUOUS_GESTURE, CLASSIFICATION_DEEP_PRESS, - CLASSIFICATION_TWO_FINGER_SWIPE, CLASSIFICATION_MULTI_FINGER_SWIPE}) + CLASSIFICATION_TWO_FINGER_SWIPE, CLASSIFICATION_MULTI_FINGER_SWIPE, + CLASSIFICATION_PINCH}) public @interface Classification {}; /** diff --git a/native/android/input.cpp b/native/android/input.cpp index 5e5ebed78e619..f1c30889c4db9 100644 --- a/native/android/input.cpp +++ b/native/android/input.cpp @@ -299,6 +299,8 @@ int32_t AMotionEvent_getClassification(const AInputEvent* motion_event) { return AMOTION_EVENT_CLASSIFICATION_TWO_FINGER_SWIPE; case android::MotionClassification::MULTI_FINGER_SWIPE: return AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE; + case android::MotionClassification::PINCH: + return AMOTION_EVENT_CLASSIFICATION_PINCH; } }