Added in API level 1

MotionEvent


class MotionEvent : InputEvent, Parcelable
kotlin.Any
   ↳ android.view.InputEvent
   ↳ android.view.MotionEvent

Object used to report movement (mouse, pen, finger, trackball) events. Motion events may hold either absolute or relative movements and other data, depending on the type of device.

Overview

Motion events describe movements in terms of an action code and a set of axis values. The action code specifies the state change that occurred such as a pointer going down or up. The axis values describe the position and other movement properties.

For example, when the user first touches the screen, the system delivers a touch event to the appropriate View with the action code ACTION_DOWN and a set of axis values that include the X and Y coordinates of the touch and information about the pressure, size and orientation of the contact area.

Some devices can report multiple movement traces at the same time. Multi-touch screens emit one movement trace for each finger. The individual fingers or other objects that generate movement traces are referred to as pointers. Motion events contain information about all of the pointers that are currently active even if some of them have not moved since the last event was delivered.

The number of pointers only ever changes by one as individual pointers go up and down, except when the gesture is canceled.

Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN). A pointer id remains valid until the pointer eventually goes up (indicated by ACTION_UP or ACTION_POINTER_UP) or when the gesture is canceled (indicated by ACTION_CANCEL).

The MotionEvent class provides many methods to query the position and other properties of pointers, such as getX(int), getY(int), #getAxisValue, getPointerId(int), getToolType(int), and many others. Most of these methods accept the pointer index as a parameter rather than the pointer id. The pointer index of each pointer in the event ranges from 0 to one less than the value returned by getPointerCount().

The order in which individual pointers appear within a motion event is undefined. Thus the pointer index of a pointer can change from one event to the next but the pointer id of a pointer is guaranteed to remain constant as long as the pointer remains active. Use the getPointerId(int) method to obtain the pointer id of a pointer to track it across all subsequent motion events in a gesture. Then for successive motion events, use the findPointerIndex(int) method to obtain the pointer index for a given pointer id in that motion event.

Mouse and stylus buttons can be retrieved using getButtonState(). It is a good idea to check the button state while handling ACTION_DOWN as part of a touch event. The application may choose to perform some different action if the touch event starts due to a secondary button click, such as presenting a context menu.

Batching

For efficiency, motion events with ACTION_MOVE may batch together multiple movement samples within a single object. The most current pointer coordinates are available using getX(int) and getY(int). Earlier coordinates within the batch are accessed using getHistoricalX(int,int) and getHistoricalY(int,int). The coordinates are "historical" only insofar as they are older than the current coordinates in the batch; however, they are still distinct from any other coordinates reported in prior motion events. To process all coordinates in the batch in time order, first consume the historical coordinates then consume the current coordinates.

Example: Consuming all samples for all pointers in a motion event in time order.

<code>
  void printSamples(MotionEvent ev) {
      final int historySize = ev.getHistorySize();
      final int pointerCount = ev.getPointerCount();
      for (int h = 0; h &lt; historySize; h++) {
          System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
          for (int p = 0; p &lt; pointerCount; p++) {
              System.out.printf("  pointer %d: (%f,%f)",
                  ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
          }
      }
      System.out.printf("At time %d:", ev.getEventTime());
      for (int p = 0; p &lt; pointerCount; p++) {
          System.out.printf("  pointer %d: (%f,%f)",
              ev.getPointerId(p), ev.getX(p), ev.getY(p));
      }
  }
  </code>

Device Types

The interpretation of the contents of a MotionEvent varies significantly depending on the source class of the device.

On pointing devices with source class InputDevice#SOURCE_CLASS_POINTER such as touch screens, the pointer coordinates specify absolute positions such as view X/Y coordinates. Each complete gesture is represented by a sequence of motion events with actions that describe pointer state transitions and movements. A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly. Pointer movements are described by motion events with ACTION_MOVE. Finally, a gesture end either when the final pointer goes up as represented by a motion event with ACTION_UP or when gesture is canceled with ACTION_CANCEL.

Some pointing devices such as mice may support vertical and/or horizontal scrolling. A scroll event is reported as a generic motion event with ACTION_SCROLL that includes the relative scroll offset in the AXIS_VSCROLL and AXIS_HSCROLL axes. See getAxisValue(int) for information about retrieving these additional axes.

On trackball devices with source class InputDevice#SOURCE_CLASS_TRACKBALL, the pointer coordinates specify relative movements as X/Y deltas. A trackball gesture consists of a sequence of movements described by motion events with ACTION_MOVE interspersed with occasional ACTION_DOWN or ACTION_UP motion events when the trackball button is pressed or released.

On joystick devices with source class InputDevice#SOURCE_CLASS_JOYSTICK, the pointer coordinates specify the absolute position of the joystick axes. The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds to the center position. More information about the set of available axes and the range of motion can be obtained using android.view.InputDevice#getMotionRange. Some common joystick axes are AXIS_X, AXIS_Y, AXIS_HAT_X, AXIS_HAT_Y, AXIS_Z and AXIS_RZ.

Refer to InputDevice for more information about how different kinds of input devices and sources represent pointer coordinates.

Consistency Guarantees

Motion events are always delivered to views as a consistent stream of events. What constitutes a consistent stream varies depending on the type of device. For touch events, consistency implies that pointers go down one at a time, move around as a group and then go up one at a time or are canceled.

While the framework tries to deliver consistent streams of motion events to views, it cannot guarantee it. Some events may be dropped or modified by containing views in the application before they are delivered thereby making the stream of events inconsistent. Views should always be prepared to handle ACTION_CANCEL and should tolerate anomalous situations such as receiving a new ACTION_DOWN without first having received an ACTION_UP for the prior gesture.

Summary

Nested classes

Transfer object for pointer coordinates.

Transfer object for pointer properties.

Constants
static Int

Constant for getActionMasked: A button has been pressed.

static Int

Constant for getActionMasked: A button has been released.

static Int

Constant for getActionMasked: The current gesture has been aborted.

static Int

Constant for getActionMasked: A pressed gesture has started, the motion contains the initial starting location.

static Int

Constant for getActionMasked: The pointer is not down but has entered the boundaries of a window or view.

static Int

Constant for getActionMasked: The pointer is not down but has exited the boundaries of a window or view.

static Int

Constant for getActionMasked: A change happened but the pointer is not down (unlike ACTION_MOVE).

static Int

Bit mask of the parts of the action code that are the action itself.

static Int

Constant for getActionMasked: A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).

static Int

Constant for getActionMasked: A movement has happened outside of the normal bounds of the UI element.

static Int

static Int

static Int

static Int

static Int

static Int

static Int

Constant for getActionMasked: A non-primary pointer has gone down.

static Int

static Int

static Int

Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP.

static Int

Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.

static Int

Constant for getActionMasked: A non-primary pointer has gone up.

static Int

Constant for getActionMasked: The motion event contains relative vertical and/or horizontal scroll offsets.

static Int

Constant for getActionMasked: A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

static Int

Axis constant: Brake axis of a motion event.

static Int

Axis constant: Distance axis of a motion event.

static Int

Axis constant: Gas axis of a motion event.

static Int

Axis constant: Generic 1 axis of a motion event.

static Int

Axis constant: Generic 10 axis of a motion event.

static Int

Axis constant: Generic 11 axis of a motion event.

static Int

Axis constant: Generic 12 axis of a motion event.

static Int

Axis constant: Generic 13 axis of a motion event.

static Int

Axis constant: Generic 14 axis of a motion event.

static Int

Axis constant: Generic 15 axis of a motion event.

static Int

Axis constant: Generic 16 axis of a motion event.

static Int

Axis constant: Generic 2 axis of a motion event.

static Int

Axis constant: Generic 3 axis of a motion event.

static Int

Axis constant: Generic 4 axis of a motion event.

static Int

Axis constant: Generic 5 axis of a motion event.

static Int

Axis constant: Generic 6 axis of a motion event.

static Int

Axis constant: Generic 7 axis of a motion event.

static Int

Axis constant: Generic 8 axis of a motion event.

static Int

Axis constant: Generic 9 axis of a motion event.

static Int

Axis constant: pinch scale factor of a motion event.

static Int

Axis constant: X scroll distance axis of a motion event.

static Int

Axis constant: Y scroll distance axis of a motion event.

static Int

Axis constant: X gesture offset axis of a motion event.

static Int

Axis constant: Y gesture offset axis of a motion event.

static Int

Axis constant: Hat X axis of a motion event.

static Int

Axis constant: Hat Y axis of a motion event.

static Int

Axis constant: Horizontal Scroll axis of a motion event.

static Int

Axis constant: Left Trigger axis of a motion event.

static Int

Axis constant: Orientation axis of a motion event.

static Int

Axis constant: Pressure axis of a motion event.

static Int

Axis constant: The movement of x position of a motion event.

static Int

Axis constant: The movement of y position of a motion event.

static Int

Axis constant: Right Trigger axis of a motion event.

static Int

Axis constant: Rudder axis of a motion event.

static Int

Axis constant: X Rotation axis of a motion event.

static Int

Axis constant: Y Rotation axis of a motion event.

static Int

Axis constant: Z Rotation axis of a motion event.

static Int

Axis constant: Generic scroll axis of a motion event.

static Int

Axis constant: Size axis of a motion event.

static Int

Axis constant: Throttle axis of a motion event.

static Int

Axis constant: Tilt axis of a motion event.

static Int

Axis constant: ToolMajor axis of a motion event.

static Int

