MotionEventPredictor
public 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 methods |
|
|---|---|
default static @NonNull MotionEventPredictor |
newInstance(@NonNull View view)Create a new motion predictor associated to a specific |
abstract @Nullable MotionEvent |
predict()Compute a prediction |
abstract void |
record(@NonNull MotionEvent event)Record a user's movement to the predictor. |
Public methods
newInstance
default static @NonNull MotionEventPredictor newInstance(@NonNull View view)
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.
| Returns | |
|---|---|
@NonNull MotionEventPredictor |
the new predictor instance |
predict
abstract @Nullable MotionEvent predict()
Compute a prediction
| Returns | |
|---|---|
@Nullable MotionEvent |
the predicted |
record
abstract void record(@NonNull MotionEvent event)
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 | |
|---|---|
@NonNull MotionEvent event |
the |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if an inconsistent MotionEvent stream is sent. |