diff options
| author | Siarhei Vishniakou <svv@google.com> | 2018-12-28 17:50:24 -0800 |
|---|---|---|
| committer | Siarhei Vishniakou <svv@google.com> | 2019-01-04 14:22:03 -0800 |
| commit | b05b0b53071247d3803db00477083ebc7978a7b7 (patch) | |
| tree | a406052f2962dbebbd976d955b2de6feefde997b /core/java/android | |
| parent | 8f882b5a4850b38e66d1b9509df4a43fb36f21ae (diff) | |
Add classification to MotionEvent
Classification will help categorize the current touch
stream. For example, a DEEP_PRESS classification could be generated
if the system has
determined that the user is trying to press harder on the screen.
This classification could be generated by an ML model.
Test: integration tested by observing the classification being generated
by the InputClassifier HAL.
Bug: 62940136
Change-Id: If72d69a41ff25c8a7f351bac0d86db6fd73500a1
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 94 |
1 files changed, 86 insertions, 8 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index a86abe517b6a..9d3552f71f1f 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -18,6 +18,9 @@ package android.view; import static android.view.Display.DEFAULT_DISPLAY; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import android.annotation.IntDef; import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.graphics.Matrix; @@ -30,6 +33,7 @@ import android.util.SparseArray; import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; +import java.lang.annotation.Retention; import java.util.Objects; /** @@ -462,7 +466,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { /** * This flag indicates that the event has been generated by a gesture generator. It - * provides a hint to the GestureDector to not apply any touch slop. + * provides a hint to the GestureDetector to not apply any touch slop. * * @hide */ @@ -1391,6 +1395,42 @@ public final class MotionEvent extends InputEvent implements Parcelable { }; /** + * Classification constant: None. + * + * No additional information is available about the current motion event stream. + * + * @see #getClassification + */ + public static final int CLASSIFICATION_NONE = 0; + + /** + * Classification constant: Ambiguous gesture. + * + * The user's intent with respect to the current event stream is not yet determined. + * Gestural actions, such as scrolling, should be inhibited until the classification resolves + * to another value or the event stream ends. + * + * @see #getClassification + */ + public static final int CLASSIFICATION_AMBIGUOUS_GESTURE = 1; + + /** + * Classification constant: Deep press. + * + * The current event stream represents the user intentionally pressing harder on the screen. + * This classification type should be used to accelerate the long press behaviour. + * + * @see #getClassification + */ + public static final int CLASSIFICATION_DEEP_PRESS = 2; + + /** @hide */ + @Retention(SOURCE) + @IntDef(prefix = { "CLASSIFICATION" }, value = { + CLASSIFICATION_NONE, CLASSIFICATION_AMBIGUOUS_GESTURE, CLASSIFICATION_DEEP_PRESS}) + public @interface Classification {}; + + /** * Tool type constant: Unknown tool type. * This constant is used when the tool type is not known or is not relevant, * such as for a trackball or other non-pointing device. @@ -1478,7 +1518,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { private static native long nativeInitialize(long nativePtr, int deviceId, int source, int displayId, int action, int flags, int edgeFlags, - int metaState, int buttonState, + int metaState, int buttonState, @Classification int classification, float xOffset, float yOffset, float xPrecision, float yPrecision, long downTimeNanos, long eventTimeNanos, int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords); @@ -1548,6 +1588,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { @CriticalNative private static native void nativeSetButtonState(long nativePtr, int buttonState); @CriticalNative + private static native int nativeGetClassification(long nativePtr); + @CriticalNative private static native int nativeGetActionButton(long nativePtr); @CriticalNative private static native void nativeSetActionButton(long nativePtr, int actionButton); @@ -1648,7 +1690,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { MotionEvent ev = obtain(); ev.mNativePtr = nativeInitialize(ev.mNativePtr, deviceId, source, displayId, action, flags, edgeFlags, metaState, buttonState, - 0, 0, xPrecision, yPrecision, + CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision, downTime * NS_PER_MS, eventTime * NS_PER_MS, pointerCount, pointerProperties, pointerCoords); if (ev.mNativePtr == 0) { @@ -1833,7 +1875,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { ev.mNativePtr = nativeInitialize(ev.mNativePtr, deviceId, source, displayId, - action, 0, edgeFlags, metaState, 0, + action, 0, edgeFlags, metaState, 0 /*buttonState*/, CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision, downTime * NS_PER_MS, eventTime * NS_PER_MS, 1, pp, pc); @@ -2539,6 +2581,18 @@ public final class MotionEvent extends InputEvent implements Parcelable { } /** + * Returns the classification for the current gesture. + * The classification may change as more events become available for the same gesture. + * + * @see #CLASSIFICATION_NONE + * @see #CLASSIFICATION_AMBIGUOUS_GESTURE + * @see #CLASSIFICATION_DEEP_PRESS + */ + public @Classification int getClassification() { + return nativeGetClassification(mNativePtr); + } + + /** * Gets which button has been modified during a press or release action. * * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE} @@ -3172,7 +3226,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { /** * Adds all of the movement samples of the specified event to this one if * it is compatible. To be compatible, the event must have the same device id, - * source, display id, action, flags, pointer count, pointer properties. + * source, display id, action, flags, classification, pointer count, pointer properties. * * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. * @@ -3194,7 +3248,9 @@ public final class MotionEvent extends InputEvent implements Parcelable { if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr) || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr) || nativeGetDisplayId(mNativePtr) != nativeGetDisplayId(event.mNativePtr) - || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) { + || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr) + || nativeGetClassification(mNativePtr) + != nativeGetClassification(event.mNativePtr)) { return false; } @@ -3282,7 +3338,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { nativeGetDisplayId(mNativePtr), nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr), nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr), - nativeGetButtonState(mNativePtr), + nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr), nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr), nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr), nativeGetDownTimeNanos(mNativePtr), @@ -3376,7 +3432,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { nativeGetDisplayId(mNativePtr), newAction, nativeGetFlags(mNativePtr), nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr), - nativeGetButtonState(mNativePtr), + nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr), nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr), nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr), nativeGetDownTimeNanos(mNativePtr), eventTimeNanos, @@ -3409,6 +3465,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { } appendUnless("0", msg, ", buttonState=", MotionEvent.buttonStateToString(getButtonState())); + appendUnless(classificationToString(CLASSIFICATION_NONE), msg, ", classification=", + classificationToString(getClassification())); appendUnless("0", msg, ", metaState=", KeyEvent.metaStateToString(getMetaState())); appendUnless("0", msg, ", flags=0x", Integer.toHexString(getFlags())); appendUnless("0", msg, ", edgeFlags=0x", Integer.toHexString(getEdgeFlags())); @@ -3547,6 +3605,26 @@ public final class MotionEvent extends InputEvent implements Parcelable { } /** + * Returns a string that represents the symbolic name of the specified classification. + * + * @param classification The classification type. + * @return The symbolic name of this classification. + * @hide + */ + public static String classificationToString(@Classification int classification) { + switch (classification) { + case CLASSIFICATION_NONE: + return "NONE"; + case CLASSIFICATION_AMBIGUOUS_GESTURE: + return "AMBIGUOUS_GESTURE"; + case CLASSIFICATION_DEEP_PRESS: + return "DEEP_PRESS"; + + } + return "NONE"; + } + + /** * Returns a string that represents the symbolic name of the specified tool type * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown. * |
