Most visited

Recently visited

MotionEventCompat

public final class MotionEventCompat
extends Object

java.lang.Object
   ↳ android.support.v4.view.MotionEventCompat


Helper for accessing features in MotionEvent introduced after API level 4 in a backwards compatible fashion.

Summary

Constants

int ACTION_HOVER_ENTER

Synonym for ACTION_HOVER_ENTER.

int ACTION_HOVER_EXIT

Synonym for ACTION_HOVER_EXIT.

int ACTION_HOVER_MOVE

Synonym for ACTION_HOVER_MOVE.

int ACTION_MASK

Synonym for ACTION_MASK.

int ACTION_POINTER_DOWN

Synonym for ACTION_POINTER_DOWN.

int ACTION_POINTER_INDEX_MASK

Synonym for ACTION_POINTER_INDEX_MASK.

int ACTION_POINTER_INDEX_SHIFT

Synonym for ACTION_POINTER_INDEX_SHIFT.

int ACTION_POINTER_UP

Synonym for ACTION_POINTER_UP.

int ACTION_SCROLL

Synonym for ACTION_SCROLL.

int AXIS_BRAKE

Synonym for AXIS_BRAKE.

int AXIS_DISTANCE

Synonym for AXIS_DISTANCE.

int AXIS_GAS

Synonym for AXIS_GAS.

int AXIS_GENERIC_1

Synonym for AXIS_GENERIC_1.

int AXIS_GENERIC_10

Synonym for AXIS_GENERIC_10.

int AXIS_GENERIC_11

Synonym for AXIS_GENERIC_11.

int AXIS_GENERIC_12

Synonym for AXIS_GENERIC_12.

int AXIS_GENERIC_13

Synonym for AXIS_GENERIC_13.

int AXIS_GENERIC_14

Synonym for AXIS_GENERIC_14.

int AXIS_GENERIC_15

Synonym for AXIS_GENERIC_15.

int AXIS_GENERIC_16

Synonym for AXIS_GENERIC_16.

int AXIS_GENERIC_2

Synonym for AXIS_GENERIC_2.

int AXIS_GENERIC_3

Synonym for AXIS_GENERIC_3.

int AXIS_GENERIC_4

Synonym for AXIS_GENERIC_4.

int AXIS_GENERIC_5

Synonym for AXIS_GENERIC_5.

int AXIS_GENERIC_6

Synonym for AXIS_GENERIC_6.

int AXIS_GENERIC_7

Synonym for AXIS_GENERIC_7.

int AXIS_GENERIC_8

Synonym for AXIS_GENERIC_8.

int AXIS_GENERIC_9

Synonym for AXIS_GENERIC_9.

int AXIS_HAT_X

Synonym for AXIS_HAT_X.

int AXIS_HAT_Y

Synonym for AXIS_HAT_Y.

int AXIS_HSCROLL

Synonym for AXIS_HSCROLL.

int AXIS_LTRIGGER

Synonym for AXIS_LTRIGGER.

int AXIS_ORIENTATION

Synonym for AXIS_ORIENTATION.

int AXIS_PRESSURE

Synonym for AXIS_PRESSURE.

int AXIS_RELATIVE_X

Synonym for AXIS_RELATIVE_X.

int AXIS_RELATIVE_Y

Synonym for AXIS_RELATIVE_Y.

int AXIS_RTRIGGER

Synonym for AXIS_RTRIGGER.

int AXIS_RUDDER

Synonym for AXIS_RUDDER.

int AXIS_RX

Synonym for AXIS_RX.

int AXIS_RY

Synonym for AXIS_RY.

int AXIS_RZ

Synonym for AXIS_RZ.

int AXIS_SIZE

Synonym for AXIS_SIZE.

int AXIS_THROTTLE

Synonym for AXIS_THROTTLE.

int AXIS_TILT

Synonym for AXIS_TILT.

int AXIS_TOOL_MAJOR

Synonym for AXIS_TOOL_MAJOR.

int AXIS_TOOL_MINOR

Synonym for AXIS_TOOL_MINOR.

int AXIS_TOUCH_MAJOR

Synonym for AXIS_TOUCH_MAJOR.

int AXIS_TOUCH_MINOR

Synonym for AXIS_TOUCH_MINOR.

