MotionPredictor
public
final
class
MotionPredictor
extends Object
| java.lang.Object | |
| ↳ | android.view.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(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 constructors | |
|---|---|
MotionPredictor(Context context)
Create a new MotionPredictor for the provided |
|
Public methods | |
|---|---|
boolean
|
isPredictionAvailable(int deviceId, int source)
Check whether a device supports motion predictions for a given source type. |
List<MotionEvent>
|
predict(long predictionTimeNanos)
Get predicted events for all gestures that have been provided to |
void
|
record(MotionEvent event)
Record a movement so that in the future, a prediction for the current gesture can be generated. |
Inherited methods | |
|---|---|
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 List<MotionEvent> predict (long predictionTimeNanos)
Get predicted events for all gestures that have been provided to record(MotionEvent).
If events from multiple devices were sent to 'record', this will produce a separate
MotionEvent for each device. The returned list may be empty if no predictions for
any of the added events/devices are available.
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 | |
|---|---|
List<MotionEvent> |
A list of predicted motion events, with at most one for each device observed by
record(MotionEvent). Be sure to check the historical data in addition to the latest
(getX(), getY()) coordinates for smooth
prediction curves. An empty list is returned if predictions are not supported, or not
possible for the current set of gestures.
This value cannot be null. |
record
public void record (MotionEvent event)
Record a movement so that in the future, a prediction for the current gesture can be generated. Ensure to add all motions from the gesture of interest to generate correct predictions.
| Parameters | |
|---|---|
event |
MotionEvent: The received event
This value cannot be null. |