{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MotionEventBuilder

public class MotionEventBuilder


A helper builder for creating MotionEvent's.

Default values for unspecified attributes are 0 unless otherwise noted.

Summary

Public methods

@NonNull MotionEvent

Returns a MotionEvent with the provided data or reasonable defaults.

static @NonNull MotionEventBuilder

Start building a new MotionEvent.

@NonNull MotionEventBuilder
setAction(@NonNull int action)

Sets the action.

@NonNull MotionEventBuilder
setActionIndex(@NonNull int pointerIndex)

Sets the pointer index associated with the action.

@NonNull MotionEventBuilder
setButtonState(@NonNull int buttonState)

Sets the button state.

@NonNull MotionEventBuilder
setDeviceId(@NonNull int deviceId)

Sets the device id.

@NonNull MotionEventBuilder
setDownTime(@NonNull long downTime)

Sets the down time.

@NonNull MotionEventBuilder
setEdgeFlags(@NonNull int edgeFlags)

Sets the edge flags.

@NonNull MotionEventBuilder
setEventTime(@NonNull long eventTime)

Sets the event time.

@NonNull MotionEventBuilder
setFlags(@NonNull int flags)

Sets the flags.

@NonNull MotionEventBuilder
setMetaState(@NonNull int metastate)

Sets the metaState.

@NonNull MotionEventBuilder
setPointer(@NonNull float x, @NonNull float y)

Simple mechanism to add a pointer to the MotionEvent.

@NonNull MotionEventBuilder
setPointer(
    @NonNull PointerProperties pointerProperties,
    @NonNull PointerCoords pointerCoords
)

An expanded variant of setPointer that supports specifying all pointer properties and coords data.

@NonNull MotionEventBuilder
setSource(@NonNull int source)

Sets the source.

@NonNull MotionEventBuilder
setXPrecision(@NonNull float xPrecision)

Sets the x precision.

@NonNull MotionEventBuilder
setYPrecision(@NonNull float yPrecision)

Sets the y precision.

Public methods

build

@NonNull
public MotionEvent build()

Returns a MotionEvent with the provided data or reasonable defaults.

newBuilder

@NonNull
public static MotionEventBuilder newBuilder()

Start building a new MotionEvent.

Returns
MotionEventBuilder

a new MotionEventBuilder.

setAction

@NonNull
public MotionEventBuilder setAction(@NonNull int action)

Sets the action. Default is MotionEvent.ACTION_DOWN.

See also
MotionEvent

android.view.MotionEvent#getAction()

setActionIndex

@NonNull
public MotionEventBuilder setActionIndex(@NonNull int pointerIndex)

Sets the pointer index associated with the action.

See also
MotionEvent

android.view.MotionEvent#getActionIndex()

setButtonState

@NonNull
public MotionEventBuilder setButtonState(@NonNull int buttonState)

Sets the button state.

See also
MotionEvent

android.view.MotionEvent#getButtonState()

setDeviceId

@NonNull
public MotionEventBuilder setDeviceId(@NonNull int deviceId)

Sets the device id.

See also
MotionEvent

android.view.MotionEvent#getDeviceId()

setDownTime

@NonNull
public MotionEventBuilder setDownTime(@NonNull long downTime)

Sets the down time.

See also
MotionEvent

android.view.MotionEvent#getDownTime()

setEdgeFlags

@NonNull
public MotionEventBuilder setEdgeFlags(@NonNull int edgeFlags)

Sets the edge flags.

See also
MotionEvent

android.view.MotionEvent#getEdgeFlags()

setEventTime

@NonNull
public MotionEventBuilder setEventTime(@NonNull long eventTime)

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

See also
MotionEvent

android.view.MotionEvent#getEventTime()

setFlags

@NonNull
public MotionEventBuilder setFlags(@NonNull int flags)

Sets the flags.

See also
MotionEvent

android.view.MotionEvent#getFlags()

setMetaState

@NonNull
public MotionEventBuilder setMetaState(@NonNull int metastate)

Sets the metaState.

See also
MotionEvent

android.view.MotionEvent#getMetaState()

setPointer

@NonNull
public MotionEventBuilder setPointer(@NonNull float x, @NonNull float y)

Simple mechanism to add a pointer to the MotionEvent.

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

setPointer

@NonNull
public MotionEventBuilder setPointer(
    @NonNull PointerProperties pointerProperties,
    @NonNull PointerCoords pointerCoords
)

An expanded variant of setPointer that supports specifying all pointer properties and coords data.

setSource

@NonNull
public MotionEventBuilder setSource(@NonNull int source)

Sets the source.

See also
MotionEvent

android.view.MotionEvent#getSource()

setXPrecision

@NonNull
public MotionEventBuilder setXPrecision(@NonNull float xPrecision)

Sets the x precision.

See also
MotionEvent

android.view.MotionEvent#getXPrecision()

setYPrecision

@NonNull
public MotionEventBuilder setYPrecision(@NonNull float yPrecision)

Sets the y precision.

See also
MotionEvent

android.view.MotionEvent#getYPrecision()