int AXIS_VSCROLL

Synonym for AXIS_VSCROLL.

int AXIS_WHEEL

Synonym for AXIS_WHEEL.

int AXIS_X

Synonym for AXIS_X.

int AXIS_Y

Synonym for AXIS_Y.

int AXIS_Z

Synonym for AXIS_Z.

int BUTTON_PRIMARY

Synonym for BUTTON_PRIMARY.

Public methods

static int findPointerIndex(MotionEvent event, int pointerId)

Call findPointerIndex(int).

static int getActionIndex(MotionEvent event)

Call getAction(), returning only the pointer index portion

static int getActionMasked(MotionEvent event)

Call getAction(), returning only the ACTION_MASK portion.

static float getAxisValue(MotionEvent event, int axis)

Get axis value for the first pointer index (may be an arbitrary pointer identifier).

static float getAxisValue(MotionEvent event, int axis, int pointerIndex)

Returns the value of the requested axis for the given pointer index (use getPointerId(MotionEvent, int) to find the pointer identifier for this index).

static int getButtonState(MotionEvent event)
static int getPointerCount(MotionEvent event)

The number of pointers of data contained in this event.

static int getPointerId(MotionEvent event, int pointerIndex)

Call getPointerId(int).

static int getSource(MotionEvent event)

Gets the source of the event.

static float getX(MotionEvent event, int pointerIndex)

Call getX(int).

static float getY(MotionEvent event, int pointerIndex)

Call getY(int).

static boolean isFromSource(MotionEvent event, int source)

Determines whether the event is from the given source.

Inherited methods

From class java.lang.Object

Constants

ACTION_HOVER_ENTER

int ACTION_HOVER_ENTER

Synonym for ACTION_HOVER_ENTER.

Constant Value: 9 (0x00000009)

ACTION_HOVER_EXIT

int ACTION_HOVER_EXIT

Synonym for ACTION_HOVER_EXIT.

Constant Value: 10 (0x0000000a)

ACTION_HOVER_MOVE

int ACTION_HOVER_MOVE

Synonym for ACTION_HOVER_MOVE.

Constant Value: 7 (0x00000007)

ACTION_MASK

int ACTION_MASK

Synonym for ACTION_MASK.

Constant Value: 255 (0x000000ff)

ACTION_POINTER_DOWN

int ACTION_POINTER_DOWN

Synonym for ACTION_POINTER_DOWN.

Constant Value: 5 (0x00000005)

ACTION_POINTER_INDEX_MASK

int ACTION_POINTER_INDEX_MASK

Synonym for ACTION_POINTER_INDEX_MASK.

Constant Value: 65280 (0x0000ff00)

ACTION_POINTER_INDEX_SHIFT

int ACTION_POINTER_INDEX_SHIFT

Synonym for ACTION_POINTER_INDEX_SHIFT.

Constant Value: 8 (0x00000008)

ACTION_POINTER_UP

int ACTION_POINTER_UP

Synonym for ACTION_POINTER_UP.

Constant Value: 6 (0x00000006)

ACTION_SCROLL

int ACTION_SCROLL

Synonym for ACTION_SCROLL.

Constant Value: 8 (0x00000008)

AXIS_BRAKE

int AXIS_BRAKE

Synonym for AXIS_BRAKE.

Constant Value: 23 (0x00000017)

AXIS_DISTANCE

int AXIS_DISTANCE

Synonym for AXIS_DISTANCE.

Constant Value: 24 (0x00000018)

AXIS_GAS

int AXIS_GAS

Synonym for AXIS_GAS.

Constant Value: 22 (0x00000016)

AXIS_GENERIC_1

int AXIS_GENERIC_1

Synonym for AXIS_GENERIC_1.

Constant Value: 32 (0x00000020)

AXIS_GENERIC_10

int AXIS_GENERIC_10

Synonym for AXIS_GENERIC_10.

Constant Value: 41 (0x00000029)

AXIS_GENERIC_11

int AXIS_GENERIC_11

Synonym for AXIS_GENERIC_11.

Constant Value: 42 (0x0000002a)

AXIS_GENERIC_12

int AXIS_GENERIC_12

Synonym for AXIS_GENERIC_12.

Constant Value: 43 (0x0000002b)

