MotionEventPredictor


interface MotionEventPredictor


There is a gap between the time a user touches the screen and that information is reported to the app; a motion predictor is a utility that provides predicted android.view.MotionEvent based on the previously received ones. Obtain a new predictor instance using newInstance; put the motion events you receive into it with record, and call predict to retrieve the predicted android.view.MotionEvent that would occur at the moment the next frame is rendered on the display.

Summary

Public functions

java-static MotionEventPredictor

Create a new motion predictor associated to a specific android.view.View.

MotionEvent?

Compute a prediction

Unit

Record a user's movement to the predictor.

Public functions

newInstance

Added in 1.0.0-beta03
java-static fun newInstance(view: View): MotionEventPredictor

Create a new motion predictor associated to a specific android.view.View. For devices running Android versions before U, the predicions are provided by a library based on a Kalman filter; from Android U, a system API is available, but predictions may not be supported for all strokes (for instance, it may be limited to stylus events). In these cases, the Kalman filter library will be used; to determine if a `MotionEvent` will be handled by the system prediction, use isPredictionAvailable.

Parameters
view: View

the view to associated to this predictor

Returns
MotionEventPredictor

the new predictor instance

predict

Added in 1.0.0-beta03
fun predict(): MotionEvent?

Compute a prediction

Returns
MotionEvent?

the predicted android.view.MotionEvent, or null if not possible to make a prediction.

record

Added in 1.0.0-beta03
fun record(event: MotionEvent): Unit

Record a user's movement to the predictor. You should call this for every android.view.MotionEvent that is received by the associated android.view.View.

Parameters
event: MotionEvent

the android.view.MotionEvent the associated view received and that needs to be recorded.

Throws
java.lang.IllegalArgumentException

if an inconsistent MotionEvent stream is sent.