From 86413b57e1a1c1c273da24b023dceb7765af5b49 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 11 Jan 2023 13:26:44 -0800 Subject: [PATCH] Add MotionPredictor API This API will provide access to motion predictions. Bug: 167946763 Test: atest InputTests Change-Id: Ib8bc0debd9714e76520baae6ab8122762525716d --- core/api/current.txt | 7 +++++++ core/java/android/view/MotionPredictor.java | 11 ++++++++--- tests/MotionPrediction/Android.bp | 3 +-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index c147be9b3caf0..fcff8bb7afe1d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -50628,6 +50628,13 @@ package android.view { field public int toolType; } + public final class MotionPredictor { + ctor public MotionPredictor(@NonNull android.content.Context); + method public boolean isPredictionAvailable(int, int); + method @NonNull public java.util.List predict(long); + method public void record(@NonNull android.view.MotionEvent); + } + public interface OnReceiveContentListener { method @Nullable public android.view.ContentInfo onReceiveContent(@NonNull android.view.View, @NonNull android.view.ContentInfo); } diff --git a/core/java/android/view/MotionPredictor.java b/core/java/android/view/MotionPredictor.java index 3e58a31745dee..fa86a4c73fb20 100644 --- a/core/java/android/view/MotionPredictor.java +++ b/core/java/android/view/MotionPredictor.java @@ -25,10 +25,15 @@ import java.util.Arrays; import java.util.List; /** - * Calculates motion predictions. + * Calculate motion predictions. * - * Add motions here to get predicted events! - * @hide + * Feed motion events to this class in order to generate the predicted events. The prediction + * functionality may not be available on all devices. Check if a specific source is supported on a + * given input device using #isPredictionAvailable. + * + * Send all of the events that were received from the system here in order to generate complete, + * accurate predictions. When processing the returned predictions, make sure to consider all of the + * {@link MotionEvent#getHistoricalAxisValue historical samples}. */ // Acts as a pass-through to the native MotionPredictor object. // Do not store any state in this Java layer, or add any business logic here. All of the diff --git a/tests/MotionPrediction/Android.bp b/tests/MotionPrediction/Android.bp index b9d01da263aae..6cda8f050987b 100644 --- a/tests/MotionPrediction/Android.bp +++ b/tests/MotionPrediction/Android.bp @@ -26,6 +26,5 @@ package { android_app { name: "MotionPrediction", srcs: ["**/*.kt"], - platform_apis: true, - certificate: "platform", + sdk_version: "current", }