加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20111010210545/http://developer.android.com:80/reference/android/view/MotionEvent.html
public final class

MotionEvent

extends InputEvent
implements Parcelable
java.lang.Object
   ↳ android.view.InputEvent
     ↳ android.view.MotionEvent

Class Overview

Object used to report movement (mouse, pen, finger, trackball) events. This class may hold either absolute or relative movements, depending on what it is being used for.

On pointing devices with source class 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 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 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 getMotionRange(int). Some common joystick axes are AXIS_X, AXIS_Y, AXIS_HAT_X, AXIS_HAT_Y, AXIS_Z and AXIS_RZ.

Motion events always report movements for all pointers at once. The number of pointers only ever changes by one as individual pointers go up and down, except when the gesture is canceled.

The order in which individual pointers appear within a motion event can change from one event to the next. Use the getPointerId(int) method to obtain a pointer id to track pointers across 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.

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.


 void printSamples(MotionEvent ev) {
     final int historySize = ev.getHistorySize();
     final int pointerCount = ev.getPointerCount();
     for (int h = 0; h < historySize; h++) {
         System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
         for (int p = 0; p < 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 < pointerCount; p++) {
         System.out.printf("  pointer %d: (%f,%f)",
             ev.getPointerId(p), ev.getX(p), ev.getY(p));
     }
 }
 

In general, the framework cannot guarantee that the motion events it delivers to a view always constitute a complete motion sequences since some events may be dropped or modified by containing views before they are delivered. The view implementation should 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.

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

Summary

Nested Classes
class MotionEvent.PointerCoords Transfer object for pointer coordinates. 
Constants
int ACTION_CANCEL Constant for getAction(): The current gesture has been aborted.
int ACTION_DOWN Constant for getAction(): A pressed gesture has started, the motion contains the initial starting location.
int ACTION_HOVER_MOVE Constant for getAction(): A change happened but the pointer is not down (unlike ACTION_MOVE).
int ACTION_MASK Bit mask of the parts of the action code that are the action itself.
int ACTION_MOVE Constant for getAction(): A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
int ACTION_OUTSIDE Constant for getAction(): A movement has happened outside of the normal bounds of the UI element.
int ACTION_POINTER_1_DOWN This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.
int ACTION_POINTER_1_UP This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.
int ACTION_POINTER_2_DOWN This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.
int ACTION_POINTER_2_UP This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.
int ACTION_POINTER_3_DOWN This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.
int ACTION_POINTER_3_UP This constant is deprecated. Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.
int ACTION_POINTER_DOWN A non-primary pointer has gone down.
int ACTION_POINTER_ID_MASK This constant is deprecated. Renamed to ACTION_POINTER_INDEX_MASK to match the actual data contained in these bits.
int ACTION_POINTER_ID_SHIFT This constant is deprecated. Renamed to ACTION_POINTER_INDEX_SHIFT to match the actual data contained in these bits.
int ACTION_POINTER_INDEX_MASK Bits in the action code that represent a pointer index, used with ACTION_POINTER_DOWN and ACTION_POINTER_UP.
int ACTION_POINTER_INDEX_SHIFT Bit shift for the action bits holding the pointer index as defined by ACTION_POINTER_INDEX_MASK.
int ACTION_POINTER_UP A non-primary pointer has gone up.
int ACTION_SCROLL Constant for getAction(): The motion event contains relative vertical and/or horizontal scroll offsets.
int ACTION_UP Constant for getAction(): 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.
int AXIS_BRAKE Constant used to identify the Brake axis of a motion event.
int AXIS_GAS Constant used to identify the Gas axis of a motion event.
int AXIS_GENERIC_1 Constant used to identify the Generic 1 axis of a motion event.
int AXIS_GENERIC_10 Constant used to identify the Generic 10 axis of a motion event.
int AXIS_GENERIC_11 Constant used to identify the Generic 11 axis of a motion event.
int AXIS_GENERIC_12 Constant used to identify the Generic 12 axis of a motion event.
int AXIS_GENERIC_13 Constant used to identify the Generic 13 axis of a motion event.
int AXIS_GENERIC_14 Constant used to identify the Generic 14 axis of a motion event.
int AXIS_GENERIC_15 Constant used to identify the Generic 15 axis of a motion event.
int AXIS_GENERIC_16 Constant used to identify the Generic 16 axis of a motion event.
int AXIS_GENERIC_2 Constant used to identify the Generic 2 axis of a motion event.
int AXIS_GENERIC_3 Constant used to identify the Generic 3 axis of a motion event.
int AXIS_GENERIC_4 Constant used to identify the Generic 4 axis of a motion event.
int AXIS_GENERIC_5 Constant used to identify the Generic 5 axis of a motion event.
int AXIS_GENERIC_6 Constant used to identify the Generic 6 axis of a motion event.
int AXIS_GENERIC_7 Constant used to identify the Generic 7 axis of a motion event.
int AXIS_GENERIC_8 Constant used to identify the Generic 8 axis of a motion event.
int AXIS_GENERIC_9 Constant used to identify the Generic 9 axis of a motion event.
int AXIS_HAT_X Constant used to identify the Hat X axis of a motion event.
int AXIS_HAT_Y Constant used to identify the Hat Y axis of a motion event.
int AXIS_HSCROLL Constant used to identify the Horizontal Scroll axis of a motion event.
int AXIS_LTRIGGER Constant used to identify the Left Trigger axis of a motion event.
int AXIS_ORIENTATION Constant used to identify the Orientation axis of a motion event.
int AXIS_PRESSURE Constant used to identify the Pressure axis of a motion event.
int AXIS_RTRIGGER Constant used to identify the Right Trigger axis of a motion event.
int AXIS_RUDDER Constant used to identify the Rudder axis of a motion event.
int AXIS_RX Constant used to identify the X Rotation axis of a motion event.
int AXIS_RY Constant used to identify the Y Rotation axis of a motion event.
int AXIS_RZ Constant used to identify the Z Rotation axis of a motion event.
int AXIS_SIZE Constant used to identify the Size axis of a motion event.
int AXIS_THROTTLE Constant used to identify the Throttle axis of a motion event.
int AXIS_TOOL_MAJOR Constant used to identify the ToolMajor axis of a motion event.
int AXIS_TOOL_MINOR Constant used to identify the ToolMinor axis of a motion event.
int AXIS_TOUCH_MAJOR Constant used to identify the TouchMajor axis of a motion event.
int AXIS_TOUCH_MINOR Constant used to identify the TouchMinor axis of a motion event.
int AXIS_VSCROLL Constant used to identify the Vertical Scroll axis of a motion event.
int AXIS_WHEEL Constant used to identify the Wheel axis of a motion event.
int AXIS_X Constant used to identify the X axis of a motion event.
int AXIS_Y Constant used to identify the Y axis of a motion event.
int AXIS_Z Constant used to identify the Z axis of a motion event.
int EDGE_BOTTOM Flag indicating the motion event intersected the bottom edge of the screen.
int EDGE_LEFT Flag indicating the motion event intersected the left edge of the screen.
int EDGE_RIGHT Flag indicating the motion event intersected the right edge of the screen.
int EDGE_TOP Flag indicating the motion event intersected the top edge of the screen.
int FLAG_WINDOW_IS_OBSCURED This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<MotionEvent> CREATOR
[Expand]
Inherited Fields
From class android.view.InputEvent
Public Methods
final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState)
Add a new movement to the batch of movements in this event.
final void addBatch(long eventTime, float x, float y, float pressure, float size, int metaState)
Add a new movement to the batch of movements in this event.
static int axisFromString(String symbolicName)
Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".
static String axisToString(int axis)
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.
final int findPointerIndex(int pointerId)
Given a pointer identifier, find the index of its data in the event.
final int getAction()
Return the kind of action being performed.
final int getActionIndex()
For ACTION_POINTER_DOWN or ACTION_POINTER_UP as returned by getActionMasked(), this returns the associated pointer index.
final int getActionMasked()
Return the masked action being performed, without pointer index information.
final float getAxisValue(int axis)
getAxisValue(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getAxisValue(int axis, int pointerIndex)
Returns the value of the requested axis for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final int getDeviceId()
Gets the id for the device that this event came from.
final long getDownTime()
Returns the time (in ms) when the user originally pressed down to start a stream of position events.
final int getEdgeFlags()
Returns a bitfield indicating which edges, if any, were touched by this MotionEvent.
final long getEventTime()
Returns the time (in ms) when this specific event was generated.
final int getFlags()
Gets the motion event flags.
final float getHistoricalAxisValue(int axis, int pointerIndex, int pos)
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.
final float getHistoricalAxisValue(int axis, int pos)
getHistoricalAxisValue(int, int, int) for the first pointer index (may be an arbitrary pointer identifier).
final long getHistoricalEventTime(int pos)
Returns the time that a historical movement occurred between this event and the previous event.
final float getHistoricalOrientation(int pointerIndex, int pos)
Returns a historical orientation coordinate, as per getOrientation(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalOrientation(int pos)
getHistoricalOrientation(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final void getHistoricalPointerCoords(int pointerIndex, int pos, MotionEvent.PointerCoords outPointerCoords)
Populates a MotionEvent.PointerCoords object with historical pointer coordinate data, as per getPointerCoords(int, MotionEvent.PointerCoords), that occurred between this event and the previous event for the given pointer.
final float getHistoricalPressure(int pos)
getHistoricalPressure(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalPressure(int pointerIndex, int pos)
Returns a historical pressure coordinate, as per getPressure(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalSize(int pos)
getHistoricalSize(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalSize(int pointerIndex, int pos)
Returns a historical size coordinate, as per getSize(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalToolMajor(int pointerIndex, int pos)
Returns a historical tool major axis coordinate, as per getToolMajor(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalToolMajor(int pos)
getHistoricalToolMajor(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalToolMinor(int pointerIndex, int pos)
Returns a historical tool minor axis coordinate, as per getToolMinor(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalToolMinor(int pos)
getHistoricalToolMinor(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalTouchMajor(int pointerIndex, int pos)
Returns a historical touch major axis coordinate, as per getTouchMajor(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalTouchMajor(int pos)
getHistoricalTouchMajor(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalTouchMinor(int pointerIndex, int pos)
Returns a historical touch minor axis coordinate, as per getTouchMinor(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalTouchMinor(int pos)
getHistoricalTouchMinor(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalX(int pos)
getHistoricalX(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalX(int pointerIndex, int pos)
Returns a historical X coordinate, as per getX(int), that occurred between this event and the previous event for the given pointer.
final float getHistoricalY(int pos)
getHistoricalY(int, int) for the first pointer index (may be an arbitrary pointer identifier).
final float getHistoricalY(int pointerIndex, int pos)
Returns a historical Y coordinate, as per getY(int), that occurred between this event and the previous event for the given pointer.
final int getHistorySize()
Returns the number of historical points in this event.
final int getMetaState()
Returns the state of any meta / modifier keys that were in effect when the event was generated.
final float getOrientation(int pointerIndex)
Returns the orientation of the touch area and tool area in radians clockwise from vertical for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getOrientation()
getOrientation(int) for the first pointer index (may be an arbitrary pointer identifier).
final void getPointerCoords(int pointerIndex, MotionEvent.PointerCoords outPointerCoords)
Populates a MotionEvent.PointerCoords object with pointer coordinate data for the specified pointer index.
final int getPointerCount()
The number of pointers of data contained in this event.
final int getPointerId(int pointerIndex)
Return the pointer identifier associated with a particular pointer data index is this event.
final float getPressure()
getPressure(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getPressure(int pointerIndex)
Returns the current pressure of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getRawX()
Returns the original raw X coordinate of this event.
final float getRawY()
Returns the original raw Y coordinate of this event.
final float getSize(int pointerIndex)
Returns a scaled value of the approximate size for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getSize()
getSize(int) for the first pointer index (may be an arbitrary pointer identifier).
final int getSource()
Gets the source of the event.
final float getToolMajor(int pointerIndex)
Returns the length of the major axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getToolMajor()
getToolMajor(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getToolMinor()
getToolMinor(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getToolMinor(int pointerIndex)
Returns the length of the minor axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getTouchMajor()
getTouchMajor(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getTouchMajor(int pointerIndex)
Returns the length of the major axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getTouchMinor()
getTouchMinor(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getTouchMinor(int pointerIndex)
Returns the length of the minor axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getX(int pointerIndex)
Returns the X coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getX()
getX(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getXPrecision()
Return the precision of the X coordinates being reported.
final float getY(int pointerIndex)
Returns the Y coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).
final float getY()
getY(int) for the first pointer index (may be an arbitrary pointer identifier).
final float getYPrecision()
Return the precision of the Y coordinates being reported.
static MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)
Create a new MotionEvent, filling in all of the basic values that define the motion.
static MotionEvent obtain(long downTime, long eventTime, int action, int pointers, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)
static MotionEvent obtain(long downTime, long eventTime, int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)
Create a new MotionEvent, filling in all of the basic values that define the motion.
static MotionEvent obtain(MotionEvent other)
Create a new MotionEvent, copying from an existing one.
static MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, int metaState)
Create a new MotionEvent, filling in a subset of the basic motion values.
static MotionEvent obtainNoHistory(MotionEvent other)
Create a new MotionEvent, copying from an existing one, but not including any historical point information.
final void offsetLocation(float deltaX, float deltaY)
Adjust this event's location.
final void recycle()
Recycle the MotionEvent, to be re-used by a later caller.
final void setAction(int action)
Sets this event's action.
final void setEdgeFlags(int flags)
Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.
final void setLocation(float x, float y)
Set this event's location.
final void setSource(int source)
Modifies the source of the event.
String toString()
Returns a string containing a concise, human-readable description of this object.
final void transform(Matrix matrix)
Applies a transformation matrix to all of the points in the event.
void writeToParcel(Parcel out, int flags)
Flatten this object in to a Parcel.
Protected Methods
void finalize()
Called before the object's memory is reclaimed by the VM.
[Expand]
Inherited Methods
From class android.view.InputEvent
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int ACTION_CANCEL

Since: API Level 1

Constant for getAction(): 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.

Constant Value: 3 (0x00000003)

public static final int ACTION_DOWN

Since: API Level 1

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

Constant Value: 0 (0x00000000)

public static final int ACTION_HOVER_MOVE

Since: API Level 12

Constant for getAction(): 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 not a touch event so it is delivered to onGenericMotionEvent(MotionEvent) rather than onTouchEvent(MotionEvent).

Constant Value: 7 (0x00000007)

public static final int ACTION_MASK

Since: API Level 5

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

Constant Value: 255 (0x000000ff)

public static final int ACTION_MOVE

Since: API Level 1

Constant for getAction(): 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.

Constant Value: 2 (0x00000002)

public static final int ACTION_OUTSIDE

Since: API Level 3

Constant for getAction(): 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.

Constant Value: 4 (0x00000004)

public static final int ACTION_POINTER_1_DOWN

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Constant Value: 5 (0x00000005)

public static final int ACTION_POINTER_1_UP

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Constant Value: 6 (0x00000006)

public static final int ACTION_POINTER_2_DOWN

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Constant Value: 261 (0x00000105)

public static final int ACTION_POINTER_2_UP

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Constant Value: 262 (0x00000106)

public static final int ACTION_POINTER_3_DOWN

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_DOWN.

Constant Value: 517 (0x00000205)

public static final int ACTION_POINTER_3_UP

Since: API Level 5

This constant is deprecated.
Use ACTION_POINTER_INDEX_MASK to retrieve the data index associated with ACTION_POINTER_UP.

Constant Value: 518 (0x00000206)

public static final int ACTION_POINTER_DOWN

Since: API Level 5

A non-primary pointer has gone down. The bits in ACTION_POINTER_ID_MASK indicate which pointer changed.

Constant Value: 5 (0x00000005)

public static final int ACTION_POINTER_ID_MASK

Since: API Level 5

This constant is deprecated.
Renamed to ACTION_POINTER_INDEX_MASK to match the actual data contained in these bits.

Constant Value: 65280 (0x0000ff00)

public static final int ACTION_POINTER_ID_SHIFT

Since: API Level 5

This constant is deprecated.
Renamed to ACTION_POINTER_INDEX_SHIFT to match the actual data contained in these bits.

Constant Value: 8 (0x00000008)

public static final int ACTION_POINTER_INDEX_MASK

Since: API Level 8

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.

Constant Value: 65280 (0x0000ff00)

public static final int ACTION_POINTER_INDEX_SHIFT

Since: API Level 8

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

Constant Value: 8 (0x00000008)

public static final int ACTION_POINTER_UP

Since: API Level 5

A non-primary pointer has gone up. The bits in ACTION_POINTER_ID_MASK indicate which pointer changed.

Constant Value: 6 (0x00000006)

public static final int ACTION_SCROLL

Since: API Level 12

Constant for getAction(): 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 winder under the pointer, which may not be the window currently touched.

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

Constant Value: 8 (0x00000008)

public static final int ACTION_UP

Since: API Level 1

Constant for getAction(): 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.

Constant Value: 1 (0x00000001)

public static final int AXIS_BRAKE

Since: API Level 12

Constant used to identify the 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).
Constant Value: 23 (0x00000017)

public static final int AXIS_GAS

Since: API Level 12

Constant used to identify the 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).
Constant Value: 22 (0x00000016)

public static final int AXIS_GENERIC_1

Since: API Level 12

Constant used to identify the Generic 1 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 32 (0x00000020)

public static final int AXIS_GENERIC_10

Since: API Level 12

Constant used to identify the Generic 10 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 41 (0x00000029)

public static final int AXIS_GENERIC_11

Since: API Level 12

Constant used to identify the Generic 11 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 42 (0x0000002a)

public static final int AXIS_GENERIC_12

Since: API Level 12

Constant used to identify the Generic 12 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 43 (0x0000002b)

public static final int AXIS_GENERIC_13

Since: API Level 12

Constant used to identify the Generic 13 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 44 (0x0000002c)

public static final int AXIS_GENERIC_14

Since: API Level 12

Constant used to identify the Generic 14 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 45 (0x0000002d)

public static final int AXIS_GENERIC_15

Since: API Level 12

Constant used to identify the Generic 15 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 46 (0x0000002e)

public static final int AXIS_GENERIC_16

Since: API Level 12

Constant used to identify the Generic 16 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 47 (0x0000002f)

public static final int AXIS_GENERIC_2

Since: API Level 12

Constant used to identify the Generic 2 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 33 (0x00000021)

public static final int AXIS_GENERIC_3

Since: API Level 12

Constant used to identify the Generic 3 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 34 (0x00000022)

public static final int AXIS_GENERIC_4

Since: API Level 12

Constant used to identify the Generic 4 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 35 (0x00000023)

public static final int AXIS_GENERIC_5

Since: API Level 12

Constant used to identify the Generic 5 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 36 (0x00000024)

public static final int AXIS_GENERIC_6

Since: API Level 12

Constant used to identify the Generic 6 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 37 (0x00000025)

public static final int AXIS_GENERIC_7

Since: API Level 12

Constant used to identify the Generic 7 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 38 (0x00000026)

public static final int AXIS_GENERIC_8

Since: API Level 12

Constant used to identify the Generic 8 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 39 (0x00000027)

public static final int AXIS_GENERIC_9

Since: API Level 12

Constant used to identify the Generic 9 axis of a motion event. The interpretation of a generic axis is device-specific.

Constant Value: 40 (0x00000028)

public static final int AXIS_HAT_X

Since: API Level 12

Constant used to identify the 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).
Constant Value: 15 (0x0000000f)

public static final int AXIS_HAT_Y

Since: API Level 12

Constant used to identify the 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).
Constant Value: 16 (0x00000010)

public static final int AXIS_HSCROLL

Since: API Level 12

Constant used to identify the 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.

Constant Value: 10 (0x0000000a)

public static final int AXIS_LTRIGGER

Since: API Level 12

Constant used to identify the 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).
Constant Value: 17 (0x00000011)

public static final int AXIS_ORIENTATION

Since: API Level 12

Constant used to identify the 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).
Constant Value: 8 (0x00000008)

public static final int AXIS_PRESSURE

Since: API Level 12

Constant used to identify the 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.
Constant Value: 2 (0x00000002)

public static final int AXIS_RTRIGGER

Since: API Level 12

Constant used to identify the 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).
Constant Value: 18 (0x00000012)

public static final int AXIS_RUDDER

Since: API Level 12

Constant used to identify the 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).
Constant Value: 20 (0x00000014)

public static final int AXIS_RX

Since: API Level 12

Constant used to identify the 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).
Constant Value: 12 (0x0000000c)

public static final int AXIS_RY

Since: API Level 12

Constant used to identify the 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).
Constant Value: 13 (0x0000000d)

public static final int AXIS_RZ

Since: API Level 12

Constant used to identify the 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.
Constant Value: 14 (0x0000000e)

public static final int AXIS_SIZE

Since: API Level 12

Constant used to identify the 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. This value is of limited use. To obtain calibrated size information, use AXIS_TOUCH_MAJOR or AXIS_TOOL_MAJOR.
Constant Value: 3 (0x00000003)

public static final int AXIS_THROTTLE

Since: API Level 12

Constant used to identify the 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).
Constant Value: 19 (0x00000013)

public static final int AXIS_TOOL_MAJOR

Since: API Level 12

Constant used to identify the 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 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.

Constant Value: 6 (0x00000006)

public static final int AXIS_TOOL_MINOR

Since: API Level 12

Constant used to identify the 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 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.

Constant Value: 7 (0x00000007)

public static final int AXIS_TOUCH_MAJOR

Since: API Level 12

Constant used to identify the 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 getMotionRange(int) to query the effective range of values.
Constant Value: 4 (0x00000004)

public static final int AXIS_TOUCH_MINOR

Since: API Level 12

Constant used to identify the 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 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.

Constant Value: 5 (0x00000005)

public static final int AXIS_VSCROLL

Since: API Level 12

Constant used to identify the 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.

Constant Value: 9 (0x00000009)

public static final int AXIS_WHEEL

Since: API Level 12

Constant used to identify the 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).
Constant Value: 21 (0x00000015)

public static final int AXIS_X

Since: API Level 12

Constant used to identify the 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 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).
Constant Value: 0 (0x00000000)

public static final int AXIS_Y

Since: API Level 12

Constant used to identify the 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 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).
Constant Value: 1 (0x00000001)

public static final int AXIS_Z

Since: API Level 12

Constant used to identify the 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.
Constant Value: 11 (0x0000000b)

public static final int EDGE_BOTTOM

Since: API Level 1

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

Constant Value: 2 (0x00000002)

public static final int EDGE_LEFT

Since: API Level 1

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

Constant Value: 4 (0x00000004)

public static final int EDGE_RIGHT

Since: API Level 1

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

Constant Value: 8 (0x00000008)

public static final int EDGE_TOP

Since: API Level 1

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

Constant Value: 1 (0x00000001)

public static final int FLAG_WINDOW_IS_OBSCURED

Since: API Level 9

This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it. This flag is set to true even if 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.

Constant Value: 1 (0x00000001)

Fields

public static final Creator<MotionEvent> CREATOR

Since: API Level 1

Public Methods

public final void addBatch (long eventTime, PointerCoords[] pointerCoords, int metaState)

Since: API Level 9

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 The time stamp (in ms) for this data.
pointerCoords The new pointer coordinates.
metaState Meta key state.

public final void addBatch (long eventTime, float x, float y, float pressure, float size, int metaState)

Since: API Level 1

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 The time stamp (in ms) for this data.
x The new X position.
y The new Y position.
pressure The new pressure.
size The new size.
metaState Meta key state.

public static int axisFromString (String symbolicName)

Since: API Level 12

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

Parameters
symbolicName The symbolic name of the axis.
Returns
  • The axis or -1 if not found.

public static String axisToString (int axis)

Since: API Level 12

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 The axis
Returns
  • The symbolic name of the specified axis.

public final int findPointerIndex (int pointerId)

Since: API Level 5

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

Parameters
pointerId The identifier of the pointer to be found.
Returns
  • 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.

public final int getAction ()

Since: API Level 1

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

Returns

public final int getActionIndex ()

Since: API Level 8

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.

Returns
  • The index associated with the action.

public final int getActionMasked ()

Since: API Level 8

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

Returns

public final float getAxisValue (int axis)

Since: API Level 12

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

Parameters
axis The axis identifier for the axis value to retrieve.
See Also

public final float getAxisValue (int axis, int pointerIndex)

Since: API Level 12

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 The axis identifier for the axis value to retrieve.
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
Returns
  • The value of the axis, or 0 if the axis is not available.
See Also

public final int getDeviceId ()

Since: API Level 1

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.

Returns
  • The device id.

public final long getDownTime ()

Since: API Level 1

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

public final int getEdgeFlags ()

Since: API Level 1

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.

public final long getEventTime ()

Since: API Level 1

Returns the time (in ms) when this specific event was generated.

public final int getFlags ()

Since: API Level 9

Gets the motion event flags.

public final float getHistoricalAxisValue (int axis, int pointerIndex, int pos)

Since: API Level 12

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 The axis identifier for the axis value to retrieve.
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()
Returns
  • The value of the axis, or 0 if the axis is not available.
See Also

public final float getHistoricalAxisValue (int axis, int pos)

Since: API Level 12

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

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

public final long getHistoricalEventTime (int pos)

Since: API Level 1

Returns the time that a historical movement occurred between this event and the previous event. Only applies to ACTION_MOVE events.

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalOrientation (int pointerIndex, int pos)

Since: API Level 9

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalOrientation (int pos)

Since: API Level 9

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final void getHistoricalPointerCoords (int pointerIndex, int pos, MotionEvent.PointerCoords outPointerCoords)

Since: API Level 9

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

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

public final float getHistoricalPressure (int pos)

Since: API Level 1

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalPressure (int pointerIndex, int pos)

Since: API Level 5

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalSize (int pos)

Since: API Level 1

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalSize (int pointerIndex, int pos)

Since: API Level 5

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalToolMajor (int pointerIndex, int pos)

Since: API Level 9

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalToolMajor (int pos)

Since: API Level 9

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalToolMinor (int pointerIndex, int pos)

Since: API Level 9

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalToolMinor (int pos)

Since: API Level 9

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalTouchMajor (int pointerIndex, int pos)

Since: API Level 9

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalTouchMajor (int pos)

Since: API Level 9

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalTouchMinor (int pointerIndex, int pos)

Since: API Level 9

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalTouchMinor (int pos)

Since: API Level 9

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalX (int pos)

Since: API Level 1

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalX (int pointerIndex, int pos)

Since: API Level 5

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalY (int pos)

Since: API Level 1

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

Parameters
pos Which historical value to return; must be less than getHistorySize()

public final float getHistoricalY (int pointerIndex, int pos)

Since: API Level 5

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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.
pos Which historical value to return; must be less than getHistorySize()

public final int getHistorySize ()

Since: API Level 1

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.

Returns
  • Returns the number of historical points in the event.

public final int getMetaState ()

Since: API Level 1

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.

Returns
  • an integer in which each bit set to 1 represents a pressed meta key
See Also

public final float getOrientation (int pointerIndex)

Since: API Level 9

Returns the orientation of the touch area and tool area in radians clockwise from vertical for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). 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).

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

public final float getOrientation ()

Since: API Level 9

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

See Also

public final void getPointerCoords (int pointerIndex, MotionEvent.PointerCoords outPointerCoords)

Since: API Level 9

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

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

public final int getPointerCount ()

Since: API Level 5

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

public final int getPointerId (int pointerIndex)

Since: API Level 5

Return the pointer identifier associated with a particular pointer data index is 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 Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

public final float getPressure ()

Since: API Level 1

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

See Also

public final float getPressure (int pointerIndex)

Since: API Level 5

Returns the current pressure of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). 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.

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

public final float getRawX ()

Since: API Level 1

Returns the original raw X coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.

public final float getRawY ()

Since: API Level 1

Returns the original raw Y coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.

public final float getSize (int pointerIndex)

Since: API Level 5

Returns a scaled value of the approximate size for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). This represents some approximation of the area of the screen being pressed; the actual value in pixels corresponding to the touch is normalized with the device specific range of values and scaled to a value between 0 and 1. The value of size can be used to determine fat touch events.

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

public final float getSize ()

Since: API Level 1

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

See Also

public final int getSource ()

Since: API Level 9

Gets the source of the event.

Returns

public final float getToolMajor (int pointerIndex)

Since: API Level 9

Returns the length of the major axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). The tool area represents the estimated size of the finger or pen that is touching the device independent of its actual touch area at the point of contact.

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

