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

MotionEventBuilder

class MotionEventBuilder


A helper builder for creating MotionEvent's.

Default values for unspecified attributes are 0 unless otherwise noted.

Summary

Public functions

MotionEvent

Returns a MotionEvent with the provided data or reasonable defaults.

MotionEventBuilder

Start building a new MotionEvent.

MotionEventBuilder
setAction(action: Int)

Sets the action.

MotionEventBuilder
setActionIndex(pointerIndex: Int)

Sets the pointer index associated with the action.

MotionEventBuilder
setButtonState(buttonState: Int)

Sets the button state.

MotionEventBuilder
setDeviceId(deviceId: Int)

Sets the device id.

MotionEventBuilder
setDownTime(downTime: Long)

Sets the down time.

MotionEventBuilder
setEdgeFlags(edgeFlags: Int)

Sets the edge flags.

MotionEventBuilder
setEventTime(eventTime: Long)

Sets the event time.

MotionEventBuilder
setFlags(flags: Int)

Sets the flags.

MotionEventBuilder
setMetaState(metastate: Int)

Sets the metaState.

MotionEventBuilder

Simple mechanism to add a pointer to the MotionEvent.

MotionEventBuilder
setPointer(
    pointerProperties: PointerProperties,
    pointerCoords: PointerCoords
)

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

MotionEventBuilder
setSource(source: Int)

Sets the source.

MotionEventBuilder
setXPrecision(xPrecision: Float)

Sets the x precision.

MotionEventBuilder
setYPrecision(yPrecision: Float)

Sets the y precision.

Public functions

build

fun build(): MotionEvent

Returns a MotionEvent with the provided data or reasonable defaults.

newBuilder

fun newBuilder(): MotionEventBuilder

Start building a new MotionEvent.

Returns
MotionEventBuilder

a new MotionEventBuilder.

setAction

fun setAction(action: Int): MotionEventBuilder

Sets the action. Default is MotionEvent.ACTION_DOWN.

See also
MotionEvent

android.view.MotionEvent#getAction()

setActionIndex

fun setActionIndex(pointerIndex: Int): MotionEventBuilder

Sets the pointer index associated with the action.

See also
MotionEvent

android.view.MotionEvent#getActionIndex()

setButtonState

fun setButtonState(buttonState: Int): MotionEventBuilder

Sets the button state.

See also
MotionEvent

android.view.MotionEvent#getButtonState()

setDeviceId

fun setDeviceId(deviceId: Int): MotionEventBuilder

Sets the device id.

See also
MotionEvent

android.view.MotionEvent#getDeviceId()

setDownTime

fun setDownTime(downTime: Long): MotionEventBuilder

Sets the down time.

See also
MotionEvent

android.view.MotionEvent#getDownTime()

setEdgeFlags

fun setEdgeFlags(edgeFlags: Int): MotionEventBuilder

Sets the edge flags.

See also
MotionEvent

android.view.MotionEvent#getEdgeFlags()

setEventTime

fun setEventTime(eventTime: Long): MotionEventBuilder

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

See also
MotionEvent

android.view.MotionEvent#getEventTime()

setFlags

fun setFlags(flags: Int): MotionEventBuilder

Sets the flags.

See also
MotionEvent

android.view.MotionEvent#getFlags()

setMetaState

fun setMetaState(metastate: Int): MotionEventBuilder

Sets the metaState.

See also
MotionEvent

android.view.MotionEvent#getMetaState()

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.

setPointer

fun setPointer(
    pointerProperties: PointerProperties,
    pointerCoords: PointerCoords
): MotionEventBuilder

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

setSource

fun setSource(source: Int): MotionEventBuilder

Sets the source.

See also
MotionEvent

android.view.MotionEvent#getSource()

setXPrecision

fun setXPrecision(xPrecision: Float): MotionEventBuilder

Sets the x precision.

See also
MotionEvent

android.view.MotionEvent#getXPrecision()

setYPrecision

fun setYPrecision(yPrecision: Float): MotionEventBuilder

Sets the y precision.

See also
MotionEvent

android.view.MotionEvent#getYPrecision()