Stay organized with collections Save and categorize content based on your preferences. MotionPredictor
public final class MotionPredictor
extends Object
Calculate motion predictions. Feed motion events to this class in order to generate predicted future 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(int, int). Send all of the events that were received from the system to record(MotionEvent) to generate complete, accurate predictions from predict(long). When processing the returned predictions, make sure to consider all of the historical samples.
Summary
Public methods |
boolean | isPredictionAvailable(int deviceId, int source) Check whether a device supports motion predictions for a given source type. |
MotionEvent | predict(long predictionTimeNanos) Get a predicted event for the gesture that has been provided to record(MotionEvent). |
void | record(MotionEvent event) Record a movement so that in the future, a prediction for the current gesture can be generated. |
Inherited methods |
From class java.lang.Object Object | clone() Creates and returns a copy of this object. | boolean | equals(Object obj) Indicates whether some other object is "equal to" this one. | void | finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | final Class<?> | getClass() Returns the runtime class of this Object. | int | hashCode() Returns a hash code value for the object. | final void | notify() Wakes up a single thread that is waiting on this object's monitor. | final void | notifyAll() Wakes up all threads that are waiting on this object's monitor. | String | toString() Returns a string representation of the object. | final void | wait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. | final void | wait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. | final void | wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted. | |
Public constructors
MotionPredictor
public MotionPredictor (Context context)
Create a new MotionPredictor for the provided Context.
| Parameters |
context | Context: The context for the predictions This value cannot be null. |
Public methods
isPredictionAvailable
public boolean isPredictionAvailable (int deviceId, int source)
Check whether a device supports motion predictions for a given source type.
| Parameters |
deviceId | int: The input device id. |
source | int: The source of input events. |
| Returns |
boolean | True if the current device supports predictions, false otherwise. |
predict
public MotionEvent predict (long predictionTimeNanos)
Get a predicted event for the gesture that has been provided to record(MotionEvent). Predictions may not reach the requested timestamp if the confidence in the prediction results is low.
| Parameters |
predictionTimeNanos | long: The time that the prediction should target, in the SystemClock.uptimeMillis() time base, but in nanoseconds. |
| Returns |
MotionEvent | The predicted motion event, or `null` if predictions are not supported, or not possible for the current gesture. Be sure to check the historical data in addition to the latest (getX(), getY()) coordinates for smooth prediction curves. |
record
public void record (MotionEvent event)
Record a movement so that in the future, a prediction for the current gesture can be generated. Only gestures from one input device at a time should be provided to an instance of MotionPredictor.
| Parameters |
event | MotionEvent: The received event This value cannot be null. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[]]