public final float getToolMajor ()

Since: API Level 9

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

See Also

public final float getToolMinor ()

Since: API Level 9

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

See Also

public final float getToolMinor (int pointerIndex)

Since: API Level 9

Returns the length of the minor axis of an ellipse that describes the size of the approaching tool for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). The tool area represents the estimated size of the finger or pen that is touching the device independent of its actual touch area at the point of contact.

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

public final float getTouchMajor ()

Since: API Level 9

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

See Also

public final float getTouchMajor (int pointerIndex)

Since: API Level 9

Returns the length of the major axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).

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

public final float getTouchMinor ()

Since: API Level 9

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

See Also

public final float getTouchMinor (int pointerIndex)

Since: API Level 9

Returns the length of the minor axis of an ellipse that describes the touch area at the point of contact for the given pointer index (use getPointerId(int) to find the pointer identifier for this index).

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

public final float getX (int pointerIndex)

Since: API Level 5

Returns the X coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.

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

public final float getX ()

Since: API Level 1

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

See Also

public final float getXPrecision ()

Since: API Level 1

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.

Returns
  • Returns the precision of X coordinates being reported.
See Also

public final float getY (int pointerIndex)

Since: API Level 5

Returns the Y coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.

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

public final float getY ()

Since: API Level 1

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

