MotionEventBuilder

public class MotionEventBuilder
extends Object

java.lang.Object
   ↳ androidx.test.core.view.MotionEventBuilder


A helper builder for creating MotionEvent's.

Default values for unspecified attributes are 0 unless otherwise noted.

Summary

Public methods

MotionEvent build()

Returns a MotionEvent with the provided data or reasonable defaults.

static MotionEventBuilder newBuilder()

Start building a new MotionEvent.

MotionEventBuilder setAction(int action)

Sets the action.

MotionEventBuilder setActionIndex(int pointerIndex)

Sets the pointer index associated with the action.

MotionEventBuilder setButtonState(int buttonState)

Sets the button state.

MotionEventBuilder setDeviceId(int deviceId)

Sets the device id.

MotionEventBuilder setDownTime(long downTime)

Sets the down time.

MotionEventBuilder setEdgeFlags(int edgeFlags)

Sets the edge flags.

MotionEventBuilder setEventTime(long eventTime)

Sets the event time.

MotionEventBuilder setFlags(int flags)

Sets the flags.

MotionEventBuilder setMetaState(int metastate)

Sets the metaState.

MotionEventBuilder setPointer(MotionEvent.PointerProperties pointerProperties, MotionEvent.PointerCoords pointerCoords)

An expanded variant of setPointer(float, float) that supports specifying all pointer properties and coords data.

MotionEventBuilder setPointer(float x, float y)

Simple mechanism to add a pointer to the MotionEvent.

MotionEventBuilder setSource(int source)

Sets the source.

MotionEventBuilder setXPrecision(float xPrecision)

Sets the x precision.

MotionEventBuilder setYPrecision(float yPrecision)

Sets the y precision.

Inherited methods

Public methods

build

public MotionEvent build ()

Returns a MotionEvent with the provided data or reasonable defaults.

Returns
MotionEvent

newBuilder

public static MotionEventBuilder newBuilder ()

Start building a new MotionEvent.

Returns
MotionEventBuilder a new MotionEventBuilder.

setAction

public MotionEventBuilder setAction (int action)

Sets the action. Default is ERROR(/MotionEvent.ACTION_DOWN).

Parameters
action int

Returns
MotionEventBuilder

setActionIndex

public MotionEventBuilder setActionIndex (int pointerIndex)

Sets the pointer index associated with the action.

Parameters
pointerIndex int

Returns
MotionEventBuilder

setButtonState

public MotionEventBuilder setButtonState (int buttonState)

Sets the button state.

Parameters
buttonState int

Returns
MotionEventBuilder

setDeviceId

public MotionEventBuilder setDeviceId (int deviceId)

Sets the device id.

Parameters
deviceId int

Returns
MotionEventBuilder

setDownTime

public MotionEventBuilder setDownTime (long downTime)

Sets the down time.

Parameters
downTime long

Returns
MotionEventBuilder

setEdgeFlags

public MotionEventBuilder setEdgeFlags (int edgeFlags)

Sets the edge flags.

Parameters
edgeFlags int

Returns
MotionEventBuilder

setEventTime

public MotionEventBuilder setEventTime (long eventTime)

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

Parameters
eventTime long

Returns
MotionEventBuilder

setFlags

public MotionEventBuilder setFlags (int flags)

Sets the flags.

Parameters
flags int

Returns
MotionEventBuilder

setMetaState

public MotionEventBuilder setMetaState (int metastate)

Sets the metaState.

Parameters
metastate int

Returns
MotionEventBuilder

setPointer

public MotionEventBuilder setPointer (MotionEvent.PointerProperties pointerProperties, 
                MotionEvent.PointerCoords pointerCoords)

An expanded variant of setPointer(float, float) that supports specifying all pointer properties and coords data.

Parameters
pointerProperties MotionEvent.PointerProperties

pointerCoords MotionEvent.PointerCoords

Returns
MotionEventBuilder

setPointer

public MotionEventBuilder setPointer (float x, 
                float y)

Simple mechanism to add a pointer to the MotionEvent.

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

Parameters
x float

y float

Returns
MotionEventBuilder

setSource

public MotionEventBuilder setSource (int source)

Sets the source.

Parameters
source int

Returns
MotionEventBuilder

setXPrecision

public MotionEventBuilder setXPrecision (float xPrecision)

Sets the x precision.

Parameters
xPrecision float

Returns
MotionEventBuilder

setYPrecision

public MotionEventBuilder setYPrecision (float yPrecision)

Sets the y precision.

Parameters
yPrecision float

Returns
MotionEventBuilder