Stay organized with collections
Save and categorize content based on your preferences.
MotionPredictor
class MotionPredictor
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
. Send all of the events that were received from the system to record
to generate complete, accurate predictions from predict
. When processing the returned predictions, make sure to consider all of the android.view.MotionEvent#getHistoricalAxisValue.
Summary
Public constructors |
Create a new MotionPredictor for the provided Context .
|
Public methods |
Boolean |
Check whether a device supports motion predictions for a given source type.
|
MotionEvent? |
Get a predicted event for the gesture that has been provided to record .
|
Unit |
Record a movement so that in the future, a prediction for the current gesture can be generated.
|
Public constructors
MotionPredictor
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
fun isPredictionAvailable(
deviceId: Int,
source: Int
): Boolean
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. |
Return |
Boolean |
True if the current device supports predictions, false otherwise. |
predict
fun predict(predictionTimeNanos: Long): MotionEvent?
Get a predicted event for the gesture that has been provided to record
. Predictions may not reach the requested timestamp if the confidence in the prediction results is low.
Return |
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 (android.view.MotionEvent#getX, android.view.MotionEvent#getY) coordinates for smooth prediction curves. |
record
fun record(event: MotionEvent): Unit
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 . |
Exceptions |
java.lang.IllegalArgumentException |
if an inconsistent MotionEvent stream is sent. |
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[]]