See Also

public final float getYPrecision ()

Since: API Level 1

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.

Returns
  • Returns the precision of Y coordinates being reported.
See Also

public static MotionEvent obtain (long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)

Since: API Level 1

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

Parameters
downTime The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from uptimeMillis().
eventTime The the time (in ms) when this specific event was generated. This must be obtained from uptimeMillis().
action The kind of action being performed, such as ACTION_DOWN.
x The X coordinate of this event.
y The Y coordinate of this event.
pressure 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 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 The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision The precision of the X coordinate being reported.
yPrecision The precision of the Y coordinate being reported.
deviceId 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 A bitfield indicating which edges, if any, were touched by this MotionEvent.

public static MotionEvent obtain (long downTime, long eventTime, int action, int pointers, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)

Since: API Level 5

This method is 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 The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from uptimeMillis().
eventTime The the time (in ms) when this specific event was generated. This must be obtained from uptimeMillis().
action The kind of action being performed, such as ACTION_DOWN.
pointers The number of pointers that are active in this event.
x The X coordinate of this event.
y The Y coordinate of this event.
pressure 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 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 The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision The precision of the X coordinate being reported.
yPrecision The precision of the Y coordinate being reported.
deviceId 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 A bitfield indicating which edges, if any, were touched by this MotionEvent.

