Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/view/MotionPredictor#pubctors) \| [Methods](https://developer.android.com/reference/android/view/MotionPredictor#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/MotionPredictor#inhmethods)

# MotionPredictor

*** ** * ** ***

` public final class MotionPredictor `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.MotionPredictor |

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/android/view/MotionPredictor#isPredictionAvailable(int,%20int)`. Send all of the events that were received from the system to `https://developer.android.com/reference/android/view/MotionPredictor#record(android.view.MotionEvent)` to generate complete, accurate predictions from `https://developer.android.com/reference/android/view/MotionPredictor#predict(long)`. When processing the returned predictions, make sure to consider all of the `https://developer.android.com/reference/android/view/MotionEvent#getHistoricalAxisValue(int,%20int)`.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/MotionPredictor#MotionPredictor(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Create a new MotionPredictor for the provided `https://developer.android.com/reference/android/content/Context`. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/view/MotionPredictor#isPredictionAvailable(int,%20int)(int deviceId, int source) ` Check whether a device supports motion predictions for a given source type. |
| ` https://developer.android.com/reference/android/view/MotionEvent` | ` https://developer.android.com/reference/android/view/MotionPredictor#predict(long)(long predictionTimeNanos) ` Get a predicted event for the gesture that has been provided to `https://developer.android.com/reference/android/view/MotionPredictor#record(android.view.MotionEvent)`. |
| ` void` | ` https://developer.android.com/reference/android/view/MotionPredictor#record(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent event) ` Record a movement so that in the future, a prediction for the current gesture can be generated. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### MotionPredictor

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MotionPredictor (Context context)
```

Create a new MotionPredictor for the provided `https://developer.android.com/reference/android/content/Context`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The context for the predictions. This value cannot be `null`. <br /> |

## Public methods

### isPredictionAvailable

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isPredictionAvailable (int deviceId, 
                int source)
```

Check whether a device supports motion predictions for a given source type.

<br />

| Parameters ||
|---|---|
| `deviceId` | `int`: The input device id. <br /> |
| `source` | `int`: The source of input events. <br /> |

| Returns ||
|---|---|
| `boolean` | True if the current device supports predictions, false otherwise. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/MotionEvent#getDeviceId()`
- `https://developer.android.com/reference/android/view/MotionEvent#getSource()`

### predict

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MotionEvent predict (long predictionTimeNanos)
```

Get a predicted event for the gesture that has been provided to `https://developer.android.com/reference/android/view/MotionPredictor#record(android.view.MotionEvent)`. Predictions may not reach the requested timestamp if the confidence in the prediction results is low.

<br />

| Parameters ||
|---|---|
| `predictionTimeNanos` | `long`: The time that the prediction should target, in the `https://developer.android.com/reference/android/os/SystemClock#uptimeMillis()` time base, but in nanoseconds. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/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 (`https://developer.android.com/reference/android/view/MotionEvent#getX()`, `https://developer.android.com/reference/android/view/MotionEvent#getY()`) coordinates for smooth prediction curves. <br /> |

### record

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void record (MotionEvent event)
```

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.

<br />

| Parameters ||
|---|---|
| `event` | `MotionEvent`: The received event. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if an inconsistent MotionEvent stream is sent. |