Axis constant: ToolMinor axis of a motion event.

static Int

Axis constant: TouchMajor axis of a motion event.

static Int

Axis constant: TouchMinor axis of a motion event.

static Int

Axis constant: Vertical Scroll axis of a motion event.

static Int

Axis constant: Wheel axis of a motion event.

static Int

Axis constant: X axis of a motion event.

static Int

Axis constant: Y axis of a motion event.

static Int

Axis constant: Z axis of a motion event.

static Int

Button constant: Back button pressed (mouse back button).

static Int

Button constant: Forward button pressed (mouse forward button).

static Int

Button constant: Primary button (left mouse button).

static Int

Button constant: Secondary button (right mouse button).

static Int

Button constant: Primary stylus button pressed.

static Int

Button constant: Secondary stylus button pressed.

static Int

Button constant: Tertiary button (middle mouse button).

static Int

Classification constant: Ambiguous gesture.

static Int

Classification constant: Deep press.

static Int

Classification constant: None.

static Int

Classification constant: touchpad pinch.

static Int

Classification constant: touchpad scroll.

static Int

Flag indicating the motion event intersected the bottom edge of the screen.

static Int

Flag indicating the motion event intersected the left edge of the screen.

static Int

Flag indicating the motion event intersected the right edge of the screen.

static Int

Flag indicating the motion event intersected the top edge of the screen.

static Int

This flag is only set for events with ACTION_POINTER_UP and ACTION_CANCEL.

static Int

This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it and the event directly passed through the obscured area.

static Int

This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it and the event did not directly pass through the obscured area.

static Int

An invalid pointer id.

static Int

Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.

static Int

Tool type constant: The tool is a finger.

static Int

Tool type constant: The tool is a mouse.

static Int

Tool type constant: The tool is a stylus.

static Int

Tool type constant: Unknown tool type.

Inherited constants
Public methods
static String!

Returns a string that represents the symbolic name of the specified unmasked action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant such as "35" if unknown.

Unit
addBatch(eventTime: Long, x: Float, y: Float, pressure: Float, size: Float, metaState: Int)

Add a new movement to the batch of movements in this event.

Unit
addBatch(eventTime: Long, pointerCoords: Array<MotionEvent.PointerCoords!>!, metaState: Int)

Add a new movement to the batch of movements in this event.

static Int
axisFromString(symbolicName: String!)

Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".

static String!

Returns a string that represents the symbolic name of the specified axis such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.

Int
findPointerIndex(pointerId: Int)

Given a pointer identifier, find the index of its data in the event.

Int

Return the kind of action being performed.

Int

Gets which button has been modified during a press or release action.

Int

For ACTION_POINTER_DOWN or ACTION_POINTER_UP as returned by getActionMasked, this returns the associated pointer index.

Int

Return the masked action being performed, without pointer index information.

Float