public static MotionEvent obtain (long downTime, long eventTime, int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)

Since: API Level 9

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

Parameters
downTime The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from uptimeMillis().
eventTime The the time (in ms) when this specific event was generated. This must be obtained from uptimeMillis().
action The kind of action being performed, such as ACTION_DOWN.
pointers The number of points that will be in this event.
pointerIds An array of pointers values providing an identifier for each pointer.
pointerCoords An array of pointers values providing a MotionEvent.PointerCoords coordinate object for each pointer.
metaState The state of any meta / modifier keys that were in effect when the event was generated.
xPrecision The precision of the X coordinate being reported.
yPrecision The precision of the Y coordinate being reported.
deviceId 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 A bitfield indicating which edges, if any, were touched by this MotionEvent.
source The source of this event.
flags The motion event flags.

public static MotionEvent obtain (MotionEvent other)

Since: API Level 1

Create a new MotionEvent, copying from an existing one.

public static MotionEvent obtain (long downTime, long eventTime, int action, float x, float y, int metaState)

Since: API Level 1

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 The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from uptimeMillis().
eventTime The the time (in ms) when this specific event was generated. This must be obtained from uptimeMillis().
action The kind of action being performed, such as ACTION_DOWN.
x The X coordinate of this event.
y The Y coordinate of this event.
metaState The state of any meta / modifier keys that were in effect when the event was generated.

public static MotionEvent obtainNoHistory (MotionEvent other)

Since: API Level 5

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

public final void offsetLocation (float deltaX, float deltaY)

Since: API Level 1

Adjust this event's location.

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

public final void recycle ()

Since: API Level 1

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

public final void setAction (int action)

Since: API Level 1

Sets this event's action.

public final void setEdgeFlags (int flags)

Since: API Level 1

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

See Also

public final void setLocation (float x, float y)

Since: API Level 1

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

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

public final void setSource (int source)

Since: API Level 12

Modifies the source of the event.

Parameters
source The new source.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public final void transform (Matrix matrix)

Since: API Level 11

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

Parameters
matrix The transformation matrix to apply.

public void writeToParcel (Parcel out, int flags)

Since: API Level 1

Flatten this object in to a Parcel.

Parameters
out The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Protected Methods

protected void finalize ()

Since: API Level 1

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable