# MotionEventBuilder

# MotionEventBuilder

Artifact:[androidx.test:core](https://developer.android.com/jetpack/androidx/releases/test)  
[View Source](https://cs.android.com/search?q=file:androidx/test/core/view/MotionEventBuilder.java+class:androidx.test.core.view.MotionEventBuilder)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/core/view/MotionEventBuilder "View this page in Java")

<br />

```
class MotionEventBuilder
```

<br />

*** ** * ** ***

A helper builder for creating[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html)'s.

Default values for unspecified attributes are 0 unless otherwise noted.

## Summary

|                                                       ### Public functions                                                       |
|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html)`!`                                          | [build](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#build())`()` Returns a MotionEvent with the provided data or reasonable defaults.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `java-static `[MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!` | [newBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#newBuilder())`()` Start building a new MotionEvent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setAction](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setAction(int))`(action: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the action.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setActionIndex](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setActionIndex(int))`(pointerIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the pointer index associated with the action.                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setButtonState](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setButtonState(int))`(buttonState: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the button state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setDeviceId](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setDeviceId(int))`(deviceId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the device id.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setDownTime](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setDownTime(long))`(downTime: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Sets the down time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setEdgeFlags](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setEdgeFlags(int))`(edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the edge flags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setEventTime](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setEventTime(long))`(eventTime: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Sets the event time.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setFlags](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setFlags(int))`(flags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the flags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setMetaState](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setMetaState(int))`(metastate: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the metaState.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setPointer](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setPointer(android.view.MotionEvent.PointerProperties,android.view.MotionEvent.PointerCoords))`(` ` pointerProperties: `[MotionEvent.PointerProperties](https://developer.android.com/reference/android/view/MotionEvent.PointerProperties.html)`!,` ` pointerCoords: `[MotionEvent.PointerCoords](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords.html)`!` `)` An expanded variant of[setPointer](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setPointer(float,float))that supports specifying all pointer properties and coords data. |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setPointer](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setPointer(float,float))`(x: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`, y: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Simple mechanism to add a pointer to the MotionEvent.                                                                                                                                                                                                                                                                                                                                                         |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setSource](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setSource(int))`(source: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the source.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setXPrecision](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setXPrecision(float))`(xPrecision: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the x precision.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!`               | [setYPrecision](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setYPrecision(float))`(yPrecision: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the y precision.                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

## Public functions

### build

```
fun build(): MotionEvent!
```

Returns a MotionEvent with the provided data or reasonable defaults.  

### newBuilder

```
java-static fun newBuilder(): MotionEventBuilder!
```

Start building a new MotionEvent.  

|                                                      Returns                                                       |
|--------------------------------------------------------------------------------------------------------------------|---------------------------|
| [MotionEventBuilder](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder)`!` | a new MotionEventBuilder. |

### setAction

```
fun setAction(action: Int): MotionEventBuilder!
```

Sets the action. Default is MotionEvent.ACTION_DOWN.  

|                                            See also                                            |
|------------------------------------------------------------------------------------------------|---|
| [getAction](https://developer.android.com/reference/android/view/MotionEvent.html#getAction()) |   |

### setActionIndex

```
fun setActionIndex(pointerIndex: Int): MotionEventBuilder!
```

Sets the pointer index associated with the action.  

|                                                 See also                                                 |
|----------------------------------------------------------------------------------------------------------|---|
| [getActionIndex](https://developer.android.com/reference/android/view/MotionEvent.html#getActionIndex()) |   |

### setButtonState

```
fun setButtonState(buttonState: Int): MotionEventBuilder!
```

Sets the button state.  

|                                                 See also                                                 |
|----------------------------------------------------------------------------------------------------------|---|
| [getButtonState](https://developer.android.com/reference/android/view/MotionEvent.html#getButtonState()) |   |

### setDeviceId

```
fun setDeviceId(deviceId: Int): MotionEventBuilder!
```

Sets the device id.  

|                                              See also                                              |
|----------------------------------------------------------------------------------------------------|---|
| [getDeviceId](https://developer.android.com/reference/android/view/MotionEvent.html#getDeviceId()) |   |

### setDownTime

```
fun setDownTime(downTime: Long): MotionEventBuilder!
```

Sets the down time.  

|                                              See also                                              |
|----------------------------------------------------------------------------------------------------|---|
| [getDownTime](https://developer.android.com/reference/android/view/MotionEvent.html#getDownTime()) |   |

### setEdgeFlags

```
fun setEdgeFlags(edgeFlags: Int): MotionEventBuilder!
```

Sets the edge flags.  

|                                               See also                                               |
|------------------------------------------------------------------------------------------------------|---|
| [getEdgeFlags](https://developer.android.com/reference/android/view/MotionEvent.html#getEdgeFlags()) |   |

### setEventTime

```
fun setEventTime(eventTime: Long): MotionEventBuilder!
```

Sets the event time. Default is SystemClock.uptimeMillis().  

|                                               See also                                               |
|------------------------------------------------------------------------------------------------------|---|
| [getEventTime](https://developer.android.com/reference/android/view/MotionEvent.html#getEventTime()) |   |

### setFlags

```
fun setFlags(flags: Int): MotionEventBuilder!
```

Sets the flags.  

|                                           See also                                           |
|----------------------------------------------------------------------------------------------|---|
| [getFlags](https://developer.android.com/reference/android/view/MotionEvent.html#getFlags()) |   |

### setMetaState

```
fun setMetaState(metastate: Int): MotionEventBuilder!
```

Sets the metaState.  

|                                               See also                                               |
|------------------------------------------------------------------------------------------------------|---|
| [getMetaState](https://developer.android.com/reference/android/view/MotionEvent.html#getMetaState()) |   |

### setPointer

```
fun setPointer(
    pointerProperties: MotionEvent.PointerProperties!,
    pointerCoords: MotionEvent.PointerCoords!
): MotionEventBuilder!
```

An expanded variant of[setPointer](https://developer.android.com/reference/kotlin/androidx/test/core/view/MotionEventBuilder#setPointer(float,float))that supports specifying all pointer properties and coords data.  

### setPointer

```
fun setPointer(x: Float, y: Float): MotionEventBuilder!
```

Simple mechanism to add a pointer to the MotionEvent.

Can be called multiple times to add multiple pointers to the event.  

### setSource

```
fun setSource(source: Int): MotionEventBuilder!
```

Sets the source.  

|                                            See also                                            |
|------------------------------------------------------------------------------------------------|---|
| [getSource](https://developer.android.com/reference/android/view/MotionEvent.html#getSource()) |   |

### setXPrecision

```
fun setXPrecision(xPrecision: Float): MotionEventBuilder!
```

Sets the x precision.  

|                                                See also                                                |
|--------------------------------------------------------------------------------------------------------|---|
| [getXPrecision](https://developer.android.com/reference/android/view/MotionEvent.html#getXPrecision()) |   |

### setYPrecision

```
fun setYPrecision(yPrecision: Float): MotionEventBuilder!
```

Sets the y precision.  

|                                                See also                                                |
|--------------------------------------------------------------------------------------------------------|---|
| [getYPrecision](https://developer.android.com/reference/android/view/MotionEvent.html#getYPrecision()) |   |