FileDocCategorySizeDatePackage
MotionEvent.javaAPI DocAndroid 5.1 API141168Thu Mar 12 22:22:10 GMT 2015android.view

MotionEvent

public final class MotionEvent extends InputEvent implements android.os.Parcelable
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 {@link View} with the action code {@link #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 {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP} or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by {@link #ACTION_CANCEL}).

The MotionEvent class provides many methods to query the position and other properties of pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue}, {@link #getPointerId(int)}, {@link #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 {@link #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 {@link #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 {@link #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 {@link #getButtonState()}. It is a good idea to check the button state while handling {@link #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 {@link #ACTION_MOVE} may batch together multiple movement samples within a single object. The most current pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}. Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)} and {@link #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));
}
}

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 {@link 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 {@link #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 {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly. Pointer movements are described by motion events with {@link #ACTION_MOVE}. Finally, a gesture end either when the final pointer goes up as represented by a motion event with {@link #ACTION_UP} or when gesture is canceled with {@link #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 {@link #ACTION_SCROLL} that includes the relative scroll offset in the {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information about retrieving these additional axes.

On trackball devices with source class {@link 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 {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN} or {@link #ACTION_UP} motion events when the trackball button is pressed or released.

On joystick devices with source class {@link 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 {@link InputDevice#getMotionRange}. Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y}, {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.

Refer to {@link 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 {@link #ACTION_CANCEL} and should tolerate anomalous situations such as receiving a new {@link #ACTION_DOWN} without first having received an {@link #ACTION_UP} for the prior gesture.

Fields Summary
private static final long
NS_PER_MS
private static final String
LABEL_PREFIX
public static final int
INVALID_POINTER_ID
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 {@link MotionEvent}.
public static final int
ACTION_MASK
Bit mask of the parts of the action code that are the action itself.
public static final int
ACTION_DOWN
Constant for {@link #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 {@link #getButtonState} to retrieve the button state.

public static final int
ACTION_UP
Constant for {@link #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.
public static final int
ACTION_MOVE
Constant for {@link #getActionMasked}: A change has happened during a press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
public static final int
ACTION_CANCEL
Constant for {@link #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.
public static final int
ACTION_OUTSIDE
Constant for {@link #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.
public static final int
ACTION_POINTER_DOWN
Constant for {@link #getActionMasked}: A non-primary pointer has gone down.

Use {@link #getActionIndex} to retrieve the index of the pointer that changed.

The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the unmasked action returned by {@link #getAction}.

public static final int
ACTION_POINTER_UP
Constant for {@link #getActionMasked}: A non-primary pointer has gone up.

Use {@link #getActionIndex} to retrieve the index of the pointer that changed.

The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the unmasked action returned by {@link #getAction}.

public static final int
ACTION_HOVER_MOVE
Constant for {@link #getActionMasked}: A change happened but the pointer is not down (unlike {@link #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 {@link View#onGenericMotionEvent(MotionEvent)} rather than {@link View#onTouchEvent(MotionEvent)}.

public static final int
ACTION_SCROLL
Constant for {@link #getActionMasked}: The motion event contains relative vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)} to retrieve the information from {@link #AXIS_VSCROLL} and {@link #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 {@link View#onGenericMotionEvent(MotionEvent)} rather than {@link View#onTouchEvent(MotionEvent)}.

public static final int
ACTION_HOVER_ENTER
Constant for {@link #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 {@link View#onGenericMotionEvent(MotionEvent)} rather than {@link View#onTouchEvent(MotionEvent)}.

public static final int
ACTION_HOVER_EXIT
Constant for {@link #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 {@link View#onGenericMotionEvent(MotionEvent)} rather than {@link View#onTouchEvent(MotionEvent)}.

public static final int
ACTION_POINTER_INDEX_MASK
Bits in the action code that represent a pointer index, used with {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting down by {@link #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 {@link #getPointerId(int)} and the actual data with {@link #getX(int)} etc.
public static final int
ACTION_POINTER_INDEX_SHIFT
Bit shift for the action bits holding the pointer index as defined by {@link #ACTION_POINTER_INDEX_MASK}.
public static final int
ACTION_POINTER_1_DOWN
public static final int
ACTION_POINTER_2_DOWN
public static final int
ACTION_POINTER_3_DOWN
public static final int
ACTION_POINTER_1_UP
public static final int
ACTION_POINTER_2_UP
public static final int
ACTION_POINTER_3_UP
public static final int
ACTION_POINTER_ID_MASK
public static final int
ACTION_POINTER_ID_SHIFT
public static final 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. 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.
public static final int
FLAG_TAINTED
Private flag that indicates when the system has detected that this motion event may be inconsistent with respect to the sequence of previously delivered motion events, such as when a pointer move event is sent but the pointer is not down.
public static final int
FLAG_TARGET_ACCESSIBILITY_FOCUS
Private flag indicating that this event was synthesized by the system and should be delivered to the accessibility focused view first. When being dispatched such an event is not handled by predecessors of the accessibility focused view and after the event reaches that view the flag is cleared and normal event dispatch is performed. This ensures that the platform can click on any view that has accessibility focus which is semantically equivalent to asking the view to perform a click accessibility action but more generic as views not implementing click action correctly can still be activated.
public static final int
EDGE_TOP
Flag indicating the motion event intersected the top edge of the screen.
public static final int
EDGE_BOTTOM
Flag indicating the motion event intersected the bottom edge of the screen.
public static final int
EDGE_LEFT
Flag indicating the motion event intersected the left edge of the screen.
public static final int
EDGE_RIGHT
Flag indicating the motion event intersected the right edge of the screen.
public static final int
AXIS_X
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 {@link 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).

public static final int
AXIS_Y
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 {@link 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).

public static final int
AXIS_PRESSURE
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.

public static final int
AXIS_SIZE
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. This value is of limited use. To obtain calibrated size information, use {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.

public static final int
AXIS_TOUCH_MAJOR
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 {@link InputDevice#getMotionRange(int)} to query the effective range of values.

public static final int
AXIS_TOUCH_MINOR
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 {@link 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.

public static final int
AXIS_TOOL_MAJOR
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 {@link 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.

public static final int
AXIS_TOOL_MINOR
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 {@link 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.

public static final int
AXIS_ORIENTATION
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 {@link #AXIS_TILT}.

public static final int
AXIS_VSCROLL
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.

public static final int
AXIS_HSCROLL
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.

public static final int
AXIS_Z
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.

public static final int
AXIS_RX
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).

public static final int
AXIS_RY
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).

public static final int
AXIS_RZ
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.

public static final int
AXIS_HAT_X
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).

public static final int
AXIS_HAT_Y
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).

public static final int
AXIS_LTRIGGER
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).

public static final int
AXIS_RTRIGGER
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).

public static final int
AXIS_THROTTLE
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).

public static final int
AXIS_RUDDER
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).

public static final int
AXIS_WHEEL
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).

public static final int
AXIS_GAS
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).

public static final int
AXIS_BRAKE
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).

public static final int
AXIS_DISTANCE
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.

public static final int
AXIS_TILT
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.

public static final int
AXIS_GENERIC_1
Axis constant: Generic 1 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_2
Axis constant: Generic 2 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_3
Axis constant: Generic 3 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_4
Axis constant: Generic 4 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_5
Axis constant: Generic 5 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_6
Axis constant: Generic 6 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_7
Axis constant: Generic 7 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_8
Axis constant: Generic 8 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_9
Axis constant: Generic 9 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_10
Axis constant: Generic 10 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_11
Axis constant: Generic 11 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_12
Axis constant: Generic 12 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_13
Axis constant: Generic 13 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_14
Axis constant: Generic 14 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_15
Axis constant: Generic 15 axis of a motion event. The interpretation of a generic axis is device-specific.
public static final int
AXIS_GENERIC_16
Axis constant: Generic 16 axis of a motion event. The interpretation of a generic axis is device-specific.
private static final android.util.SparseArray
AXIS_SYMBOLIC_NAMES
public static final int
BUTTON_PRIMARY
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.
public static final int
BUTTON_SECONDARY
Button constant: Secondary button (right mouse button, stylus first button).
public static final int
BUTTON_TERTIARY
Button constant: Tertiary button (middle mouse button, stylus second button).
public static final int
BUTTON_BACK
Button constant: Back button pressed (mouse back button).

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

public static final int
BUTTON_FORWARD
Button constant: Forward button pressed (mouse forward button).

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

private static final String[]
BUTTON_SYMBOLIC_NAMES
public static final int
TOOL_TYPE_UNKNOWN
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.
public static final int
TOOL_TYPE_FINGER
Tool type constant: The tool is a finger.
public static final int
TOOL_TYPE_STYLUS
Tool type constant: The tool is a stylus.
public static final int
TOOL_TYPE_MOUSE
Tool type constant: The tool is a mouse or trackpad.
public static final int
TOOL_TYPE_ERASER
Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
private static final android.util.SparseArray
TOOL_TYPE_SYMBOLIC_NAMES
private static final int
HISTORY_CURRENT
private static final int
MAX_RECYCLED
private static final Object
gRecyclerLock
private static int
gRecyclerUsed
private static MotionEvent
gRecyclerTop
private static final Object
gSharedTempLock
private static PointerCoords[]
gSharedTempPointerCoords
private static PointerProperties[]
gSharedTempPointerProperties
private static int[]
gSharedTempPointerIndexMap
private long
mNativePtr
private MotionEvent
mNext
public static final Parcelable.Creator
CREATOR
Constructors Summary
private MotionEvent()

    
Methods Summary
public static java.lang.StringactionToString(int action)
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.

param
action The unmasked action.
return
The symbolic name of the specified action.
see
#getAction()

        switch (action) {
            case ACTION_DOWN:
                return "ACTION_DOWN";
            case ACTION_UP:
                return "ACTION_UP";
            case ACTION_CANCEL:
                return "ACTION_CANCEL";
            case ACTION_OUTSIDE:
                return "ACTION_OUTSIDE";
            case ACTION_MOVE:
                return "ACTION_MOVE";
            case ACTION_HOVER_MOVE:
                return "ACTION_HOVER_MOVE";
            case ACTION_SCROLL:
                return "ACTION_SCROLL";
            case ACTION_HOVER_ENTER:
                return "ACTION_HOVER_ENTER";
            case ACTION_HOVER_EXIT:
                return "ACTION_HOVER_EXIT";
        }
        int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
        switch (action & ACTION_MASK) {
            case ACTION_POINTER_DOWN:
                return "ACTION_POINTER_DOWN(" + index + ")";
            case ACTION_POINTER_UP:
                return "ACTION_POINTER_UP(" + index + ")";
            default:
                return Integer.toString(action);
        }
    
public final voidaddBatch(long eventTime, float x, float y, float pressure, float size, int metaState)
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 {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.

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

        synchronized (gSharedTempLock) {
            ensureSharedTempPointerCapacity(1);
            final PointerCoords[] pc = gSharedTempPointerCoords;
            pc[0].clear();
            pc[0].x = x;
            pc[0].y = y;
            pc[0].pressure = pressure;
            pc[0].size = size;

            nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
        }
    
public final voidaddBatch(long eventTime, android.view.MotionEvent$PointerCoords[] pointerCoords, int metaState)
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 {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.

param
eventTime The time stamp (in ms) for this data.
param
pointerCoords The new pointer coordinates.
param
metaState Meta key state.

        nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
    
public final booleanaddBatch(android.view.MotionEvent event)
Adds all of the movement samples of the specified event to this one if it is compatible. To be compatible, the event must have the same device id, source, action, flags, pointer count, pointer properties. Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.

param
event The event whose movements samples should be added to this one if possible.
return
True if batching was performed or false if batching was not possible.
hide

        final int action = nativeGetAction(mNativePtr);
        if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
            return false;
        }
        if (action != nativeGetAction(event.mNativePtr)) {
            return false;
        }

        if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
                || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
                || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) {
            return false;
        }

        final int pointerCount = nativeGetPointerCount(mNativePtr);
        if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
            return false;
        }

        synchronized (gSharedTempLock) {
            ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
            final PointerProperties[] pp = gSharedTempPointerProperties;
            final PointerCoords[] pc = gSharedTempPointerCoords;

            for (int i = 0; i < pointerCount; i++) {
                nativeGetPointerProperties(mNativePtr, i, pp[0]);
                nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
                if (!pp[0].equals(pp[1])) {
                    return false;
                }
            }

            final int metaState = nativeGetMetaState(event.mNativePtr);
            final int historySize = nativeGetHistorySize(event.mNativePtr);
            for (int h = 0; h <= historySize; h++) {
                final int historyPos = (h == historySize ? HISTORY_CURRENT : h);

                for (int i = 0; i < pointerCount; i++) {
                    nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
                }

                final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
                nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
            }
        }
        return true;
    
public static intaxisFromString(java.lang.String symbolicName)
Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".

param
symbolicName The symbolic name of the axis.
return
The axis or -1 if not found.
see
KeyEvent#keyCodeToString(int)

        if (symbolicName.startsWith(LABEL_PREFIX)) {
            symbolicName = symbolicName.substring(LABEL_PREFIX.length());
            int axis = nativeAxisFromString(symbolicName);
            if (axis >= 0) {
                return axis;
            }
        }
        try {
            return Integer.parseInt(symbolicName, 10);
        } catch (NumberFormatException ex) {
            return -1;
        }
    
public static java.lang.StringaxisToString(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.

param
axis The axis.
return
The symbolic name of the specified axis.

        String symbolicName = nativeAxisToString(axis);
        return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
    
public static java.lang.StringbuttonStateToString(int buttonState)
Returns a string that represents the symbolic name of the specified combined button state flags such as "0", "BUTTON_PRIMARY", "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000" if unknown.

param
buttonState The button state.
return
The symbolic name of the specified combined button state flags.
hide

        if (buttonState == 0) {
            return "0";
        }
        StringBuilder result = null;
        int i = 0;
        while (buttonState != 0) {
            final boolean isSet = (buttonState & 1) != 0;
            buttonState >>>= 1; // unsigned shift!
            if (isSet) {
                final String name = BUTTON_SYMBOLIC_NAMES[i];
                if (result == null) {
                    if (buttonState == 0) {
                        return name;
                    }
                    result = new StringBuilder(name);
                } else {
                    result.append('|");
                    result.append(name);
                }
            }
            i += 1;
        }
        return result.toString();
    
public final voidcancel()

hide

        setAction(ACTION_CANCEL);
    
private static final floatclamp(float value, float low, float high)

        if (value < low) {
            return low;
        } else if (value > high) {
            return high;
        }
        return value;
    
public final android.view.MotionEventclampNoHistory(float left, float top, float right, float bottom)
Returns a new motion events whose points have been clamped to the specified bounds.

hide

        MotionEvent ev = obtain();
        synchronized (gSharedTempLock) {
            final int pointerCount = nativeGetPointerCount(mNativePtr);

            ensureSharedTempPointerCapacity(pointerCount);
            final PointerProperties[] pp = gSharedTempPointerProperties;
            final PointerCoords[] pc = gSharedTempPointerCoords;

            for (int i = 0; i < pointerCount; i++) {
                nativeGetPointerProperties(mNativePtr, i, pp[i]);
                nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
                pc[i].x = clamp(pc[i].x, left, right);
                pc[i].y = clamp(pc[i].y, top, bottom);
            }
            ev.mNativePtr = nativeInitialize(ev.mNativePtr,
                    nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
                    nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
                    nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
                    nativeGetButtonState(mNativePtr),
                    nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
                    nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
                    nativeGetDownTimeNanos(mNativePtr),
                    nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
                    pointerCount, pp, pc);
            return ev;
        }
    
public android.view.MotionEventcopy()

hide

        return obtain(this);
    
public static android.view.MotionEventcreateFromParcelBody(android.os.Parcel in)

hide


      
         
        MotionEvent ev = obtain();
        ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
        return ev;
    
private static final voidensureSharedTempPointerCapacity(int desiredCapacity)


          
        if (gSharedTempPointerCoords == null
                || gSharedTempPointerCoords.length < desiredCapacity) {
            int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
            while (capacity < desiredCapacity) {
                capacity *= 2;
            }
            gSharedTempPointerCoords = PointerCoords.createArray(capacity);
            gSharedTempPointerProperties = PointerProperties.createArray(capacity);
            gSharedTempPointerIndexMap = new int[capacity];
        }
    
protected voidfinalize()

        try {
            if (mNativePtr != 0) {
                nativeDispose(mNativePtr);
                mNativePtr = 0;
            }
        } finally {
            super.finalize();
        }
    
public final intfindPointerIndex(int pointerId)
Given a pointer identifier, find the index of its data in the event.

param
pointerId The identifier of the pointer to be found.
return
Returns either the index of the pointer (for use with {@link #getX(int)} et al.), or -1 if there is no data available for that pointer identifier.

        return nativeFindPointerIndex(mNativePtr, pointerId);
    
public final intgetAction()
Return the kind of action being performed. Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve the separate masked action and pointer index.

return
The action, such as {@link #ACTION_DOWN} or the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.

        return nativeGetAction(mNativePtr);
    
public final intgetActionIndex()
For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} as returned by {@link #getActionMasked}, this returns the associated pointer index. The index may be used with {@link #getPointerId(int)}, {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, and {@link #getSize(int)} to get information about the pointer that has gone down or up.

return
The index associated with the action.

        return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
                >> ACTION_POINTER_INDEX_SHIFT;
    
public final intgetActionMasked()
Return the masked action being performed, without pointer index information. Use {@link #getActionIndex} to return the index associated with pointer actions.

return
The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.

        return nativeGetAction(mNativePtr) & ACTION_MASK;
    
public final floatgetAxisValue(int axis)
{@link #getAxisValue(int)} for the first pointer index (may be an arbitrary pointer identifier).

param
axis The axis identifier for the axis value to retrieve.
see
#AXIS_X
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
    
public final floatgetAxisValue(int axis, int pointerIndex)
Returns the value of the requested axis for the given pointer index (use {@link #getPointerId(int)} to find the pointer identifier for this index).

param
axis The axis identifier for the axis value to retrieve.
param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
return
The value of the axis, or 0 if the axis is not available.
see
#AXIS_X
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
    
public final intgetButtonState()
Gets the state of all buttons that are pressed such as a mouse or stylus button.

return
The button state.
see
#BUTTON_PRIMARY
see
#BUTTON_SECONDARY
see
#BUTTON_TERTIARY
see
#BUTTON_FORWARD
see
#BUTTON_BACK

        return nativeGetButtonState(mNativePtr);
    
public final intgetDeviceId()
{@inheritDoc}

        return nativeGetDeviceId(mNativePtr);
    
public final longgetDownTime()
Returns the time (in ms) when the user originally pressed down to start a stream of position events.

        return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
    
public final intgetEdgeFlags()
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 {@link #ACTION_DOWN} events.

see
#EDGE_LEFT
see
#EDGE_TOP
see
#EDGE_RIGHT
see
#EDGE_BOTTOM

        return nativeGetEdgeFlags(mNativePtr);
    
public final longgetEventTime()
Retrieve the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base.

return
Returns the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base.

        return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
    
public final longgetEventTimeNano()
Retrieve the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base but with nanosecond precision.

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

return
Returns the time this event occurred, in the {@link android.os.SystemClock#uptimeMillis} time base but with nanosecond precision.
hide

        return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
    
public final intgetFlags()
Gets the motion event flags.

see
#FLAG_WINDOW_IS_OBSCURED

        return nativeGetFlags(mNativePtr);
    
public final floatgetHistoricalAxisValue(int axis, int pos)
{@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
axis The axis identifier for the axis value to retrieve.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getAxisValue(int)
see
#AXIS_X
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, axis, 0, pos);
    
public final floatgetHistoricalAxisValue(int axis, int pointerIndex, int pos)
Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)}, occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
axis The axis identifier for the axis value to retrieve.
param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
return
The value of the axis, or 0 if the axis is not available.
see
#AXIS_X
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
    
public final longgetHistoricalEventTime(int pos)
Returns the time that a historical movement occurred between this event and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.

This only applies to ACTION_MOVE events.

param
pos Which historical value to return; must be less than {@link #getHistorySize}
return
Returns the time that a historical movement occurred between this event and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
see
#getHistorySize
see
#getEventTime

        return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
    
public final longgetHistoricalEventTimeNano(int pos)
Returns the time that a historical movement occurred between this event and the previous event, in the {@link 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.

param
pos Which historical value to return; must be less than {@link #getHistorySize}
return
Returns the time that a historical movement occurred between this event and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base but with nanosecond (instead of millisecond) precision.
see
#getHistorySize
see
#getEventTime
hide

        return nativeGetEventTimeNanos(mNativePtr, pos);
    
public final floatgetHistoricalOrientation(int pos)
{@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getOrientation()
see
#AXIS_ORIENTATION

        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
    
public final floatgetHistoricalOrientation(int pointerIndex, int pos)
Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getOrientation(int)
see
#AXIS_ORIENTATION

        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
    
public final voidgetHistoricalPointerCoords(int pointerIndex, int pos, android.view.MotionEvent$PointerCoords outPointerCoords)
Populates a {@link PointerCoords} object with historical pointer coordinate data, as per {@link #getPointerCoords}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
param
outPointerCoords The pointer coordinate object to populate.
see
#getHistorySize
see
#getPointerCoords
see
PointerCoords

        nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
    
public final floatgetHistoricalPressure(int pos)
{@link #getHistoricalPressure(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getPressure()
see
#AXIS_PRESSURE

        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
    
public final floatgetHistoricalPressure(int pointerIndex, int pos)
Returns a historical pressure coordinate, as per {@link #getPressure(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getPressure(int)
see
#AXIS_PRESSURE

        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
    
public final floatgetHistoricalSize(int pos)
{@link #getHistoricalSize(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getSize()
see
#AXIS_SIZE

        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
    
public final floatgetHistoricalSize(int pointerIndex, int pos)
Returns a historical size coordinate, as per {@link #getSize(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getSize(int)
see
#AXIS_SIZE

        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
    
public final floatgetHistoricalToolMajor(int pos)
{@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getToolMajor()
see
#AXIS_TOOL_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
    
public final floatgetHistoricalToolMajor(int pointerIndex, int pos)
Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getToolMajor(int)
see
#AXIS_TOOL_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
    
public final floatgetHistoricalToolMinor(int pos)
{@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getToolMinor()
see
#AXIS_TOOL_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
    
public final floatgetHistoricalToolMinor(int pointerIndex, int pos)
Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getToolMinor(int)
see
#AXIS_TOOL_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
    
public final floatgetHistoricalTouchMajor(int pos)
{@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getTouchMajor()
see
#AXIS_TOUCH_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
    
public final floatgetHistoricalTouchMajor(int pointerIndex, int pos)
Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getTouchMajor(int)
see
#AXIS_TOUCH_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
    
public final floatgetHistoricalTouchMinor(int pos)
{@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getTouchMinor()
see
#AXIS_TOUCH_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
    
public final floatgetHistoricalTouchMinor(int pointerIndex, int pos)
Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getTouchMinor(int)
see
#AXIS_TOUCH_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
    
public final floatgetHistoricalX(int pos)
{@link #getHistoricalX(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getX()
see
#AXIS_X

        return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
    
public final floatgetHistoricalX(int pointerIndex, int pos)
Returns a historical X coordinate, as per {@link #getX(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getX(int)
see
#AXIS_X

        return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
    
public final floatgetHistoricalY(int pos)
{@link #getHistoricalY(int, int)} for the first pointer index (may be an arbitrary pointer identifier).

param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getY()
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
    
public final floatgetHistoricalY(int pointerIndex, int pos)
Returns a historical Y coordinate, as per {@link #getY(int)}, that occurred between this event and the previous event for the given pointer. Only applies to ACTION_MOVE events.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
pos Which historical value to return; must be less than {@link #getHistorySize}
see
#getHistorySize
see
#getY(int)
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
    
public final intgetHistorySize()
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
Returns the number of historical points in the event.

        return nativeGetHistorySize(mNativePtr);
    
public final intgetMetaState()
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 {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.

return
an integer in which each bit set to 1 represents a pressed meta key
see
KeyEvent#getMetaState()

        return nativeGetMetaState(mNativePtr);
    
public final floatgetOrientation()
{@link #getOrientation(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_ORIENTATION

        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
    
public final floatgetOrientation(int pointerIndex)
Returns the orientation of the touch area and tool area in radians clockwise from vertical for the given pointer index (use {@link #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).

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_ORIENTATION

        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
    
public final voidgetPointerCoords(int pointerIndex, android.view.MotionEvent$PointerCoords outPointerCoords)
Populates a {@link PointerCoords} object with pointer coordinate data for the specified pointer index.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
outPointerCoords The pointer coordinate object to populate.
see
PointerCoords

        nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
    
public final intgetPointerCount()
The number of pointers of data contained in this event. Always >= 1.

        return nativeGetPointerCount(mNativePtr);
    
public final intgetPointerId(int pointerIndex)
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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.

        return nativeGetPointerId(mNativePtr, pointerIndex);
    
public final intgetPointerIdBits()
Gets an integer where each pointer id present in the event is marked as a bit.

hide

        int idBits = 0;
        final int pointerCount = nativeGetPointerCount(mNativePtr);
        for (int i = 0; i < pointerCount; i++) {
            idBits |= 1 << nativeGetPointerId(mNativePtr, i);
        }
        return idBits;
    
public final voidgetPointerProperties(int pointerIndex, android.view.MotionEvent$PointerProperties outPointerProperties)
Populates a {@link PointerProperties} object with pointer properties for the specified pointer index.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
param
outPointerProperties The pointer properties object to populate.
see
PointerProperties

        nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
    
public final floatgetPressure()
{@link #getPressure(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_PRESSURE

        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
    
public final floatgetPressure(int pointerIndex)
Returns the current pressure of this event for the given pointer index (use {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_PRESSURE

        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
    
public final floatgetRawX()
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.

see
#getX(int)
see
#AXIS_X

        return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
    
public final floatgetRawY()
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.

see
#getY(int)
see
#AXIS_Y

        return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
    
public final floatgetSize()
{@link #getSize(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_SIZE

        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
    
public final floatgetSize(int pointerIndex)
Returns a scaled value of the approximate size for the given pointer index (use {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_SIZE

        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
    
public final intgetSource()
{@inheritDoc}

        return nativeGetSource(mNativePtr);
    
public final floatgetToolMajor()
{@link #getToolMajor(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_TOOL_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
    
public final floatgetToolMajor(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 {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_TOOL_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
    
public final floatgetToolMinor()
{@link #getToolMinor(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_TOOL_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
    
public final floatgetToolMinor(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 {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_TOOL_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
    
public final intgetToolType(int pointerIndex)
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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
return
The tool type of the pointer.
see
#TOOL_TYPE_UNKNOWN
see
#TOOL_TYPE_FINGER
see
#TOOL_TYPE_STYLUS
see
#TOOL_TYPE_MOUSE

        return nativeGetToolType(mNativePtr, pointerIndex);
    
public final floatgetTouchMajor()
{@link #getTouchMajor(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_TOUCH_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
    
public final floatgetTouchMajor(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 {@link #getPointerId(int)} to find the pointer identifier for this index).

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_TOUCH_MAJOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
    
public final floatgetTouchMinor()
{@link #getTouchMinor(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_TOUCH_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
    
public final floatgetTouchMinor(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 {@link #getPointerId(int)} to find the pointer identifier for this index).

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_TOUCH_MINOR

        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
    
public final floatgetX()
{@link #getX(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_X

        return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
    
public final floatgetX(int pointerIndex)
Returns the X coordinate of this event for the given pointer index (use {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_X

        return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
    
public final floatgetXPrecision()
Return the precision of the X coordinates being reported. You can multiply this number with {@link #getX} to find the actual hardware value of the X coordinate.

return
Returns the precision of X coordinates being reported.
see
#AXIS_X

        return nativeGetXPrecision(mNativePtr);
    
public final floatgetY()
{@link #getY(int)} for the first pointer index (may be an arbitrary pointer identifier).

see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
    
public final floatgetY(int pointerIndex)
Returns the Y coordinate of this event for the given pointer index (use {@link #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.

param
pointerIndex Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to {@link #getPointerCount()}-1.
see
#AXIS_Y

        return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
    
public final floatgetYPrecision()
Return the precision of the Y coordinates being reported. You can multiply this number with {@link #getY} to find the actual hardware value of the Y coordinate.

return
Returns the precision of Y coordinates being reported.
see
#AXIS_Y

        return nativeGetYPrecision(mNativePtr);
    
public final booleanisButtonPressed(int button)
Checks if a mouse or stylus button (or combination of buttons) is pressed.

param
button Button (or combination of buttons).
return
True if specified buttons are pressed.
see
#BUTTON_PRIMARY
see
#BUTTON_SECONDARY
see
#BUTTON_TERTIARY
see
#BUTTON_FORWARD
see
#BUTTON_BACK

        if (button == 0) {
            return false;
        }
        return (getButtonState() & button) == button;
    
public final booleanisTainted()

hide

        final int flags = getFlags();
        return (flags & FLAG_TAINTED) != 0;
    
public final booleanisTargetAccessibilityFocus()

hide

        final int flags = getFlags();
        return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
    
public final booleanisTouchEvent()
Returns true if this motion event is a touch event.

Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE}, {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL} because they are not actually touch events (the pointer is not down).

return
True if this motion event is a touch event.
hide

        return nativeIsTouchEvent(mNativePtr);
    
public final booleanisWithinBoundsNoHistory(float left, float top, float right, float bottom)
Returns true if all points in the motion event are completely within the specified bounds.

hide

        final int pointerCount = nativeGetPointerCount(mNativePtr);
        for (int i = 0; i < pointerCount; i++) {
            final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
            final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
            if (x < left || x > right || y < top || y > bottom) {
                return false;
            }
        }
        return true;
    
private static native voidnativeAddBatch(long nativePtr, long eventTimeNanos, android.view.MotionEvent$PointerCoords[] pointerCoords, int metaState)

private static native intnativeAxisFromString(java.lang.String label)

private static native java.lang.StringnativeAxisToString(int axis)

private static native longnativeCopy(long destNativePtr, long sourceNativePtr, boolean keepHistory)

private static native voidnativeDispose(long nativePtr)

private static native intnativeFindPointerIndex(long nativePtr, int pointerId)

private static native intnativeGetAction(long nativePtr)

private static native floatnativeGetAxisValue(long nativePtr, int axis, int pointerIndex, int historyPos)

private static native intnativeGetButtonState(long nativePtr)

private static native intnativeGetDeviceId(long nativePtr)

private static native longnativeGetDownTimeNanos(long nativePtr)

private static native intnativeGetEdgeFlags(long nativePtr)

private static native longnativeGetEventTimeNanos(long nativePtr, int historyPos)

private static native intnativeGetFlags(long nativePtr)

private static native intnativeGetHistorySize(long nativePtr)

private static native intnativeGetMetaState(long nativePtr)

private static native voidnativeGetPointerCoords(long nativePtr, int pointerIndex, int historyPos, android.view.MotionEvent$PointerCoords outPointerCoords)

private static native intnativeGetPointerCount(long nativePtr)

private static native intnativeGetPointerId(long nativePtr, int pointerIndex)

private static native voidnativeGetPointerProperties(long nativePtr, int pointerIndex, android.view.MotionEvent$PointerProperties outPointerProperties)

private static native floatnativeGetRawAxisValue(long nativePtr, int axis, int pointerIndex, int historyPos)

private static native intnativeGetSource(long nativePtr)

private static native intnativeGetToolType(long nativePtr, int pointerIndex)

private static native floatnativeGetXOffset(long nativePtr)

private static native floatnativeGetXPrecision(long nativePtr)

private static native floatnativeGetYOffset(long nativePtr)

private static native floatnativeGetYPrecision(long nativePtr)

private static native longnativeInitialize(long nativePtr, int deviceId, int source, int action, int flags, int edgeFlags, int metaState, int buttonState, float xOffset, float yOffset, float xPrecision, float yPrecision, long downTimeNanos, long eventTimeNanos, int pointerCount, android.view.MotionEvent$PointerProperties[] pointerIds, android.view.MotionEvent$PointerCoords[] pointerCoords)

private static native booleannativeIsTouchEvent(long nativePtr)

private static native voidnativeOffsetLocation(long nativePtr, float deltaX, float deltaY)

private static native longnativeReadFromParcel(long nativePtr, android.os.Parcel parcel)

private static native voidnativeScale(long nativePtr, float scale)

private static native voidnativeSetAction(long nativePtr, int action)

private static native voidnativeSetDownTimeNanos(long nativePtr, long downTime)

private static native voidnativeSetEdgeFlags(long nativePtr, int action)

private static native voidnativeSetFlags(long nativePtr, int flags)

private static native intnativeSetSource(long nativePtr, int source)

private static native voidnativeTransform(long nativePtr, android.graphics.Matrix matrix)

private static native voidnativeWriteToParcel(long nativePtr, android.os.Parcel parcel)

private static android.view.MotionEventobtain()

        final MotionEvent ev;
        synchronized (gRecyclerLock) {
            ev = gRecyclerTop;
            if (ev == null) {
                return new MotionEvent();
            }
            gRecyclerTop = ev.mNext;
            gRecyclerUsed -= 1;
        }
        ev.mNext = null;
        ev.prepareForReuse();
        return ev;
    
public static android.view.MotionEventobtain(long downTime, long eventTime, int action, int pointerCount, android.view.MotionEvent$PointerProperties[] pointerProperties, android.view.MotionEvent$PointerCoords[] pointerCoords, int metaState, int buttonState, 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.

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

        MotionEvent ev = obtain();
        ev.mNativePtr = nativeInitialize(ev.mNativePtr,
                deviceId, source, action, flags, edgeFlags, metaState, buttonState,
                0, 0, xPrecision, yPrecision,
                downTime * NS_PER_MS, eventTime * NS_PER_MS,
                pointerCount, pointerProperties, pointerCoords);
        return ev;
    
public static android.view.MotionEventobtain(long downTime, long eventTime, int action, int pointerCount, int[] pointerIds, android.view.MotionEvent$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.

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

        synchronized (gSharedTempLock) {
            ensureSharedTempPointerCapacity(pointerCount);
            final PointerProperties[] pp = gSharedTempPointerProperties;
            for (int i = 0; i < pointerCount; i++) {
                pp[i].clear();
                pp[i].id = pointerIds[i];
            }
            return obtain(downTime, eventTime, action, pointerCount, pp,
                    pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
                    edgeFlags, source, flags);
        }
    
public static android.view.MotionEventobtain(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.

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

        MotionEvent ev = obtain();
        synchronized (gSharedTempLock) {
            ensureSharedTempPointerCapacity(1);
            final PointerProperties[] pp = gSharedTempPointerProperties;
            pp[0].clear();
            pp[0].id = 0;

            final PointerCoords pc[] = gSharedTempPointerCoords;
            pc[0].clear();
            pc[0].x = x;
            pc[0].y = y;
            pc[0].pressure = pressure;
            pc[0].size = size;

            ev.mNativePtr = nativeInitialize(ev.mNativePtr,
                    deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, 0,
                    0, 0, xPrecision, yPrecision,
                    downTime * NS_PER_MS, eventTime * NS_PER_MS,
                    1, pp, pc);
            return ev;
        }
    
public static android.view.MotionEventobtain(long downTime, long eventTime, int action, int pointerCount, 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.

param
downTime The time (in ms) when the user originally pressed down to start a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
param
eventTime The the time (in ms) when this specific event was generated. This must be obtained from {@link SystemClock#uptimeMillis()}.
param
action The kind of action being performed, such as {@link #ACTION_DOWN}.
param
pointerCount The number of pointers that are active in this event.
param
x The X coordinate of this event.
param
y The Y coordinate of this event.
param
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.
param
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.
param
metaState The state of any meta / modifier keys that were in effect when the event was generated.
param
xPrecision The precision of the X coordinate being reported.
param
yPrecision The precision of the Y coordinate being reported.
param
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.
param
edgeFlags A bitfield indicating which edges, if any, were touched by this MotionEvent.
deprecated
Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} instead.

        return obtain(downTime, eventTime, action, x, y, pressure, size,
                metaState, xPrecision, yPrecision, deviceId, edgeFlags);
    
public static android.view.MotionEventobtain(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. Those not specified here are: device id (always 0), pressure and size (always 1), x and y precision (always 1), and edgeFlags (always 0).

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

        return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
                metaState, 1.0f, 1.0f, 0, 0);
    
public static android.view.MotionEventobtain(android.view.MotionEvent other)
Create a new MotionEvent, copying from an existing one.

        if (other == null) {
            throw new IllegalArgumentException("other motion event must not be null");
        }

        MotionEvent ev = obtain();
        ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
        return ev;
    
public static android.view.MotionEventobtainNoHistory(android.view.MotionEvent other)
Create a new MotionEvent, copying from an existing one, but not including any historical point information.

        if (other == null) {
            throw new IllegalArgumentException("other motion event must not be null");
        }

        MotionEvent ev = obtain();
        ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
        return ev;
    
public final voidoffsetLocation(float deltaX, float deltaY)
Adjust this event's location.

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

        if (deltaX != 0.0f || deltaY != 0.0f) {
            nativeOffsetLocation(mNativePtr, deltaX, deltaY);
        }
    
public final voidrecycle()
Recycle the MotionEvent, to be re-used by a later caller. After calling this function you must not ever touch the event again.

        super.recycle();

        synchronized (gRecyclerLock) {
            if (gRecyclerUsed < MAX_RECYCLED) {
                gRecyclerUsed++;
                mNext = gRecyclerTop;
                gRecyclerTop = this;
            }
        }
    
public final voidscale(float scale)
Applies a scale factor to all points within this event. This method is used to adjust touch events to simulate different density displays for compatibility mode. The values returned by {@link #getRawX()}, {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()} are also affected by the scale factor.

param
scale The scale factor to apply.
hide

        if (scale != 1.0f) {
            nativeScale(mNativePtr, scale);
        }
    
public final voidsetAction(int action)
Sets this event's action.

        nativeSetAction(mNativePtr, action);
    
public final voidsetDownTime(long downTime)
Sets the time (in ms) when the user originally pressed down to start a stream of position events.

hide

        nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
    
public final voidsetEdgeFlags(int flags)
Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.

see
#getEdgeFlags()

        nativeSetEdgeFlags(mNativePtr, flags);
    
public final voidsetLocation(float x, float y)
Set this event's location. Applies {@link #offsetLocation} with a delta from the current location to the given new location.

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

        float oldX = getX();
        float oldY = getY();
        offsetLocation(x - oldX, y - oldY);
    
public final voidsetSource(int source)
{@inheritDoc}

        nativeSetSource(mNativePtr, source);
    
public final voidsetTainted(boolean tainted)

hide

        final int flags = getFlags();
        nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
    
public final voidsetTargetAccessibilityFocus(boolean targetsFocus)

hide

        final int flags = getFlags();
        nativeSetFlags(mNativePtr, targetsFocus
                ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
                : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
    
public final android.view.MotionEventsplit(int idBits)
Splits a motion event such that it includes only a subset of pointer ids.

hide

        MotionEvent ev = obtain();
        synchronized (gSharedTempLock) {
            final int oldPointerCount = nativeGetPointerCount(mNativePtr);
            ensureSharedTempPointerCapacity(oldPointerCount);
            final PointerProperties[] pp = gSharedTempPointerProperties;
            final PointerCoords[] pc = gSharedTempPointerCoords;
            final int[] map = gSharedTempPointerIndexMap;

            final int oldAction = nativeGetAction(mNativePtr);
            final int oldActionMasked = oldAction & ACTION_MASK;
            final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
                    >> ACTION_POINTER_INDEX_SHIFT;
            int newActionPointerIndex = -1;
            int newPointerCount = 0;
            int newIdBits = 0;
            for (int i = 0; i < oldPointerCount; i++) {
                nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
                final int idBit = 1 << pp[newPointerCount].id;
                if ((idBit & idBits) != 0) {
                    if (i == oldActionPointerIndex) {
                        newActionPointerIndex = newPointerCount;
                    }
                    map[newPointerCount] = i;
                    newPointerCount += 1;
                    newIdBits |= idBit;
                }
            }

            if (newPointerCount == 0) {
                throw new IllegalArgumentException("idBits did not match any ids in the event");
            }

            final int newAction;
            if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
                if (newActionPointerIndex < 0) {
                    // An unrelated pointer changed.
                    newAction = ACTION_MOVE;
                } else if (newPointerCount == 1) {
                    // The first/last pointer went down/up.
                    newAction = oldActionMasked == ACTION_POINTER_DOWN
                            ? ACTION_DOWN : ACTION_UP;
                } else {
                    // A secondary pointer went down/up.
                    newAction = oldActionMasked
                            | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
                }
            } else {
                // Simple up/down/cancel/move or other motion action.
                newAction = oldAction;
            }

            final int historySize = nativeGetHistorySize(mNativePtr);
            for (int h = 0; h <= historySize; h++) {
                final int historyPos = h == historySize ? HISTORY_CURRENT : h;

                for (int i = 0; i < newPointerCount; i++) {
                    nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
                }

                final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
                if (h == 0) {
                    ev.mNativePtr = nativeInitialize(ev.mNativePtr,
                            nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
                            newAction, nativeGetFlags(mNativePtr),
                            nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
                            nativeGetButtonState(mNativePtr),
                            nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
                            nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
                            nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
                            newPointerCount, pp, pc);
                } else {
                    nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
                }
            }
            return ev;
        }
    
public java.lang.StringtoString()

        StringBuilder msg = new StringBuilder();
        msg.append("MotionEvent { action=").append(actionToString(getAction()));

        final int pointerCount = getPointerCount();
        for (int i = 0; i < pointerCount; i++) {
            msg.append(", id[").append(i).append("]=").append(getPointerId(i));
            msg.append(", x[").append(i).append("]=").append(getX(i));
            msg.append(", y[").append(i).append("]=").append(getY(i));
            msg.append(", toolType[").append(i).append("]=").append(
                    toolTypeToString(getToolType(i)));
        }

        msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState()));
        msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState()));
        msg.append(", flags=0x").append(Integer.toHexString(getFlags()));
        msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags()));
        msg.append(", pointerCount=").append(pointerCount);
        msg.append(", historySize=").append(getHistorySize());
        msg.append(", eventTime=").append(getEventTime());
        msg.append(", downTime=").append(getDownTime());
        msg.append(", deviceId=").append(getDeviceId());
        msg.append(", source=0x").append(Integer.toHexString(getSource()));
        msg.append(" }");
        return msg.toString();
    
public static java.lang.StringtoolTypeToString(int toolType)
Returns a string that represents the symbolic name of the specified tool type such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.

param
toolType The tool type.
return
The symbolic name of the specified tool type.
hide

        String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
        return symbolicName != null ? symbolicName : Integer.toString(toolType);
    
public final voidtransform(android.graphics.Matrix matrix)
Applies a transformation matrix to all of the points in the event.

param
matrix The transformation matrix to apply.

        if (matrix == null) {
            throw new IllegalArgumentException("matrix must not be null");
        }

        nativeTransform(mNativePtr, matrix);
    
public voidwriteToParcel(android.os.Parcel out, int flags)

        out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
        nativeWriteToParcel(mNativePtr, out);