getAxisValue(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getAxisValue(axis: Int, pointerIndex: Int)

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

Int

Gets the state of all buttons that are pressed such as a mouse or stylus button.

Int

Returns the classification for the current gesture.

Int

Gets the id for the device that this event came from.

Long

Returns the time (in ms) when the user originally pressed down to start a stream of position events.

Int

Returns a bitfield indicating which edges, if any, were touched by this MotionEvent.

Long

Retrieve the time this event occurred, in the android.os.SystemClock#uptimeMillis time base.

Long

Retrieve the time this event occurred, in the android.os.SystemClock#uptimeMillis time base but with nanosecond precision.

Int

Gets the motion event flags.

Float

getHistoricalAxisValue(int,int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalAxisValue(axis: Int, pointerIndex: Int, pos: Int)

Returns the historical value of the requested axis, as per getAxisValue(int,int), occurred between this event and the previous event for the given pointer.

Long

Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base.

Long

Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base but with nanosecond (instead of millisecond) precision.

Float

getHistoricalOrientation(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalOrientation(pointerIndex: Int, pos: Int)

Returns a historical orientation coordinate, as per getOrientation(int), that occurred between this event and the previous event for the given pointer.

Unit
getHistoricalPointerCoords(pointerIndex: Int, pos: Int, outPointerCoords: MotionEvent.PointerCoords!)

Populates a PointerCoords object with historical pointer coordinate data, as per getPointerCoords, that occurred between this event and the previous event for the given pointer.

Float

getHistoricalPressure(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalPressure(pointerIndex: Int, pos: Int)

Returns a historical pressure coordinate, as per getPressure(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalSize(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalSize(pointerIndex: Int, pos: Int)

Returns a historical size coordinate, as per getSize(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalToolMajor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalToolMajor(pointerIndex: Int, pos: Int)

Returns a historical tool major axis coordinate, as per getToolMajor(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalToolMinor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalToolMinor(pointerIndex: Int, pos: Int)

Returns a historical tool minor axis coordinate, as per getToolMinor(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalTouchMajor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalTouchMajor(pointerIndex: Int, pos: Int)

Returns a historical touch major axis coordinate, as per getTouchMajor(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalTouchMinor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalTouchMinor(pointerIndex: Int, pos: Int)

Returns a historical touch minor axis coordinate, as per getTouchMinor(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalX(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalX(pointerIndex: Int, pos: Int)

Returns a historical X coordinate, as per getX(int), that occurred between this event and the previous event for the given pointer.

Float

getHistoricalY(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getHistoricalY(pointerIndex: Int, pos: Int)

Returns a historical Y coordinate, as per getY(int), that occurred between this event and the previous event for the given pointer.

Int

Returns the number of historical points in this event.

Int

Returns the state of any meta / modifier keys that were in effect when the event was generated.

Float

getOrientation(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getOrientation(pointerIndex: Int)

Returns the value of AXIS_ORIENTATION for the given pointer index.

Unit
getPointerCoords(pointerIndex: Int, outPointerCoords: MotionEvent.PointerCoords!)

Populates a PointerCoords object with pointer coordinate data for the specified pointer index.

Int

The number of pointers of data contained in this event.

Int
getPointerId(pointerIndex: Int)

Return the pointer identifier associated with a particular pointer data index in this event.

Unit
getPointerProperties(pointerIndex: Int, outPointerProperties: MotionEvent.PointerProperties!)

Populates a PointerProperties object with pointer properties for the specified pointer index.

Float

getPressure(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getPressure(pointerIndex: Int)

Returns the value of AXIS_PRESSURE for the given pointer index.

Float

Equivalent to getRawX(int) for pointer index 0 (regardless of the pointer identifier).

Float
getRawX(pointerIndex: Int)

Returns the X coordinate of the pointer referenced by pointerIndex for this motion event.

Float

Equivalent to getRawY(int) for pointer index 0 (regardless of the pointer identifier).

Float
getRawY(pointerIndex: Int)

Returns the Y coordinate of the pointer referenced by pointerIndex for this motion event.

Float

getSize(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getSize(pointerIndex: Int)

Returns the value of AXIS_SIZE for the given pointer index.

Int

Gets the source of the event.

Float

getToolMajor(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getToolMajor(pointerIndex: Int)

Returns the value of AXIS_TOOL_MAJOR for the given pointer index.

Float

getToolMinor(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getToolMinor(pointerIndex: Int)

Returns the value of AXIS_TOOL_MINOR for the given pointer index.

Int
getToolType(pointerIndex: Int)

Gets the tool type of a pointer for the given pointer index.

Float

getTouchMajor(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getTouchMajor(pointerIndex: Int)

Returns the value of AXIS_TOUCH_MAJOR for the given pointer index.

Float

getTouchMinor(int) for the first pointer index (may be an arbitrary pointer identifier).

Float
getTouchMinor(pointerIndex: Int)

Returns the value of AXIS_TOUCH_MINOR for the given pointer index.

Float

Equivalent to getX(int) for pointer index 0 (regardless of the pointer identifier).

Float
getX(pointerIndex: Int)

Returns the X coordinate of the pointer referenced by pointerIndex for this motion event.

Float

Return the precision of the X coordinates being reported.

Float

Equivalent to getY(int) for pointer index 0 (regardless of the pointer identifier).

Float
getY(pointerIndex: Int)

Returns the Y coordinate of the pointer referenced by pointerIndex for this motion event.

Float

Return the precision of the Y coordinates being reported.

Boolean

Checks if a mouse or stylus button (or combination of buttons) is pressed.

static MotionEvent?
obtain(downTime: Long, eventTime: Long, action: Int, pointerCount: Int, pointerProperties: Array<MotionEvent.PointerProperties!>, pointerCoords: Array<MotionEvent.PointerCoords!>, metaState: Int, buttonState: Int, xPrecision: Float, yPrecision: Float, deviceId: Int, edgeFlags: Int, source: Int, displayId: Int, flags: Int, classification: Int)

Create a new MotionEvent, filling in all of the basic values that define the motion.

static MotionEvent!
obtain(downTime: Long, eventTime: Long, action: Int, pointerCount: Int, pointerProperties: Array<MotionEvent.PointerProperties!>!, pointerCoords: Array<MotionEvent.PointerCoords!>!, metaState: Int, buttonState: Int, xPrecision: Float, yPrecision: Float, deviceId: Int, edgeFlags: Int, source: Int, flags: Int)

Create a new MotionEvent, filling in all of the basic values that define the motion.

static MotionEvent!
obtain(downTime: Long, eventTime: Long, action: Int, pointerCount: Int, pointerIds: IntArray!, pointerCoords: Array<MotionEvent.PointerCoords!>!, metaState: Int, xPrecision: Float, yPrecision: Float, deviceId: Int, edgeFlags: Int, source: Int, flags: Int)

Create a new MotionEvent, filling in all of the basic values that define the motion.

static MotionEvent!
obtain(downTime: Long, eventTime: Long, action: Int, x: Float, y: Float, pressure: Float, size: Float, metaState: Int, xPrecision: Float, yPrecision: Float, deviceId: Int, edgeFlags: Int)

Create a new MotionEvent, filling in all of the basic values that define the motion.

static MotionEvent!
obtain(downTime: Long, eventTime: Long, action: Int, pointerCount: Int, x: Float, y: Float, pressure: Float, size: Float, metaState: Int, xPrecision: Float, yPrecision: Float, deviceId: Int, edgeFlags: Int)

Create a new MotionEvent, filling in all of the basic values that define the motion.

static MotionEvent!
obtain(downTime: Long, eventTime: Long, action: Int, x: Float, y: Float, metaState: Int)

Create a new MotionEvent, filling in a subset of the basic motion values.

static MotionEvent!

Create a new MotionEvent, copying from an existing one.

static MotionEvent!

Create a new MotionEvent, copying from an existing one, but not including any historical point information.

Unit
offsetLocation(deltaX: Float, deltaY: Float)

Adjust this event's location.

Unit

Recycle the MotionEvent, to be re-used by a later caller.

Unit
setAction(action: Int)

Sets this event's action.

Unit
setEdgeFlags(flags: Int)

Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.

Unit

Set this event's location.

Unit
setSource(source: Int)

String

Unit
transform(matrix: Matrix!)

Applies a transformation matrix to all of the points in the event.

Unit
writeToParcel(out: Parcel, flags: Int)

Protected methods
Unit

Inherited functions
Properties
static Parcelable.Creator<MotionEvent!>

Constants

ACTION_BUTTON_PRESS

Added in API level 23
static val ACTION_BUTTON_PRESS: Int

Constant for getActionMasked: A button has been pressed.

Use getActionButton() to get which button was pressed.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 11

ACTION_BUTTON_RELEASE

Added in API level 23
static val ACTION_BUTTON_RELEASE: Int

Constant for getActionMasked: A button has been released.

Use getActionButton() to get which button was released.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 12

ACTION_CANCEL

Added in API level 1
static val ACTION_CANCEL: Int

Constant for getActionMasked: The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.

Value: 3

ACTION_DOWN

Added in API level 1
static val ACTION_DOWN: Int

Constant for getActionMasked: A pressed gesture has started, the motion contains the initial starting location.

This is also a good time to check the button state to distinguish secondary and tertiary button clicks and handle them appropriately. Use getButtonState to retrieve the button state.

Value: 0

ACTION_HOVER_ENTER

Added in API level 14
static val ACTION_HOVER_ENTER: Int

Constant for getActionMasked: The pointer is not down but has entered the boundaries of a window or view.

This action is always delivered to the window or view under the pointer.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 9

ACTION_HOVER_EXIT

Added in API level 14
static val ACTION_HOVER_EXIT: Int

Constant for getActionMasked: The pointer is not down but has exited the boundaries of a window or view.

This action is always delivered to the window or view that was previously under the pointer.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 10

ACTION_HOVER_MOVE

Added in API level 12
static val ACTION_HOVER_MOVE: Int

Constant for getActionMasked: A change happened but the pointer is not down (unlike ACTION_MOVE). The motion contains the most recent point, as well as any intermediate points since the last hover move event.

This action is always delivered to the window or view under the pointer.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 7

ACTION_MASK

Added in API level 5
static val ACTION_MASK: Int

Bit mask of the parts of the action code that are the action itself.

Value: 255

ACTION_MOVE

Added in API level 1
static val ACTION_MOVE: Int

Constant for getActionMasked: A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.

Value: 2

ACTION_OUTSIDE

Added in API level 3
static val ACTION_OUTSIDE: Int

Constant for getActionMasked: A movement has happened outside of the normal bounds of the UI element. This does not provide a full gesture, but only the initial location of the movement/touch.

Note: Because the location of any event will be outside the bounds of the view hierarchy, it will not get dispatched to any children of a ViewGroup by default. Therefore, movements with ACTION_OUTSIDE should be handled in either the root View or in the appropriate Window.Callback (e.g. android.app.Activity or android.app.Dialog).

Value: 4

ACTION_POINTER_1_DOWN

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_1_DOWN: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Value: 5

ACTION_POINTER_1_UP

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_1_UP: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Value: 6

ACTION_POINTER_2_DOWN

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_2_DOWN: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Value: 261

ACTION_POINTER_2_UP

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_2_UP: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Value: 262

ACTION_POINTER_3_DOWN

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_3_DOWN: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Value: 517

ACTION_POINTER_3_UP

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_3_UP: Int

Deprecated: Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Value: 518

ACTION_POINTER_DOWN

Added in API level 5
static val ACTION_POINTER_DOWN: Int

Constant for getActionMasked: A non-primary pointer has gone down.

Use getActionIndex to retrieve the index of the pointer that changed.

The index is encoded in the ACTION_POINTER_INDEX_MASK bits of the unmasked action returned by getAction.

Value: 5

ACTION_POINTER_ID_MASK

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_ID_MASK: Int

Deprecated: Renamed to ACTION_POINTER_INDEX_MASK to match the actual data contained in these bits.

Value: 65280

ACTION_POINTER_ID_SHIFT

Added in API level 5
Deprecated in API level 15
static val ACTION_POINTER_ID_SHIFT: Int

Deprecated: Renamed to ACTION_POINTER_INDEX_SHIFT to match the actual data contained in these bits.

Value: 8

ACTION_POINTER_INDEX_MASK

Added in API level 8
static val ACTION_POINTER_INDEX_MASK: Int

Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP. Shifting down by ACTION_POINTER_INDEX_SHIFT provides the actual pointer index where the data for the pointer going up or down can be found; you can get its identifier with getPointerId(int) and the actual data with getX(int) etc.

Value: 65280

See Also

ACTION_POINTER_INDEX_SHIFT

Added in API level 8
static val ACTION_POINTER_INDEX_SHIFT: Int

Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.

Value: 8

See Also

ACTION_POINTER_UP

Added in API level 5
static val ACTION_POINTER_UP: Int

Constant for getActionMasked: A non-primary pointer has gone up.

Use getActionIndex to retrieve the index of the pointer that changed.

The index is encoded in the ACTION_POINTER_INDEX_MASK bits of the unmasked action returned by getAction.

Value: 6

ACTION_SCROLL

Added in API level 12
static val ACTION_SCROLL: Int

Constant for getActionMasked: The motion event contains relative vertical and/or horizontal scroll offsets. Use getAxisValue(int) to retrieve the information from AXIS_VSCROLL and AXIS_HSCROLL. The pointer may or may not be down when this event is dispatched.

This action is always delivered to the window or view under the pointer, which may not be the window or view currently touched.

This action is not a touch event so it is delivered to View#onGenericMotionEvent(MotionEvent) rather than View#onTouchEvent(MotionEvent).

Value: 8

ACTION_UP

Added in API level 1
static val ACTION_UP: Int

Constant for getActionMasked: A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Value: 1

AXIS_BRAKE

Added in API level 12
static val AXIS_BRAKE: Int

Axis constant: Brake axis of a motion event.

  • For a joystick, reports the absolute position of the brake control. The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).

Value: 23

AXIS_DISTANCE

Added in API level 14
static val AXIS_DISTANCE: Int

Axis constant: Distance axis of a motion event.

  • For a stylus, reports the distance of the stylus from the screen. A value of 0.0 indicates direct contact and larger values indicate increasing distance from the surface.

Value: 24

AXIS_GAS

Added in API level 12
static val AXIS_GAS: Int

Axis constant: Gas axis of a motion event.

  • For a joystick, reports the absolute position of the gas (accelerator) control. The value is normalized to a range from 0.0 (no acceleration) to 1.0 (maximum acceleration).

Value: 22

AXIS_GENERIC_1

Added in API level 12
static val AXIS_GENERIC_1: Int

Axis constant: Generic 1 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 32

AXIS_GENERIC_10

Added in API level 12
static val AXIS_GENERIC_10: Int

Axis constant: Generic 10 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 41

AXIS_GENERIC_11

Added in API level 12
static val AXIS_GENERIC_11: Int

Axis constant: Generic 11 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 42

AXIS_GENERIC_12

Added in API level 12
static val AXIS_GENERIC_12: Int

Axis constant: Generic 12 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 43

AXIS_GENERIC_13

Added in API level 12
static val AXIS_GENERIC_13: Int

Axis constant: Generic 13 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 44

AXIS_GENERIC_14

Added in API level 12
static val AXIS_GENERIC_14: Int

Axis constant: Generic 14 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 45

AXIS_GENERIC_15

Added in API level 12
static val AXIS_GENERIC_15: Int

Axis constant: Generic 15 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 46

AXIS_GENERIC_16

Added in API level 12
static val AXIS_GENERIC_16: Int

Axis constant: Generic 16 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 47

AXIS_GENERIC_2

Added in API level 12
static val AXIS_GENERIC_2: Int

Axis constant: Generic 2 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 33

AXIS_GENERIC_3

Added in API level 12
static val AXIS_GENERIC_3: Int

Axis constant: Generic 3 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 34

AXIS_GENERIC_4

Added in API level 12
static val AXIS_GENERIC_4: Int

Axis constant: Generic 4 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 35

AXIS_GENERIC_5

Added in API level 12
static val AXIS_GENERIC_5: Int

Axis constant: Generic 5 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 36

AXIS_GENERIC_6

Added in API level 12
static val AXIS_GENERIC_6: Int

Axis constant: Generic 6 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 37

AXIS_GENERIC_7

Added in API level 12
static val AXIS_GENERIC_7: Int

Axis constant: Generic 7 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 38

AXIS_GENERIC_8

Added in API level 12
static val AXIS_GENERIC_8: Int

Axis constant: Generic 8 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 39

AXIS_GENERIC_9

Added in API level 12
static val AXIS_GENERIC_9: Int

Axis constant: Generic 9 axis of a motion event. The interpretation of a generic axis is device-specific.

Value: 40

AXIS_GESTURE_PINCH_SCALE_FACTOR

Added in API level 34
static val AXIS_GESTURE_PINCH_SCALE_FACTOR: Int

Axis constant: pinch scale factor of a motion event.

  • For a touch pad, reports the change in distance between the fingers when the user is making a pinch gesture, as a proportion of the previous distance. For example, if the fingers were 50 units apart and are now 52 units apart, the scale factor would be 1.04.
These values are relative to the state from the last event, not accumulated, so developers should make sure to process this axis value for all batched historical events.

This axis is only set on the first pointer in a motion event.

Value: 52

AXIS_GESTURE_SCROLL_X_DISTANCE

Added in API level 34
static val AXIS_GESTURE_SCROLL_X_DISTANCE: Int

Axis constant: X scroll distance axis of a motion event.

  • For a touch pad, reports the distance that should be scrolled in the X axis as a result of the user's two-finger scroll gesture, in display pixels.
These values are relative to the state from the last event, not accumulated, so developers should make sure to process this axis value for all batched historical events.

This axis is only set on the first pointer in a motion event.

Value: 50

AXIS_GESTURE_SCROLL_Y_DISTANCE

Added in API level 34
static val AXIS_GESTURE_SCROLL_Y_DISTANCE: Int

Axis constant: Y scroll distance axis of a motion event. The same as AXIS_GESTURE_SCROLL_X_DISTANCE, but for the Y axis.

Value: 51

AXIS_GESTURE_X_OFFSET

Added in API level 34
static val AXIS_GESTURE_X_OFFSET: Int

Axis constant: X gesture offset axis of a motion event.

  • For a touch pad, reports the distance that a swipe gesture has moved in the X axis, as a proportion of the touch pad's size. For example, if a touch pad is 1000 units wide, and a swipe gesture starts at X = 500 then moves to X = 400, this axis would have a value of -0.1.
These values are relative to the state from the last event, not accumulated, so developers should make sure to process this axis value for all batched historical events.

This axis is only set on the first pointer in a motion event.

Value: 48

AXIS_GESTURE_Y_OFFSET

Added in API level 34
static val AXIS_GESTURE_Y_OFFSET: Int

Axis constant: Y gesture offset axis of a motion event. The same as AXIS_GESTURE_X_OFFSET, but for the Y axis.

Value: 49

AXIS_HAT_X

Added in API level 12
static val AXIS_HAT_X: Int

Axis constant: Hat X axis of a motion event.

  • For a joystick, reports the absolute X position of the directional hat control. The value is normalized to a range from -1.0 (left) to 1.0 (right).

Value: 15

AXIS_HAT_Y

Added in API level 12
static val AXIS_HAT_Y: Int

Axis constant: Hat Y axis of a motion event.

  • For a joystick, reports the absolute Y position of the directional hat control. The value is normalized to a range from -1.0 (up) to 1.0 (down).

Value: 16

AXIS_HSCROLL

Added in API level 12
static val AXIS_HSCROLL: Int

Axis constant: Horizontal Scroll axis of a motion event.

  • For a mouse, reports the relative movement of the horizontal scroll wheel. The value is normalized to a range from -1.0 (left) to 1.0 (right).

This axis should be used to scroll views horizontally.

Value: 10

AXIS_LTRIGGER

Added in API level 12
static val AXIS_LTRIGGER: Int

Axis constant: Left Trigger axis of a motion event.

  • For a joystick, reports the absolute position of the left trigger control. The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).

Value: 17

AXIS_ORIENTATION

Added in API level 12
static val AXIS_ORIENTATION: Int

Axis constant: Orientation axis of a motion event.

  • For a touch screen or touch pad, reports the orientation of the finger or tool in radians relative to the vertical plane of the device. An angle of 0 radians indicates that the major axis of contact is oriented upwards, is perfectly circular or is of unknown orientation. A positive angle indicates that the major axis of contact is oriented to the right. A negative angle indicates that the major axis of contact is oriented to the left. The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians (finger pointing fully right).
  • For a stylus, the orientation indicates the direction in which the stylus is pointing in relation to the vertical axis of the current orientation of the screen. The range is from -PI radians to PI radians, where 0 is pointing up, -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians is pointing right. See also AXIS_TILT.

Value: 8

AXIS_PRESSURE

Added in API level 12
static val AXIS_PRESSURE: Int

Axis constant: Pressure axis of a motion event.

  • For a touch screen or touch pad, reports the approximate pressure applied to the surface by a finger or other tool. The value is normalized to a range from 0 (no pressure at all) to 1 (normal pressure), although values higher than 1 may be generated depending on the calibration of the input device.
  • For a trackball, the value is set to 1 if the trackball button is pressed or 0 otherwise.
  • For a mouse, the value is set to 1 if the primary mouse button is pressed or 0 otherwise.

Value: 2

AXIS_RELATIVE_X

Added in API level 24
static val AXIS_RELATIVE_X: Int

Axis constant: The movement of x position of a motion event.

  • For a mouse, reports a difference of x position between the previous position. This is useful when pointer is captured, in that case the mouse pointer doesn't change the location but this axis reports the difference which allows the app to see how the mouse is moved.

Value: 27

AXIS_RELATIVE_Y

Added in API level 24
static val AXIS_RELATIVE_Y: Int

Axis constant: The movement of y position of a motion event.

This is similar to AXIS_RELATIVE_X but for y-axis.

Value: 28

AXIS_RTRIGGER

Added in API level 12
static val AXIS_RTRIGGER: Int

Axis constant: Right Trigger axis of a motion event.

  • For a joystick, reports the absolute position of the right trigger control. The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).

Value: 18

AXIS_RUDDER

Added in API level 12
static val AXIS_RUDDER: Int

Axis constant: Rudder axis of a motion event.

  • For a joystick, reports the absolute position of the rudder control. The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).

Value: 20

AXIS_RX

Added in API level 12
static val AXIS_RX: Int

Axis constant: X Rotation axis of a motion event.

  • For a joystick, reports the absolute rotation angle about the X axis. The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).

Value: 12

AXIS_RY

Added in API level 12
static val AXIS_RY: Int

Axis constant: Y Rotation axis of a motion event.

  • For a joystick, reports the absolute rotation angle about the Y axis. The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).

Value: 13

AXIS_RZ

Added in API level 12
static val AXIS_RZ: Int

Axis constant: Z Rotation axis of a motion event.

  • For a joystick, reports the absolute rotation angle about the Z axis. The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). On game pads with two analog joysticks, this axis is often reinterpreted to report the absolute Y position of the second joystick instead.

Value: 14

AXIS_SCROLL

Added in API level 26
static val AXIS_SCROLL: Int

Axis constant: Generic scroll axis of a motion event.

  • Reports the relative movement of the generic scrolling device.

This axis should be used for scroll events that are neither strictly vertical nor horizontal. A good example would be the rotation of a rotary encoder input device.

Value: 26

AXIS_SIZE

Added in API level 12
static val AXIS_SIZE: Int

Axis constant: Size axis of a motion event.

  • For a touch screen or touch pad, reports the approximate size of the contact area in relation to the maximum detectable size for the device. The value is normalized to a range from 0 (smallest detectable size) to 1 (largest detectable size), although it is not a linear scale. The value of size can be used to determine fat touch events. To obtain calibrated size information, use AXIS_TOUCH_MAJOR or AXIS_TOOL_MAJOR.

Value: 3

AXIS_THROTTLE

Added in API level 12
static val AXIS_THROTTLE: Int

Axis constant: Throttle axis of a motion event.

  • For a joystick, reports the absolute position of the throttle control. The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).

Value: 19

AXIS_TILT

Added in API level 14
static val AXIS_TILT: Int

Axis constant: Tilt axis of a motion event.

  • For a stylus, reports the tilt angle of the stylus in radians where 0 radians indicates that the stylus is being held perpendicular to the surface, and PI/2 radians indicates that the stylus is being held flat against the surface.

Value: 25

AXIS_TOOL_MAJOR

Added in API level 12
static val AXIS_TOOL_MAJOR: Int

Axis constant: ToolMajor axis of a motion event.

  • For a touch screen, reports the length of the major axis of an ellipse that represents the size of the approaching finger or tool used to make contact.
  • For a touch pad, reports the length of the major axis of an ellipse that represents the size of the approaching finger or tool used to make contact. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.

When the touch is circular, the major and minor axis lengths will be equal to one another.

The tool size may be larger than the touch size since the tool may not be fully in contact with the touch sensor.

Value: 6

AXIS_TOOL_MINOR

Added in API level 12
static val AXIS_TOOL_MINOR: Int

Axis constant: ToolMinor axis of a motion event.

  • For a touch screen, reports the length of the minor axis of an ellipse that represents the size of the approaching finger or tool used to make contact.
  • For a touch pad, reports the length of the minor axis of an ellipse that represents the size of the approaching finger or tool used to make contact. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.

When the touch is circular, the major and minor axis lengths will be equal to one another.

The tool size may be larger than the touch size since the tool may not be fully in contact with the touch sensor.

Value: 7

AXIS_TOUCH_MAJOR

Added in API level 12
static val AXIS_TOUCH_MAJOR: Int

Axis constant: TouchMajor axis of a motion event.

  • For a touch screen, reports the length of the major axis of an ellipse that represents the touch area at the point of contact. The units are display pixels.
  • For a touch pad, reports the length of the major axis of an ellipse that represents the touch area at the point of contact. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.

Value: 4

AXIS_TOUCH_MINOR

Added in API level 12
static val AXIS_TOUCH_MINOR: Int

Axis constant: TouchMinor axis of a motion event.

  • For a touch screen, reports the length of the minor axis of an ellipse that represents the touch area at the point of contact. The units are display pixels.
  • For a touch pad, reports the length of the minor axis of an ellipse that represents the touch area at the point of contact. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.

When the touch is circular, the major and minor axis lengths will be equal to one another.

Value: 5

AXIS_VSCROLL

Added in API level 12
static val AXIS_VSCROLL: Int

Axis constant: Vertical Scroll axis of a motion event.

  • For a mouse, reports the relative movement of the vertical scroll wheel. The value is normalized to a range from -1.0 (down) to 1.0 (up).

This axis should be used to scroll views vertically.

Value: 9

AXIS_WHEEL

Added in API level 12
static val AXIS_WHEEL: Int

Axis constant: Wheel axis of a motion event.

  • For a joystick, reports the absolute position of the steering wheel control. The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).

Value: 21

AXIS_X

Added in API level 12
static val AXIS_X: Int

Axis constant: X axis of a motion event.

  • For a touch screen, reports the absolute X screen position of the center of the touch contact area. The units are display pixels.
  • For a touch pad, reports the absolute X surface position of the center of the touch contact area. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.
  • For a mouse, reports the absolute X screen position of the mouse pointer. The units are display pixels.
  • For a trackball, reports the relative horizontal displacement of the trackball. The value is normalized to a range from -1.0 (left) to 1.0 (right).
  • For a joystick, reports the absolute X position of the joystick. The value is normalized to a range from -1.0 (left) to 1.0 (right).

Value: 0

AXIS_Y

Added in API level 12
static val AXIS_Y: Int

Axis constant: Y axis of a motion event.

  • For a touch screen, reports the absolute Y screen position of the center of the touch contact area. The units are display pixels.
  • For a touch pad, reports the absolute Y surface position of the center of the touch contact area. The units are device-dependent; use InputDevice#getMotionRange(int) to query the effective range of values.
  • For a mouse, reports the absolute Y screen position of the mouse pointer. The units are display pixels.
  • For a trackball, reports the relative vertical displacement of the trackball. The value is normalized to a range from -1.0 (up) to 1.0 (down).
  • For a joystick, reports the absolute Y position of the joystick. The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).

Value: 1

AXIS_Z

Added in API level 12
static val AXIS_Z: Int

Axis constant: Z axis of a motion event.

  • For a joystick, reports the absolute Z position of the joystick. The value is normalized to a range from -1.0 (high) to 1.0 (low). On game pads with two analog joysticks, this axis is often reinterpreted to report the absolute X position of the second joystick instead.

Value: 11

BUTTON_BACK

Added in API level 14
static val BUTTON_BACK: Int

Button constant: Back button pressed (mouse back button).

The system may send a KeyEvent#KEYCODE_BACK key press to the application when this button is pressed.

Value: 8

See Also

BUTTON_FORWARD

Added in API level 14
static val BUTTON_FORWARD: Int

Button constant: Forward button pressed (mouse forward button).

The system may send a KeyEvent#KEYCODE_FORWARD key press to the application when this button is pressed.

Value: 16

See Also

BUTTON_PRIMARY

Added in API level 14
static val BUTTON_PRIMARY: Int

Button constant: Primary button (left mouse button). This button constant is not set in response to simple touches with a finger or stylus tip. The user must actually push a button.

Value: 1

See Also

BUTTON_SECONDARY

Added in API level 14
static val BUTTON_SECONDARY: Int

Button constant: Secondary button (right mouse button).

Value: 2

See Also

BUTTON_STYLUS_PRIMARY

Added in API level 23
static val BUTTON_STYLUS_PRIMARY: Int

Button constant: Primary stylus button pressed.

Value: 32

See Also

BUTTON_STYLUS_SECONDARY

Added in API level 23
static val BUTTON_STYLUS_SECONDARY: Int

Button constant: Secondary stylus button pressed.

Value: 64

See Also

BUTTON_TERTIARY

Added in API level 14
static val BUTTON_TERTIARY: Int

Button constant: Tertiary button (middle mouse button).

Value: 4

See Also

CLASSIFICATION_AMBIGUOUS_GESTURE

Added in API level 29
static val CLASSIFICATION_AMBIGUOUS_GESTURE: Int

Classification constant: Ambiguous gesture. The user's intent with respect to the current event stream is not yet determined. Gestural actions, such as scrolling, should be inhibited until the classification resolves to another value or the event stream ends.

Value: 1

CLASSIFICATION_DEEP_PRESS

Added in API level 29
static val CLASSIFICATION_DEEP_PRESS: Int

Classification constant: Deep press. The current event stream represents the user intentionally pressing harder on the screen. This classification type should be used to accelerate the long press behaviour.

Value: 2

CLASSIFICATION_NONE

Added in API level 29
static val CLASSIFICATION_NONE: Int

Classification constant: None. No additional information is available about the current motion event stream.

Value: 0

CLASSIFICATION_PINCH

Added in API level 34
static val CLASSIFICATION_PINCH: Int

Classification constant: touchpad pinch. The current event stream represents the user pinching with two fingers on a touchpad. The gesture is centered around the current cursor position.

Value: 5

CLASSIFICATION_TWO_FINGER_SWIPE

Added in API level 34
static val CLASSIFICATION_TWO_FINGER_SWIPE: Int

Classification constant: touchpad scroll. The current event stream represents the user scrolling with two fingers on a touchpad.

Value: 3

EDGE_BOTTOM

Added in API level 1
static val EDGE_BOTTOM: Int

Flag indicating the motion event intersected the bottom edge of the screen.

Value: 2

EDGE_LEFT

Added in API level 1
static val EDGE_LEFT: Int

Flag indicating the motion event intersected the left edge of the screen.

Value: 4

EDGE_RIGHT

Added in API level 1
static val EDGE_RIGHT: Int

Flag indicating the motion event intersected the right edge of the screen.

Value: 8

EDGE_TOP

Added in API level 1
static val EDGE_TOP: Int

Flag indicating the motion event intersected the top edge of the screen.

Value: 1

FLAG_CANCELED

Added in API level 33
static val FLAG_CANCELED: Int

This flag is only set for events with ACTION_POINTER_UP and ACTION_CANCEL. It indicates that the pointer going up was an unintentional user touch. When FLAG_CANCELED is set, the typical actions that occur in response for a pointer going up (such as click handlers, end of drawing) should be aborted. This flag is typically set when the user was accidentally touching the screen, such as by gripping the device, or placing the palm on the screen.

Value: 32

FLAG_WINDOW_IS_OBSCURED

Added in API level 9
static val FLAG_WINDOW_IS_OBSCURED: Int

This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it and the event directly passed through the obscured area. A security sensitive application can check this flag to identify situations in which a malicious application may have covered up part of its content for the purpose of misleading the user or hijacking touches. An appropriate response might be to drop the suspect touches or to take additional precautions to confirm the user's actual intent.

Value: 1

FLAG_WINDOW_IS_PARTIALLY_OBSCURED

Added in API level 29
static val FLAG_WINDOW_IS_PARTIALLY_OBSCURED: Int

This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it and the event did not directly pass through the obscured area. A security sensitive application can check this flag to identify situations in which a malicious application may have covered up part of its content for the purpose of misleading the user or hijacking touches. An appropriate response might be to drop the suspect touches or to take additional precautions to confirm the user's actual intent. Unlike FLAG_WINDOW_IS_OBSCURED, this is only true if the window that received this event is obstructed in areas other than the touched location.

Value: 2

INVALID_POINTER_ID

Added in API level 14
static val INVALID_POINTER_ID: Int

An invalid pointer id. This value (-1) can be used as a placeholder to indicate that a pointer id has not been assigned or is not available. It cannot appear as a pointer id inside a MotionEvent.

Value: -1

TOOL_TYPE_ERASER

Added in API level 14
static val TOOL_TYPE_ERASER: Int

Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.

Value: 4

See Also

TOOL_TYPE_FINGER

Added in API level 14
static val TOOL_TYPE_FINGER: Int

Tool type constant: The tool is a finger.

Value: 1

See Also

TOOL_TYPE_MOUSE

Added in API level 14
static val TOOL_TYPE_MOUSE: Int

Tool type constant: The tool is a mouse.

Value: 3

See Also

TOOL_TYPE_STYLUS

Added in API level 14
static val TOOL_TYPE_STYLUS: Int

Tool type constant: The tool is a stylus.

Value: 2

See Also

TOOL_TYPE_UNKNOWN

Added in API level 14
static val TOOL_TYPE_UNKNOWN: Int

Tool type constant: Unknown tool type. This constant is used when the tool type is not known or is not relevant, such as for a trackball or other non-pointing device.

Value: 0

See Also

Public methods

actionToString

Added in API level 19
static fun actionToString(action: Int): String!

Returns a string that represents the symbolic name of the specified unmasked action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant such as "35" if unknown.

Parameters
action Int: The unmasked action.
Return
String! The symbolic name of the specified action.

See Also

addBatch

Added in API level 1
fun addBatch(
    eventTime: Long,
    x: Float,
    y: Float,
    pressure: Float,
    size: Float,
    metaState: Int
): Unit

Add a new movement to the batch of movements in this event. The event's current location, position and size is updated to the new values. The current values in the event are added to a list of historical values. Only applies to ACTION_MOVE or ACTION_HOVER_MOVE events.

Parameters
eventTime Long: The time stamp (in ms) for this data.
x Float: The new X position.
y Float: The new Y position.
pressure Float: The new pressure.
size Float: The new size.
metaState Int: Meta key state.

addBatch

Added in API level 9
fun addBatch(
    eventTime: Long,
    pointerCoords: Array<MotionEvent.PointerCoords!>!,
    metaState: Int
): Unit

Add a new movement to the batch of movements in this event. The event's current location, position and size is updated to the new values. The current values in the event are added to a list of historical values. Only applies to ACTION_MOVE or ACTION_HOVER_MOVE events.

Parameters
eventTime Long: The time stamp (in ms) for this data.
pointerCoords Array<MotionEvent.PointerCoords!>!: The new pointer coordinates.
metaState Int: Meta key state.

axisFromString

Added in API level 12
static fun axisFromString(symbolicName: String!): Int

Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".

Parameters
symbolicName String!: The symbolic name of the axis.
Return
Int The axis or -1 if not found.

axisToString

Added in API level 12
static fun axisToString(axis: Int): String!

Returns a string that represents the symbolic name of the specified axis such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.

Parameters
axis Int: The axis.
Return
String! The symbolic name of the specified axis.

findPointerIndex

Added in API level 5
fun findPointerIndex(pointerId: Int): Int

Given a pointer identifier, find the index of its data in the event.

Parameters
pointerId Int: The identifier of the pointer to be found.
Return
Int Returns either the index of the pointer (for use with getX(int) et al.), or -1 if there is no data available for that pointer identifier.

getAction

Added in API level 1
fun getAction(): Int

Return the kind of action being performed. Consider using getActionMasked and getActionIndex to retrieve the separate masked action and pointer index.

Return
Int The action, such as ACTION_DOWN or the combination of ACTION_POINTER_DOWN with a shifted pointer index.

getActionButton

Added in API level 23
fun getActionButton(): Int

Gets which button has been modified during a press or release action. For actions other than ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE the returned value is undefined.

getActionIndex

Added in API level 8
fun getActionIndex(): Int

For ACTION_POINTER_DOWN or ACTION_POINTER_UP as returned by getActionMasked, this returns the associated pointer index. The index may be used with getPointerId(int), getX(int), getY(int), getPressure(int), and getSize(int) to get information about the pointer that has gone down or up.

Return
Int The index associated with the action.

getActionMasked

Added in API level 8
fun getActionMasked(): Int

Return the masked action being performed, without pointer index information. Use getActionIndex to return the index associated with pointer actions.

Return
Int The action, such as ACTION_DOWN or ACTION_POINTER_DOWN.

getAxisValue

Added in API level 12
fun getAxisValue(axis: Int): Float

getAxisValue(int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
axis Int: The axis identifier for the axis value to retrieve.

See Also

getAxisValue

Added in API level 12
fun getAxisValue(
    axis: Int,
    pointerIndex: Int
): Float

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

Parameters
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()-1.
Return
Float The value of the axis, or 0 if the axis is not available.

See Also

getButtonState

Added in API level 14
fun getButtonState(): Int

Gets the state of all buttons that are pressed such as a mouse or stylus button.

Return
Int The button state.

getClassification

Added in API level 29
fun getClassification(): Int

Returns the classification for the current gesture. The classification may change as more events become available for the same gesture.

Return
Int Value is android.view.MotionEvent#CLASSIFICATION_NONE, android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE, android.view.MotionEvent#CLASSIFICATION_DEEP_PRESS, android.view.MotionEvent#CLASSIFICATION_TWO_FINGER_SWIPE, android.view.MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE, or android.view.MotionEvent#CLASSIFICATION_PINCH

getDeviceId

Added in API level 1
fun getDeviceId(): Int

Gets the id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.

Return
Int The device id.

getDownTime

Added in API level 1
fun getDownTime(): Long

Returns the time (in ms) when the user originally pressed down to start a stream of position events.

getEdgeFlags

Added in API level 1
fun getEdgeFlags(): Int

Returns a bitfield indicating which edges, if any, were touched by this MotionEvent. For touch events, clients can use this to determine if the user's finger was touching the edge of the display. This property is only set for ACTION_DOWN events.

getEventTime

Added in API level 1
fun getEventTime(): Long

Retrieve the time this event occurred, in the android.os.SystemClock#uptimeMillis time base.

Return
Long Returns the time this event occurred, in the android.os.SystemClock#uptimeMillis time base.

getEventTimeNanos

Added in API level 34
fun getEventTimeNanos(): Long

Retrieve the time this event occurred, in the android.os.SystemClock#uptimeMillis time base but with nanosecond precision.

The value is in nanosecond precision but it may not have nanosecond accuracy.

Return
Long Returns the time this event occurred, in the android.os.SystemClock#uptimeMillis time base but with nanosecond precision.

getFlags

Added in API level 9
fun getFlags(): Int

Gets the motion event flags.

getHistoricalAxisValue

Added in API level 12
fun getHistoricalAxisValue(
    axis: Int,
    pos: Int
): Float

getHistoricalAxisValue(int,int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
axis Int: The axis identifier for the axis value to retrieve.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalAxisValue

Added in API level 12
fun getHistoricalAxisValue(
    axis: Int,
    pointerIndex: Int,
    pos: Int
): Float

Returns the historical value of the requested axis, as per getAxisValue(int,int), occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
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()-1.
pos Int: Which historical value to return; must be less than getHistorySize
Return
Float The value of the axis, or 0 if the axis is not available.

See Also

getHistoricalEventTime

Added in API level 1
fun getHistoricalEventTime(pos: Int): Long

Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base.

This only applies to ACTION_MOVE events.

Parameters
pos Int: Which historical value to return; must be less than getHistorySize
Return
Long Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base.

getHistoricalEventTimeNanos

Added in API level 34
fun getHistoricalEventTimeNanos(pos: Int): Long

Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base but with nanosecond (instead of millisecond) precision.

This only applies to ACTION_MOVE events.

The value is in nanosecond precision but it may not have nanosecond accuracy.

Parameters
pos Int: Which historical value to return; must be less than getHistorySize
Return
Long Returns the time that a historical movement occurred between this event and the previous event, in the android.os.SystemClock#uptimeMillis time base but with nanosecond (instead of millisecond) precision.

getHistoricalOrientation

Added in API level 9
fun getHistoricalOrientation(pos: Int): Float

getHistoricalOrientation(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalOrientation

Added in API level 9
fun getHistoricalOrientation(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical orientation coordinate, as per getOrientation(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalPointerCoords

Added in API level 9
fun getHistoricalPointerCoords(
    pointerIndex: Int,
    pos: Int,
    outPointerCoords: MotionEvent.PointerCoords!
): Unit

Populates a PointerCoords object with historical pointer coordinate data, as per getPointerCoords, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize
outPointerCoords MotionEvent.PointerCoords!: The pointer coordinate object to populate.

getHistoricalPressure

Added in API level 1
fun getHistoricalPressure(pos: Int): Float

getHistoricalPressure(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalPressure

Added in API level 5
fun getHistoricalPressure(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical pressure coordinate, as per getPressure(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalSize

Added in API level 1
fun getHistoricalSize(pos: Int): Float

getHistoricalSize(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalSize

Added in API level 5
fun getHistoricalSize(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical size coordinate, as per getSize(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalToolMajor

Added in API level 9
fun getHistoricalToolMajor(pos: Int): Float

getHistoricalToolMajor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalToolMajor

Added in API level 9
fun getHistoricalToolMajor(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical tool major axis coordinate, as per getToolMajor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalToolMinor

Added in API level 9
fun getHistoricalToolMinor(pos: Int): Float

getHistoricalToolMinor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalToolMinor

Added in API level 9
fun getHistoricalToolMinor(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical tool minor axis coordinate, as per getToolMinor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalTouchMajor

Added in API level 9
fun getHistoricalTouchMajor(pos: Int): Float

getHistoricalTouchMajor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalTouchMajor

Added in API level 9
fun getHistoricalTouchMajor(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical touch major axis coordinate, as per getTouchMajor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalTouchMinor

Added in API level 9
fun getHistoricalTouchMinor(pos: Int): Float

getHistoricalTouchMinor(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalTouchMinor

Added in API level 9
fun getHistoricalTouchMinor(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical touch minor axis coordinate, as per getTouchMinor(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalX

Added in API level 1
fun getHistoricalX(pos: Int): Float

getHistoricalX(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalX

Added in API level 5
fun getHistoricalX(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical X coordinate, as per getX(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalY

Added in API level 1
fun getHistoricalY(pos: Int): Float

getHistoricalY(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Parameters
pos Int: Which historical value to return; must be less than getHistorySize

getHistoricalY

Added in API level 5
fun getHistoricalY(
    pointerIndex: Int,
    pos: Int
): Float

Returns a historical Y coordinate, as per getY(int), that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Int: Which historical value to return; must be less than getHistorySize

getHistorySize

Added in API level 1
fun getHistorySize(): Int

Returns the number of historical points in this event. These are movements that have occurred between this event and the previous event. This only applies to ACTION_MOVE events -- all other actions will have a size of 0.

Return
Int Returns the number of historical points in the event.

getMetaState

Added in API level 1
fun getMetaState(): Int

Returns the state of any meta / modifier keys that were in effect when the event was generated. This is the same values as those returned by KeyEvent.getMetaState.

Return
Int an integer in which each bit set to 1 represents a pressed meta key

getOrientation

Added in API level 9
fun getOrientation(): Float

getOrientation(int) for the first pointer index (may be an arbitrary pointer identifier).

getOrientation

Added in API level 9
fun getOrientation(pointerIndex: Int): Float

Returns the value of AXIS_ORIENTATION for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

getPointerCoords

Added in API level 9
fun getPointerCoords(
    pointerIndex: Int,
    outPointerCoords: MotionEvent.PointerCoords!
): Unit

Populates a PointerCoords object with pointer coordinate data for the specified pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
outPointerCoords MotionEvent.PointerCoords!: The pointer coordinate object to populate.

getPointerCount

Added in API level 5
fun getPointerCount(): Int

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

getPointerId

Added in API level 5
fun getPointerId(pointerIndex: Int): Int

Return the pointer identifier associated with a particular pointer data index in this event. The identifier tells you the actual pointer number associated with the data, accounting for individual pointers going up and down since the start of the current gesture.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

getPointerProperties

Added in API level 14
fun getPointerProperties(
    pointerIndex: Int,
    outPointerProperties: MotionEvent.PointerProperties!
): Unit

Populates a PointerProperties object with pointer properties for the specified pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
outPointerProperties MotionEvent.PointerProperties!: The pointer properties object to populate.

getPressure

Added in API level 1
fun getPressure(): Float

getPressure(int) for the first pointer index (may be an arbitrary pointer identifier).

See Also

getPressure

Added in API level 5
fun getPressure(pointerIndex: Int): Float

Returns the value of AXIS_PRESSURE for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

See Also

getRawX

Added in API level 1
fun getRawX(): Float

Equivalent to getRawX(int) for pointer index 0 (regardless of the pointer identifier).

Return
Float The X coordinate of the first pointer index in the coordinate space of the device display.

See Also

getRawX

Added in API level 29
fun getRawX(pointerIndex: Int): Float

Returns the X coordinate of the pointer referenced by pointerIndex for this motion event. The coordinate is in the coordinate space of the device display, irrespective of system decorations and whether or not the system is in multi-window mode. If the app spans multiple screens in a multiple-screen environment, the coordinate space includes all of the spanned screens.

In multi-window mode, the coordinate space extends beyond the bounds of the app window to encompass the entire display area. For example, if the motion event occurs in the right-hand window of split-screen mode in landscape orientation, the left edge of the screen—not the left edge of the window—is the origin from which the X coordinate is calculated.

In multiple-screen scenarios, the coordinate space can span screens. For example, if the app is spanning both screens of a dual-screen device, and the motion event occurs on the right-hand screen, the X coordinate is calculated from the left edge of the left-hand screen to the point of the motion event on the right-hand screen. When the app is restricted to a single screen in a multiple-screen environment, the coordinate space includes only the screen on which the app is running.

Use getPointerId(int) to get the pointer identifier for the pointer referenced by pointerIndex.

Parameters
pointerIndex Int: Index of the pointer for which the X coordinate is returned. May be a value in the range of 0 (the first pointer that is down) to getPointerCount() - 1.
Return
Float The X coordinate of the pointer referenced by pointerIndex for this motion event. The unit is pixels. The value may contain a fractional portion for devices that are subpixel precise.

See Also

getRawY

Added in API level 1
fun getRawY(): Float

Equivalent to getRawY(int) for pointer index 0 (regardless of the pointer identifier).

Return
Float The Y coordinate of the first pointer index in the coordinate space of the device display.

See Also

getRawY

Added in API level 29
fun getRawY(pointerIndex: Int): Float

Returns the Y coordinate of the pointer referenced by pointerIndex for this motion event. The coordinate is in the coordinate space of the device display, irrespective of system decorations and whether or not the system is in multi-window mode. If the app spans multiple screens in a multiple-screen environment, the coordinate space includes all of the spanned screens.

In multi-window mode, the coordinate space extends beyond the bounds of the app window to encompass the entire device screen. For example, if the motion event occurs in the lower window of split-screen mode in portrait orientation, the top edge of the screen—not the top edge of the window—is the origin from which the Y coordinate is determined.

In multiple-screen scenarios, the coordinate space can span screens. For example, if the app is spanning both screens of a dual-screen device that's rotated 90 degrees, and the motion event occurs on the lower screen, the Y coordinate is calculated from the top edge of the upper screen to the point of the motion event on the lower screen. When the app is restricted to a single screen in a multiple-screen environment, the coordinate space includes only the screen on which the app is running.

Use getPointerId(int) to get the pointer identifier for the pointer referenced by pointerIndex.

Parameters
pointerIndex Int: Index of the pointer for which the Y coordinate is returned. May be a value in the range of 0 (the first pointer that is down) to getPointerCount() - 1.
Return
Float The Y coordinate of the pointer referenced by pointerIndex for this motion event. The unit is pixels. The value may contain a fractional portion for devices that are subpixel precise.

See Also

getSize

Added in API level 1
fun getSize(): Float

getSize(int) for the first pointer index (may be an arbitrary pointer identifier).

See Also

getSize

Added in API level 5
fun getSize(pointerIndex: Int): Float

Returns the value of AXIS_SIZE for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

See Also

getSource

Added in API level 9
fun getSource(): Int

Gets the source of the event.

Return
Int The event source or InputDevice#SOURCE_UNKNOWN if unknown.

getToolMajor

Added in API level 9
fun getToolMajor(): Float

getToolMajor(int) for the first pointer index (may be an arbitrary pointer identifier).

See Also

getToolMajor

Added in API level 9
fun getToolMajor(pointerIndex: Int): Float

Returns the value of AXIS_TOOL_MAJOR for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

See Also

getToolMinor

Added in API level 9
fun getToolMinor(): Float

getToolMinor(int) for the first pointer index (may be an arbitrary pointer identifier).

See Also

getToolMinor

Added in API level 9
fun getToolMinor(pointerIndex: Int): Float

Returns the value of AXIS_TOOL_MINOR for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

See Also

getToolType

Added in API level 14
fun getToolType(pointerIndex: Int): Int

Gets the tool type of a pointer for the given pointer index. The tool type indicates the type of tool used to make contact such as a finger or stylus, if known.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
Return
Int The tool type of the pointer. Value is android.view.MotionEvent#TOOL_TYPE_UNKNOWN, android.view.MotionEvent#TOOL_TYPE_FINGER, android.view.MotionEvent#TOOL_TYPE_STYLUS, android.view.MotionEvent#TOOL_TYPE_MOUSE, android.view.MotionEvent#TOOL_TYPE_ERASER, or android.view.MotionEvent.TOOL_TYPE_PALM

getTouchMajor

Added in API level 9
fun getTouchMajor(): Float

getTouchMajor(int) for the first pointer index (may be an arbitrary pointer identifier).

getTouchMajor

Added in API level 9
fun getTouchMajor(pointerIndex: Int): Float

Returns the value of AXIS_TOUCH_MAJOR for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

getTouchMinor

Added in API level 9
fun getTouchMinor(): Float

getTouchMinor(int) for the first pointer index (may be an arbitrary pointer identifier).

getTouchMinor

Added in API level 9
fun getTouchMinor(pointerIndex: Int): Float

Returns the value of AXIS_TOUCH_MINOR for the given pointer index.

Parameters
pointerIndex Int: Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

getX

Added in API level 1
fun getX(): Float

Equivalent to getX(int) for pointer index 0 (regardless of the pointer identifier).

Return
Float The X coordinate of the first pointer index in the coordinate space of the view that received this motion event.

See Also

getX

Added in API level 5
fun getX(pointerIndex: Int): Float

Returns the X coordinate of the pointer referenced by pointerIndex for this motion event. The coordinate is in the coordinate space of the view that received this motion event.

Use getPointerId(int) to get the pointer identifier for the pointer referenced by pointerIndex.

Parameters
pointerIndex Int: Index of the pointer for which the X coordinate is returned. May be a value in the range of 0 (the first pointer that is down) to getPointerCount() - 1.
Return
Float The X coordinate of the pointer referenced by pointerIndex for this motion event. The unit is pixels. The value may contain a fractional portion for devices that are subpixel precise.

See Also

getXPrecision

Added in API level 1
fun getXPrecision(): Float

Return the precision of the X coordinates being reported. You can multiply this number with #getX to find the actual hardware value of the X coordinate.

Return
Float Returns the precision of X coordinates being reported.

See Also

getY

Added in API level 1
fun getY(): Float

Equivalent to getY(int) for pointer index 0 (regardless of the pointer identifier).

Return
Float The Y coordinate of the first pointer index in the coordinate space of the view that received this motion event.

See Also

getY

Added in API level 5
fun getY(pointerIndex: Int): Float

Returns the Y coordinate of the pointer referenced by pointerIndex for this motion event. The coordinate is in the coordinate space of the view that received this motion event.

Use getPointerId(int) to get the pointer identifier for the pointer referenced by pointerIndex.

Parameters
pointerIndex Int: Index of the pointer for which the Y coordinate is returned. May be a value in the range of 0 (the first pointer that is down) to getPointerCount() - 1.
Return
Float The Y coordinate of the pointer referenced by pointerIndex for this motion event. The unit is pixels. The value may contain a fractional portion for devices that are subpixel precise.

See Also

getYPrecision

Added in API level 1
fun getYPrecision(): Float

Return the precision of the Y coordinates being reported. You can multiply this number with #getY to find the actual hardware value of the Y coordinate.

Return
Float Returns the precision of Y coordinates being reported.

See Also

isButtonPressed

Added in API level 21
fun isButtonPressed(button: Int): Boolean

Checks if a mouse or stylus button (or combination of buttons) is pressed.

Parameters
button Int: Button (or combination of buttons).
Return
Boolean True if specified buttons are pressed.

obtain

Added in API level 34
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    pointerCount: Int,
    pointerProperties: Array<MotionEvent.PointerProperties!>,
    pointerCoords: Array<MotionEvent.PointerCoords!>,
    metaState: Int,
    buttonState: Int,
    xPrecision: Float,
    yPrecision: Float,
    deviceId: Int,
    edgeFlags: Int,
    source: Int,
    displayId: Int,
    flags: Int,
    classification: Int
): MotionEvent?

Create a new MotionEvent, filling in all of the basic values that define the motion.

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
pointerCount Int: The number of pointers that will be in this event.
pointerProperties Array<MotionEvent.PointerProperties!>: An array of pointerCount values providing a PointerProperties property object for each pointer, which must include the pointer identifier. This value cannot be null.
pointerCoords Array<MotionEvent.PointerCoords!>: An array of pointerCount values providing a PointerCoords coordinate object for each pointer. This value cannot be null.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.
buttonState Int: The state of buttons that are pressed.
xPrecision Float: The precision of the X coordinate being reported.
yPrecision Float: The precision of the Y coordinate being reported.
deviceId Int: The ID for the device that this event came from. An ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
edgeFlags Int: A bitfield indicating which edges, if any, were touched by this MotionEvent.
source Int: The source of this event.
displayId Int: The display ID associated with this event.
flags Int: The motion event flags.
classification Int: The classification to give this event. Value is android.view.MotionEvent#CLASSIFICATION_NONE, android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE, android.view.MotionEvent#CLASSIFICATION_DEEP_PRESS, android.view.MotionEvent#CLASSIFICATION_TWO_FINGER_SWIPE, android.view.MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE, or android.view.MotionEvent#CLASSIFICATION_PINCH
Return
MotionEvent? This value may be null.

obtain

Added in API level 14
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    pointerCount: Int,
    pointerProperties: Array<MotionEvent.PointerProperties!>!,
    pointerCoords: Array<MotionEvent.PointerCoords!>!,
    metaState: Int,
    buttonState: Int,
    xPrecision: Float,
    yPrecision: Float,
    deviceId: Int,
    edgeFlags: Int,
    source: Int,
    flags: Int
): MotionEvent!

Create a new MotionEvent, filling in all of the basic values that define the motion.

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
pointerCount Int: The number of pointers that will be in this event.
pointerProperties Array<MotionEvent.PointerProperties!>!: An array of pointerCount values providing a PointerProperties property object for each pointer, which must include the pointer identifier.
pointerCoords Array<MotionEvent.PointerCoords!>!: An array of pointerCount values providing a PointerCoords coordinate object for each pointer.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.
buttonState Int: The state of buttons that are pressed.
xPrecision Float: The precision of the X coordinate being reported.
yPrecision Float: The precision of the Y coordinate being reported.
deviceId Int: The ID for the device that this event came from. An ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
edgeFlags Int: A bitfield indicating which edges, if any, were touched by this MotionEvent.
source Int: The source of this event.
flags Int: The motion event flags.

obtain

Added in API level 9
Deprecated in API level 15
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    pointerCount: Int,
    pointerIds: IntArray!,
    pointerCoords: Array<MotionEvent.PointerCoords!>!,
    metaState: Int,
    xPrecision: Float,
    yPrecision: Float,
    deviceId: Int,
    edgeFlags: Int,
    source: Int,
    flags: Int
): MotionEvent!

Deprecated: Use obtain(long,long,int,int,android.view.MotionEvent.PointerProperties[],android.view.MotionEvent.PointerCoords[],int,int,float,float,int,int,int,int) instead.

Create a new MotionEvent, filling in all of the basic values that define the motion.

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
pointerCount Int: The number of pointers that will be in this event.
pointerIds IntArray!: An array of pointerCount values providing an identifier for each pointer.
pointerCoords Array<MotionEvent.PointerCoords!>!: An array of pointerCount values providing a PointerCoords coordinate object for each pointer.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision Float: The precision of the X coordinate being reported.
yPrecision Float: The precision of the Y coordinate being reported.
deviceId Int: The ID for the device that this event came from. An ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
edgeFlags Int: A bitfield indicating which edges, if any, were touched by this MotionEvent.
source Int: The source of this event.
flags Int: The motion event flags.

obtain

Added in API level 1
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    x: Float,
    y: Float,
    pressure: Float,
    size: Float,
    metaState: Int,
    xPrecision: Float,
    yPrecision: Float,
    deviceId: Int,
    edgeFlags: Int
): MotionEvent!

Create a new MotionEvent, filling in all of the basic values that define the motion.

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
x Float: The X coordinate of this event.
y Float: The Y coordinate of this event.
pressure Float: The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
size Float: A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision Float: The precision of the X coordinate being reported.
yPrecision Float: The precision of the Y coordinate being reported.
deviceId Int: The ID for the device that this event came from. An ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
edgeFlags Int: A bitfield indicating which edges, if any, were touched by this MotionEvent.

obtain

Added in API level 5
Deprecated in API level 15
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    pointerCount: Int,
    x: Float,
    y: Float,
    pressure: Float,
    size: Float,
    metaState: Int,
    xPrecision: Float,
    yPrecision: Float,
    deviceId: Int,
    edgeFlags: Int
): MotionEvent!

Deprecated: Use obtain(long,long,int,float,float,float,float,int,float,float,int,int) instead.

Create a new MotionEvent, filling in all of the basic values that define the motion.

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
pointerCount Int: The number of pointers that are active in this event.
x Float: The X coordinate of this event.
y Float: The Y coordinate of this event.
pressure Float: The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device.
size Float: A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision Float: The precision of the X coordinate being reported.
yPrecision Float: The precision of the Y coordinate being reported.
deviceId Int: The ID for the device that this event came from. An ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values.
edgeFlags Int: A bitfield indicating which edges, if any, were touched by this MotionEvent.

obtain

Added in API level 1
static fun obtain(
    downTime: Long,
    eventTime: Long,
    action: Int,
    x: Float,
    y: Float,
    metaState: Int
): MotionEvent!

Create a new MotionEvent, filling in a subset of the basic motion values. Those not specified here are: device id (always 0), pressure and size (always 1), x and y precision (always 1), and edgeFlags (always 0).

Parameters
downTime Long: The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from SystemClock#uptimeMillis().
eventTime Long: The time (in ms) when this specific event was generated. This must be obtained from SystemClock#uptimeMillis().
action Int: The kind of action being performed, such as ACTION_DOWN.
x Float: The X coordinate of this event.
y Float: The Y coordinate of this event.
metaState Int: The state of any meta / modifier keys that were in effect when the event was generated.

obtain

Added in API level 1
static fun obtain(other: MotionEvent!): MotionEvent!

Create a new MotionEvent, copying from an existing one.

obtainNoHistory

Added in API level 5
static fun obtainNoHistory(other: MotionEvent!): MotionEvent!

Create a new MotionEvent, copying from an existing one, but not including any historical point information.

offsetLocation

Added in API level 1
fun offsetLocation(
    deltaX: Float,
    deltaY: Float
): Unit

Adjust this event's location.

Parameters
deltaX Float: Amount to add to the current X coordinate of the event.
deltaY Float: Amount to add to the current Y coordinate of the event.

recycle

Added in API level 1
fun recycle(): Unit

Recycle the MotionEvent, to be re-used by a later caller. After calling this function you must not ever touch the event again.

setAction

Added in API level 1
fun setAction(action: Int): Unit

Sets this event's action.

setEdgeFlags

Added in API level 1
fun setEdgeFlags(flags: Int): Unit

Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.

See Also

setLocation

Added in API level 1
fun setLocation(
    x: Float,
    y: Float
): Unit

Set this event's location. Applies offsetLocation with a delta from the current location to the given new location.

Parameters
x Float: New absolute X location.
y Float: New absolute Y location.

setSource

Added in API level 12
fun setSource(source: Int): Unit

toString

Added in API level 1
fun toString(): String
Return
String a string representation of the object.

transform

Added in API level 11
fun transform(matrix: Matrix!): Unit

Applies a transformation matrix to all of the points in the event.

Parameters
matrix Matrix!: The transformation matrix to apply.

writeToParcel

Added in API level 1
fun writeToParcel(
    out: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Protected methods

finalize

Added in API level 1
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method

Properties

CREATOR

Added in API level 1
static val CREATOR: Parcelable.Creator<MotionEvent!>