AXIS_GENERIC_13

int AXIS_GENERIC_13

Synonym for AXIS_GENERIC_13.

Constant Value: 44 (0x0000002c)

AXIS_GENERIC_14

int AXIS_GENERIC_14

Synonym for AXIS_GENERIC_14.

Constant Value: 45 (0x0000002d)

AXIS_GENERIC_15

int AXIS_GENERIC_15

Synonym for AXIS_GENERIC_15.

Constant Value: 46 (0x0000002e)

AXIS_GENERIC_16

int AXIS_GENERIC_16

Synonym for AXIS_GENERIC_16.

Constant Value: 47 (0x0000002f)

AXIS_GENERIC_2

int AXIS_GENERIC_2

Synonym for AXIS_GENERIC_2.

Constant Value: 33 (0x00000021)

AXIS_GENERIC_3

int AXIS_GENERIC_3

Synonym for AXIS_GENERIC_3.

Constant Value: 34 (0x00000022)

AXIS_GENERIC_4

int AXIS_GENERIC_4

Synonym for AXIS_GENERIC_4.

Constant Value: 35 (0x00000023)

AXIS_GENERIC_5

int AXIS_GENERIC_5

Synonym for AXIS_GENERIC_5.

Constant Value: 36 (0x00000024)

AXIS_GENERIC_6

int AXIS_GENERIC_6

Synonym for AXIS_GENERIC_6.

Constant Value: 37 (0x00000025)

AXIS_GENERIC_7

int AXIS_GENERIC_7

Synonym for AXIS_GENERIC_7.

Constant Value: 38 (0x00000026)

AXIS_GENERIC_8

int AXIS_GENERIC_8

Synonym for AXIS_GENERIC_8.

Constant Value: 39 (0x00000027)

AXIS_GENERIC_9

int AXIS_GENERIC_9

Synonym for AXIS_GENERIC_9.

Constant Value: 40 (0x00000028)

AXIS_HAT_X

int AXIS_HAT_X

Synonym for AXIS_HAT_X.

Constant Value: 15 (0x0000000f)

AXIS_HAT_Y

int AXIS_HAT_Y

Synonym for AXIS_HAT_Y.

Constant Value: 16 (0x00000010)

AXIS_HSCROLL

int AXIS_HSCROLL

Synonym for AXIS_HSCROLL.

Constant Value: 10 (0x0000000a)

AXIS_LTRIGGER

int AXIS_LTRIGGER

Synonym for AXIS_LTRIGGER.

Constant Value: 17 (0x00000011)

AXIS_ORIENTATION

int AXIS_ORIENTATION

Synonym for AXIS_ORIENTATION.

Constant Value: 8 (0x00000008)

AXIS_PRESSURE

int AXIS_PRESSURE

Synonym for AXIS_PRESSURE.

Constant Value: 2 (0x00000002)

AXIS_RELATIVE_X

int AXIS_RELATIVE_X

Synonym for AXIS_RELATIVE_X.

Constant Value: 27 (0x0000001b)

AXIS_RELATIVE_Y

int AXIS_RELATIVE_Y

Synonym for AXIS_RELATIVE_Y.

Constant Value: 28 (0x0000001c)

AXIS_RTRIGGER

int AXIS_RTRIGGER

Synonym for AXIS_RTRIGGER.

Constant Value: 18 (0x00000012)

AXIS_RUDDER

int AXIS_RUDDER

Synonym for AXIS_RUDDER.

Constant Value: 20 (0x00000014)

AXIS_RX

int AXIS_RX

Synonym for AXIS_RX.

Constant Value: 12 (0x0000000c)

AXIS_RY

int AXIS_RY

Synonym for AXIS_RY.

Constant Value: 13 (0x0000000d)

AXIS_RZ

int AXIS_RZ

Synonym for AXIS_RZ.

Constant Value: 14 (0x0000000e)

AXIS_SIZE

int AXIS_SIZE

Synonym for AXIS_SIZE.

Constant Value: 3 (0x00000003)

AXIS_THROTTLE

int AXIS_THROTTLE

Synonym for AXIS_THROTTLE.

Constant Value: 19 (0x00000013)

AXIS_TILT

int AXIS_TILT

Synonym for AXIS_TILT.

