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 |
newInstance(view: View)Create a new motion predictor associated to a specific |
MotionEvent? |
predict()Compute a prediction |
Unit |
record(event: MotionEvent)Record a user's movement to the predictor. |
Public functions
newInstance
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
fun predict(): MotionEvent?
Compute a prediction
| Returns | |
|---|---|
MotionEvent? |
the predicted |
record
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 |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if an inconsistent MotionEvent stream is sent. |