Constant Value: 25 (0x00000019)

AXIS_TOOL_MAJOR

int AXIS_TOOL_MAJOR

Synonym for AXIS_TOOL_MAJOR.

Constant Value: 6 (0x00000006)

AXIS_TOOL_MINOR

int AXIS_TOOL_MINOR

Synonym for AXIS_TOOL_MINOR.

Constant Value: 7 (0x00000007)

AXIS_TOUCH_MAJOR

int AXIS_TOUCH_MAJOR

Synonym for AXIS_TOUCH_MAJOR.

Constant Value: 4 (0x00000004)

AXIS_TOUCH_MINOR

int AXIS_TOUCH_MINOR

Synonym for AXIS_TOUCH_MINOR.

Constant Value: 5 (0x00000005)

AXIS_VSCROLL

int AXIS_VSCROLL

Synonym for AXIS_VSCROLL.

Constant Value: 9 (0x00000009)

AXIS_WHEEL

int AXIS_WHEEL

Synonym for AXIS_WHEEL.

Constant Value: 21 (0x00000015)

AXIS_X

int AXIS_X

Synonym for AXIS_X.

Constant Value: 0 (0x00000000)

AXIS_Y

int AXIS_Y

Synonym for AXIS_Y.

Constant Value: 1 (0x00000001)

AXIS_Z

int AXIS_Z

Synonym for AXIS_Z.

Constant Value: 11 (0x0000000b)

BUTTON_PRIMARY

int BUTTON_PRIMARY

Synonym for BUTTON_PRIMARY.

Constant Value: 1 (0x00000001)

Public methods

findPointerIndex

int findPointerIndex (MotionEvent event, 
                int pointerId)

Call findPointerIndex(int). If running on a pre-ECLAIR device, does nothing and returns -1.

Parameters
event MotionEvent
pointerId int
Returns
int

getActionIndex

int getActionIndex (MotionEvent event)

Call getAction(), returning only the pointer index portion

Parameters
event MotionEvent
Returns
int

getActionMasked

int getActionMasked (MotionEvent event)

Call getAction(), returning only the ACTION_MASK portion.

Parameters
event MotionEvent
Returns
int

getAxisValue

float getAxisValue (MotionEvent event, 
                int axis)

Get axis value for the first pointer index (may be an arbitrary pointer identifier).

Parameters
event MotionEvent
axis int: The axis identifier for the axis value to retrieve.
Returns
float

See also:

getAxisValue

float getAxisValue (MotionEvent event, 
                int axis, 
                int pointerIndex)

Returns the value of the requested axis for the given pointer index (use getPointerId(MotionEvent, int) to find the pointer identifier for this index).

Parameters
event MotionEvent
axis int: The axis identifier for the axis value to retrieve.
pointerIndex int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount(MotionEvent)-1.
Returns
float The value of the axis, or 0 if the axis is not available.

See also:

getButtonState

int getButtonState (MotionEvent event)

Returns
int

getPointerCount

int getPointerCount (MotionEvent event)

The number of pointers of data contained in this event. Always >= 1.

Parameters
event MotionEvent
Returns
int

getPointerId

int getPointerId (MotionEvent event, 
                int pointerIndex)

Call getPointerId(int). If running on a pre-ECLAIR device, IndexOutOfBoundsException is thrown.

Parameters
event MotionEvent
pointerIndex int
Returns
int

getSource

int getSource (MotionEvent event)

Gets the source of the event.

Parameters
event MotionEvent
Returns
int The event source or SOURCE_UNKNOWN if unknown.

getX

float getX (MotionEvent event, 
                int pointerIndex)

Call getX(int). If running on a pre-ECLAIR device, IndexOutOfBoundsException is thrown.

Parameters
event MotionEvent
pointerIndex int
Returns
float

getY

float getY (MotionEvent event, 
                int pointerIndex)

Call getY(int). If running on a pre-ECLAIR device, IndexOutOfBoundsException is thrown.

Parameters
event MotionEvent
pointerIndex int
Returns
float

isFromSource

boolean isFromSource (MotionEvent event, 
                int source)

Determines whether the event is from the given source.

Parameters
event MotionEvent
source int: The input source to check against.
Returns
boolean Whether the event is from the given source.

Hooray!