java.lang.Object | ||
↳ | android.view.InputEvent | |
↳ | android.view.MotionEvent |
Object used to report movement (mouse, pen, finger, trackball) events. Motion events may hold either absolute or relative movements and other data, depending on the type of device.
Motion events describe movements in terms of an action code and a set of axis values. The action code specifies the state change that occurred such as a pointer going down or up. The axis values describe the position and other movement properties.
For example, when the user first touches the screen, the system delivers a touch
event to the appropriate
View
with the action code
ACTION_DOWN
and a set of axis values that include the X and Y coordinates of the touch and
information about the pressure, size and orientation of the contact area.
Some devices can report multiple movement traces at the same time. Multi-touch screens emit one movement trace for each finger. The individual fingers or other objects that generate movement traces are referred to as pointers . Motion events contain information about all of the pointers that are currently active even if some of them have not moved since the last event was delivered.
The number of pointers only ever changes by one as individual pointers go up and down, except when the gesture is canceled.
Each pointer has a unique id that is assigned when it first goes down
(indicated by
ACTION_DOWN
or
ACTION_POINTER_DOWN
). A pointer id
remains valid until the pointer eventually goes up (indicated by
ACTION_UP
or
ACTION_POINTER_UP
) or when the gesture is canceled (indicated by
ACTION_CANCEL
).
The MotionEvent class provides many methods to query the position and other properties of
pointers, such as
getX(int)
,
getY(int)
,
getAxisValue(int)
,
getPointerId(int)
,
getToolType(int)
, and many others. Most of these
methods accept the pointer index as a parameter rather than the pointer id.
The pointer index of each pointer in the event ranges from 0 to one less than the value
returned by
getPointerCount()
.
The order in which individual pointers appear within a motion event is undefined.
Thus the pointer index of a pointer can change from one event to the next but
the pointer id of a pointer is guaranteed to remain constant as long as the pointer
remains active. Use the
getPointerId(int)
method to obtain the
pointer id of a pointer to track it across all subsequent motion events in a gesture.
Then for successive motion events, use the
findPointerIndex(int)
method
to obtain the pointer index for a given pointer id in that motion event.
Mouse and stylus buttons can be retrieved using
getButtonState()
. It is a
good idea to check the button state while handling
ACTION_DOWN
as part
of a touch event. The application may choose to perform some different action
if the touch event starts due to a secondary button click, such as presenting a
context menu.
For efficiency, motion events with
ACTION_MOVE
may batch together
multiple movement samples within a single object. The most current
pointer coordinates are available using
getX(int)
and
getY(int)
.
Earlier coordinates within the batch are accessed using
getHistoricalX(int, int)
and
getHistoricalY(int, int)
. The coordinates are "historical" only
insofar as they are older than the current coordinates in the batch; however,
they are still distinct from any other coordinates reported in prior motion events.
To process all coordinates in the batch in time order, first consume the historical
coordinates then consume the current coordinates.
Example: Consuming all samples for all pointers in a motion event in time order.
void printSamples(MotionEvent ev) {
final int historySize = ev.getHistorySize();
final int pointerCount = ev.getPointerCount();
for (int h = 0; h < historySize; h++) {
System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
for (int p = 0; p < pointerCount; p++) {
System.out.printf(" pointer %d: (%f,%f)",
ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
}
}
System.out.printf("At time %d:", ev.getEventTime());
for (int p = 0; p < pointerCount; p++) {
System.out.printf(" pointer %d: (%f,%f)",
ev.getPointerId(p), ev.getX(p), ev.getY(p));
}
}
The interpretation of the contents of a MotionEvent varies significantly depending on the source class of the device.
On pointing devices with source class
SOURCE_CLASS_POINTER
such as touch screens, the pointer coordinates specify absolute
positions such as view X/Y coordinates. Each complete gesture is represented
by a sequence of motion events with actions that describe pointer state transitions
and movements. A gesture starts with a motion event with
ACTION_DOWN
that provides the location of the first pointer down. As each additional
pointer that goes down or up, the framework will generate a motion event with
ACTION_POINTER_DOWN
or
ACTION_POINTER_UP
accordingly.
Pointer movements are described by motion events with
ACTION_MOVE
.
Finally, a gesture end either when the final pointer goes up as represented
by a motion event with
ACTION_UP
or when gesture is canceled
with
ACTION_CANCEL
.
Some pointing devices such as mice may support vertical and/or horizontal scrolling.
A scroll event is reported as a generic motion event with
ACTION_SCROLL
that
includes the relative scroll offset in the
AXIS_VSCROLL
and
AXIS_HSCROLL
axes. See
getAxisValue(int)
for information
about retrieving these additional axes.
On trackball devices with source class
SOURCE_CLASS_TRACKBALL
,
the pointer coordinates specify relative movements as X/Y deltas.
A trackball gesture consists of a sequence of movements described by motion
events with
ACTION_MOVE
interspersed with occasional
ACTION_DOWN
or
ACTION_UP
motion events when the trackball button is pressed or released.
On joystick devices with source class
SOURCE_CLASS_JOYSTICK
,
the pointer coordinates specify the absolute position of the joystick axes.
The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
to the center position. More information about the set of available axes and the
range of motion can be obtained using
getMotionRange(int)
.
Some common joystick axes are
AXIS_X
,
AXIS_Y
,
AXIS_HAT_X
,
AXIS_HAT_Y
,
AXIS_Z
and
AXIS_RZ
.
Refer to
InputDevice
for more information about how different kinds of
input devices and sources represent pointer coordinates.
Motion events are always delivered to views as a consistent stream of events. What constitutes a consistent stream varies depending on the type of device. For touch events, consistency implies that pointers go down one at a time, move around as a group and then go up one at a time or are canceled.
While the framework tries to deliver consistent streams of motion events to
views, it cannot guarantee it. Some events may be dropped or modified by
containing views in the application before they are delivered thereby making
the stream of events inconsistent. Views should always be prepared to
handle
ACTION_CANCEL
and should tolerate anomalous
situations such as receiving a new
ACTION_DOWN
without first having
received an
ACTION_UP
for the prior gesture.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
MotionEvent.PointerCoords | Transfer object for pointer coordinates. | |||||||||
|
MotionEvent.PointerProperties | Transfer object for pointer properties. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ACTION_CANCEL |
Constant for
getActionMasked()
: The current gesture has been aborted.
|
|||||||||
int | ACTION_DOWN |
Constant for
getActionMasked()
: A pressed gesture has started, the
motion contains the initial starting location.
|
|||||||||
int | ACTION_HOVER_ENTER |
Constant for
getActionMasked()
: The pointer is not down but has entered the
boundaries of a window or view.
|
|||||||||
int | ACTION_HOVER_EXIT |
Constant for
getActionMasked()
: The pointer is not down but has exited the
boundaries of a window or view.
|
|||||||||
int | ACTION_HOVER_MOVE |
Constant for
getActionMasked()
: A change happened but the pointer
is not down (unlike
ACTION_MOVE
).
|
|||||||||
int | ACTION_MASK | Bit mask of the parts of the action code that are the action itself. | |||||||||
int | ACTION_MOVE |
Constant for
getActionMasked()
: A change has happened during a
press gesture (between
ACTION_DOWN
and
ACTION_UP
).
|
|||||||||
int | ACTION_OUTSIDE |
Constant for
getActionMasked()
: A movement has happened outside of the
normal bounds of the UI element.
|
|||||||||
int | ACTION_POINTER_1_DOWN |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
|
|||||||||
int | ACTION_POINTER_1_UP |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
|
|||||||||
int | ACTION_POINTER_2_DOWN |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
|
|||||||||
int | ACTION_POINTER_2_UP |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
|
|||||||||
int | ACTION_POINTER_3_DOWN |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
|
|||||||||
int | ACTION_POINTER_3_UP |
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
|
|||||||||
int | ACTION_POINTER_DOWN |
Constant for
getActionMasked()
: A non-primary pointer has gone down.
|
|||||||||
int | ACTION_POINTER_ID_MASK |
This constant was deprecated
in API level 8.
Renamed to
ACTION_POINTER_INDEX_MASK
to match
the actual data contained in these bits.
|
|||||||||
int | ACTION_POINTER_ID_SHIFT |
This constant was deprecated
in API level 8.
Renamed to
ACTION_POINTER_INDEX_SHIFT
to match
the actual data contained in these bits.
|
|||||||||
int | ACTION_POINTER_INDEX_MASK |
Bits in the action code that represent a pointer index, used with
ACTION_POINTER_DOWN
and
ACTION_POINTER_UP
.
|
|||||||||
int | ACTION_POINTER_INDEX_SHIFT |
Bit shift for the action bits holding the pointer index as
defined by
ACTION_POINTER_INDEX_MASK
.
|
|||||||||
int | ACTION_POINTER_UP |
Constant for
getActionMasked()
: A non-primary pointer has gone up.
|
|||||||||
int | ACTION_SCROLL |
Constant for
getActionMasked()
: The motion event contains relative
vertical and/or horizontal scroll offsets.
|
|||||||||
int | ACTION_UP |
Constant for
getActionMasked()
: A pressed gesture has finished, the
motion contains the final release location as well as any intermediate
points since the last down or move event.
|
|||||||||
int | AXIS_BRAKE | Axis constant: Brake axis of a motion event. | |||||||||
int | AXIS_DISTANCE | Axis constant: Distance axis of a motion event. | |||||||||
int | AXIS_GAS | Axis constant: Gas axis of a motion event. | |||||||||
int | AXIS_GENERIC_1 | Axis constant: Generic 1 axis of a motion event. | |||||||||
int | AXIS_GENERIC_10 | Axis constant: Generic 10 axis of a motion event. | |||||||||
int | AXIS_GENERIC_11 | Axis constant: Generic 11 axis of a motion event. | |||||||||
int | AXIS_GENERIC_12 | Axis constant: Generic 12 axis of a motion event. | |||||||||
int | AXIS_GENERIC_13 | Axis constant: Generic 13 axis of a motion event. | |||||||||
int | AXIS_GENERIC_14 | Axis constant: Generic 14 axis of a motion event. | |||||||||
int | AXIS_GENERIC_15 | Axis constant: Generic 15 axis of a motion event. | |||||||||
int | AXIS_GENERIC_16 | Axis constant: Generic 16 axis of a motion event. | |||||||||
int | AXIS_GENERIC_2 | Axis constant: Generic 2 axis of a motion event. | |||||||||
int | AXIS_GENERIC_3 | Axis constant: Generic 3 axis of a motion event. | |||||||||
int | AXIS_GENERIC_4 | Axis constant: Generic 4 axis of a motion event. | |||||||||
int | AXIS_GENERIC_5 | Axis constant: Generic 5 axis of a motion event. | |||||||||
int | AXIS_GENERIC_6 | Axis constant: Generic 6 axis of a motion event. | |||||||||
int | AXIS_GENERIC_7 | Axis constant: Generic 7 axis of a motion event. | |||||||||
int | AXIS_GENERIC_8 | Axis constant: Generic 8 axis of a motion event. | |||||||||
int | AXIS_GENERIC_9 | Axis constant: Generic 9 axis of a motion event. | |||||||||
int | AXIS_HAT_X | Axis constant: Hat X axis of a motion event. | |||||||||
int | AXIS_HAT_Y | Axis constant: Hat Y axis of a motion event. | |||||||||
int | AXIS_HSCROLL | Axis constant: Horizontal Scroll axis of a motion event. | |||||||||
int | AXIS_LTRIGGER | Axis constant: Left Trigger axis of a motion event. | |||||||||
int | AXIS_ORIENTATION | Axis constant: Orientation axis of a motion event. | |||||||||
int | AXIS_PRESSURE | Axis constant: Pressure axis of a motion event. | |||||||||
int | AXIS_RTRIGGER | Axis constant: Right Trigger axis of a motion event. | |||||||||
int | AXIS_RUDDER | Axis constant: Rudder axis of a motion event. | |||||||||
int | AXIS_RX | Axis constant: X Rotation axis of a motion event. | |||||||||
int | AXIS_RY | Axis constant: Y Rotation axis of a motion event. | |||||||||
int | AXIS_RZ | Axis constant: Z Rotation axis of a motion event. | |||||||||
int | AXIS_SIZE | Axis constant: Size axis of a motion event. | |||||||||
int | AXIS_THROTTLE | Axis constant: Throttle axis of a motion event. | |||||||||
int | AXIS_TILT | Axis constant: Tilt axis of a motion event. | |||||||||
int | AXIS_TOOL_MAJOR | Axis constant: ToolMajor axis of a motion event. | |||||||||
int | AXIS_TOOL_MINOR | Axis constant: ToolMinor axis of a motion event. | |||||||||
int | AXIS_TOUCH_MAJOR | Axis constant: TouchMajor axis of a motion event. | |||||||||
int | AXIS_TOUCH_MINOR | Axis constant: TouchMinor axis of a motion event. | |||||||||
int | AXIS_VSCROLL | Axis constant: Vertical Scroll axis of a motion event. | |||||||||
int | AXIS_WHEEL | Axis constant: Wheel axis of a motion event. | |||||||||
int | AXIS_X | Axis constant: X axis of a motion event. | |||||||||
int | AXIS_Y | Axis constant: Y axis of a motion event. | |||||||||
int | AXIS_Z | Axis constant: Z axis of a motion event. | |||||||||
int | BUTTON_BACK | Button constant: Back button pressed (mouse back button). | |||||||||
int | BUTTON_FORWARD | Button constant: Forward button pressed (mouse forward button). | |||||||||
int | BUTTON_PRIMARY | Button constant: Primary button (left mouse button). | |||||||||
int | BUTTON_SECONDARY | Button constant: Secondary button (right mouse button, stylus first button). | |||||||||
int | BUTTON_TERTIARY | Button constant: Tertiary button (middle mouse button, stylus second button). | |||||||||
int | EDGE_BOTTOM | Flag indicating the motion event intersected the bottom edge of the screen. | |||||||||
int | EDGE_LEFT | Flag indicating the motion event intersected the left edge of the screen. | |||||||||
int | EDGE_RIGHT | Flag indicating the motion event intersected the right edge of the screen. | |||||||||
int | EDGE_TOP | Flag indicating the motion event intersected the top edge of the screen. | |||||||||
int | FLAG_WINDOW_IS_OBSCURED | This flag indicates that the window that received this motion event is partly or wholly obscured by another visible window above it. | |||||||||
int | INVALID_POINTER_ID | An invalid pointer id. | |||||||||
int | TOOL_TYPE_ERASER | Tool type constant: The tool is an eraser or a stylus being used in an inverted posture. | |||||||||
int | TOOL_TYPE_FINGER | Tool type constant: The tool is a finger. | |||||||||
int | TOOL_TYPE_MOUSE | Tool type constant: The tool is a mouse or trackpad. | |||||||||
int | TOOL_TYPE_STYLUS | Tool type constant: The tool is a stylus. | |||||||||
int | TOOL_TYPE_UNKNOWN | Tool type constant: Unknown tool type. |
[Expand]
Inherited Constants
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
CREATOR |
[Expand]
Inherited Fields
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.InputEvent
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
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.
|
||||||||||
|
Add a new movement to the batch of movements in this event.
|
||||||||||
|
Add a new movement to the batch of movements in this event.
|
||||||||||
|
Gets an axis by its symbolic name such as "AXIS_X" or an
equivalent numeric constant such as "42".
|
||||||||||
|
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.
|
||||||||||
|
Given a pointer identifier, find the index of its data in the event.
|
||||||||||
|
Return the kind of action being performed.
|
||||||||||
|
For
ACTION_POINTER_DOWN
or
ACTION_POINTER_UP
as returned by
getActionMasked()
, this returns the associated
pointer index.
|
||||||||||
|
Return the masked action being performed, without pointer index information.
|
||||||||||
|
getAxisValue(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the value of the requested axis for the given pointer
index
(use
getPointerId(int)
to find the pointer identifier for this index).
|
||||||||||
|
Gets the state of all buttons that are pressed such as a mouse or stylus button.
|
||||||||||
|
Gets the id for the device that this event came from.
|
||||||||||
|
Returns the time (in ms) when the user originally pressed down to start
a stream of position events.
|
||||||||||
|
Returns a bitfield indicating which edges, if any, were touched by this
MotionEvent.
|
||||||||||
|
Retrieve the time this event occurred,
in the
uptimeMillis()
time base.
|
||||||||||
|
Gets the motion event flags.
|
||||||||||
|
Returns the historical value of the requested axis, as per
getAxisValue(int, int)
,
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalAxisValue(int, int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the time that a historical movement occurred between this event
and the previous event, in the
uptimeMillis()
time base.
|
||||||||||
|
Returns a historical orientation coordinate, as per
getOrientation(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalOrientation(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Populates a
MotionEvent.PointerCoords
object with historical pointer coordinate data,
as per
getPointerCoords(int, MotionEvent.PointerCoords)
, that occurred between this event and the previous
event for the given pointer.
|
||||||||||
|
getHistoricalPressure(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical pressure coordinate, as per
getPressure(int)
,
that occurred between this event and the previous event for the given
pointer.
|
||||||||||
|
getHistoricalSize(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical size coordinate, as per
getSize(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
Returns a historical tool major axis coordinate, as per
getToolMajor(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalToolMajor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical tool minor axis coordinate, as per
getToolMinor(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalToolMinor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical touch major axis coordinate, as per
getTouchMajor(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalTouchMajor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical touch minor axis coordinate, as per
getTouchMinor(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalTouchMinor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
getHistoricalX(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical X coordinate, as per
getX(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
getHistoricalY(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns a historical Y coordinate, as per
getY(int)
, that
occurred between this event and the previous event for the given pointer.
|
||||||||||
|
Returns the number of historical points in this event.
|
||||||||||
|
Returns the state of any meta / modifier keys that were in effect when
the event was generated.
|
||||||||||
|
Returns the orientation of the touch area and tool area in radians clockwise from vertical
for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getOrientation(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Populates a
MotionEvent.PointerCoords
object with pointer coordinate data for
the specified pointer index.
|
||||||||||
|
The number of pointers of data contained in this event.
|
||||||||||
|
Return the pointer identifier associated with a particular pointer
data index is this event.
|
||||||||||
|
Populates a
MotionEvent.PointerProperties
object with pointer properties for
the specified pointer index.
|
||||||||||
|
getPressure(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the current pressure of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
Returns the original raw X coordinate of this event.
|
||||||||||
|
Returns the original raw Y coordinate of this event.
|
||||||||||
|
Returns a scaled value of the approximate size for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getSize(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Gets the source of the event.
|
||||||||||
|
Returns the length of the major axis of an ellipse that describes the size of
the approaching tool for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getToolMajor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
getToolMinor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the length of the minor axis of an ellipse that describes the size of
the approaching tool for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
Gets the tool type of a pointer for the given pointer index.
|
||||||||||
|
getTouchMajor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the length of the major axis of an ellipse that describes the touch
area at the point of contact for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getTouchMinor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Returns the length of the minor axis of an ellipse that describes the touch
area at the point of contact for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
Returns the X coordinate of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getX(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Return the precision of the X coordinates being reported.
|
||||||||||
|
Returns the Y coordinate of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
|
||||||||||
|
getY(int)
for the first pointer index (may be an
arbitrary pointer identifier).
|
||||||||||
|
Return the precision of the Y coordinates being reported.
|
||||||||||
|
Create a new MotionEvent, filling in all of the basic values that
define the motion.
|
||||||||||
|
Create a new MotionEvent, filling in all of the basic values that
define the motion.
|
||||||||||
|
This method was deprecated
in API level 9.
Use
obtain(long, long, int, float, float, float, float, int, float, float, int, int)
instead.
|
||||||||||
|
This method was deprecated
in API level 14.
Use
obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)
instead.
|
||||||||||
|
Create a new MotionEvent, copying from an existing one.
|
||||||||||
|
Create a new MotionEvent, filling in a subset of the basic motion
values.
|
||||||||||
|
Create a new MotionEvent, copying from an existing one, but not including
any historical point information.
|
||||||||||
|
Adjust this event's location.
|
||||||||||
|
Recycle the MotionEvent, to be re-used by a later caller.
|
||||||||||
|
Sets this event's action.
|
||||||||||
|
Sets the bitfield indicating which edges, if any, were touched by this
MotionEvent.
|
||||||||||
|
Set this event's location.
|
||||||||||
|
Modifies the source of the event.
|
||||||||||
|
Returns a string containing a concise, human-readable description of this
object.
|
||||||||||
|
Applies a transformation matrix to all of the points in the event.
|
||||||||||
|
Flatten this object in to a Parcel.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.InputEvent
|
|||||||||||
From class
java.lang.Object
|
|||||||||||
From interface
android.os.Parcelable
|
Constant for
getActionMasked()
: The current gesture has been aborted.
You will not receive any more points in it. You should treat this as
an up event, but not perform any action that you normally would.
Constant for
getActionMasked()
: A pressed gesture has started, the
motion contains the initial starting location.
This is also a good time to check the button state to distinguish
secondary and tertiary button clicks and handle them appropriately.
Use
getButtonState()
to retrieve the button state.
Constant for
getActionMasked()
: The pointer is not down but has entered the
boundaries of a window or view.
This action is always delivered to the window or view under the pointer.
This action is not a touch event so it is delivered to
onGenericMotionEvent(MotionEvent)
rather than
onTouchEvent(MotionEvent)
.
Constant for
getActionMasked()
: The pointer is not down but has exited the
boundaries of a window or view.
This action is always delivered to the window or view that was previously under the pointer.
This action is not a touch event so it is delivered to
onGenericMotionEvent(MotionEvent)
rather than
onTouchEvent(MotionEvent)
.
Constant for
getActionMasked()
: A change happened but the pointer
is not down (unlike
ACTION_MOVE
). The motion contains the most
recent point, as well as any intermediate points since the last
hover move event.
This action is always delivered to the window or view under the pointer.
This action is not a touch event so it is delivered to
onGenericMotionEvent(MotionEvent)
rather than
onTouchEvent(MotionEvent)
.
Bit mask of the parts of the action code that are the action itself.
Constant for
getActionMasked()
: A change has happened during a
press gesture (between
ACTION_DOWN
and
ACTION_UP
).
The motion contains the most recent point, as well as any intermediate
points since the last down or move event.
Constant for
getActionMasked()
: A movement has happened outside of the
normal bounds of the UI element. This does not provide a full gesture,
but only the initial location of the movement/touch.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_DOWN
.
This constant was deprecated
in API level 8.
Use
ACTION_POINTER_INDEX_MASK
to retrieve the
data index associated with
ACTION_POINTER_UP
.
Constant for
getActionMasked()
: A non-primary pointer has gone down.
Use
getActionIndex()
to retrieve the index of the pointer that changed.
The index is encoded in the
ACTION_POINTER_INDEX_MASK
bits of the
unmasked action returned by
getAction()
.
This constant was deprecated
in API level 8.
Renamed to
ACTION_POINTER_INDEX_MASK
to match
the actual data contained in these bits.
This constant was deprecated
in API level 8.
Renamed to
ACTION_POINTER_INDEX_SHIFT
to match
the actual data contained in these bits.
Bits in the action code that represent a pointer index, used with
ACTION_POINTER_DOWN
and
ACTION_POINTER_UP
. Shifting
down by
ACTION_POINTER_INDEX_SHIFT
provides the actual pointer
index where the data for the pointer going up or down can be found; you can
get its identifier with
getPointerId(int)
and the actual
data with
getX(int)
etc.
Bit shift for the action bits holding the pointer index as
defined by
ACTION_POINTER_INDEX_MASK
.
Constant for
getActionMasked()
: A non-primary pointer has gone up.
Use
getActionIndex()
to retrieve the index of the pointer that changed.
The index is encoded in the
ACTION_POINTER_INDEX_MASK
bits of the
unmasked action returned by
getAction()
.
Constant for
getActionMasked()
: The motion event contains relative
vertical and/or horizontal scroll offsets. Use
getAxisValue(int)
to retrieve the information from
AXIS_VSCROLL
and
AXIS_HSCROLL
.
The pointer may or may not be down when this event is dispatched.
This action is always delivered to the window or view under the pointer, which may not be the window or view currently touched.
This action is not a touch event so it is delivered to
onGenericMotionEvent(MotionEvent)
rather than
onTouchEvent(MotionEvent)
.
Constant for
getActionMasked()
: A pressed gesture has finished, the
motion contains the final release location as well as any intermediate
points since the last down or move event.
Axis constant: Brake axis of a motion event.
Axis constant: Distance axis of a motion event.
Axis constant: Gas axis of a motion event.
Axis constant: Generic 1 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 10 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 11 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 12 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 13 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 14 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 15 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 16 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 2 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 3 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 4 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 5 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 6 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 7 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 8 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Generic 9 axis of a motion event. The interpretation of a generic axis is device-specific.
Axis constant: Hat X axis of a motion event.
Axis constant: Hat Y axis of a motion event.
Axis constant: Horizontal Scroll axis of a motion event.
This axis should be used to scroll views horizontally.
Axis constant: Left Trigger axis of a motion event.
Axis constant: Orientation axis of a motion event.
AXIS_TILT
.
Axis constant: Pressure axis of a motion event.
Axis constant: Right Trigger axis of a motion event.
Axis constant: Rudder axis of a motion event.
Axis constant: X Rotation axis of a motion event.
Axis constant: Y Rotation axis of a motion event.
Axis constant: Z Rotation axis of a motion event.
Axis constant: Size axis of a motion event.
AXIS_TOUCH_MAJOR
or
AXIS_TOOL_MAJOR
.
Axis constant: Throttle axis of a motion event.
Axis constant: Tilt axis of a motion event.
Axis constant: ToolMajor axis of a motion event.
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.
Axis constant: ToolMinor axis of a motion event.
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.
Axis constant: TouchMajor axis of a motion event.
getMotionRange(int)
to query the effective range of values.
Axis constant: TouchMinor axis of a motion event.
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.
Axis constant: Vertical Scroll axis of a motion event.
This axis should be used to scroll views vertically.
Axis constant: Wheel axis of a motion event.
Axis constant: X axis of a motion event.
getMotionRange(int)
to query the effective range of values.
Axis constant: Y axis of a motion event.
getMotionRange(int)
to query the effective range of values.
Axis constant: Z axis of a motion event.
Button constant: Back button pressed (mouse back button).
The system may send a
KEYCODE_BACK
key press to the application
when this button is pressed.
Button constant: Forward button pressed (mouse forward button).
The system may send a
KEYCODE_FORWARD
key press to the application
when this button is pressed.
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.
Button constant: Secondary button (right mouse button, stylus first button).
Button constant: Tertiary button (middle mouse button, stylus second button).
Flag indicating the motion event intersected the bottom edge of the screen.
Flag indicating the motion event intersected the left edge of the screen.
Flag indicating the motion event intersected the right edge of the screen.
Flag indicating the motion event intersected the top edge of the screen.
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.
An invalid pointer id.
This value (-1) can be used as a placeholder to indicate that a pointer id
has not been assigned or is not available. It cannot appear as
a pointer id inside a
MotionEvent
.
Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Tool type constant: The tool is a mouse or trackpad.
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.
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.
action | The unmasked action. |
---|
Add a new movement to the batch of movements in this event. The event's
current location, position and size is updated to the new values.
The current values in the event are added to a list of historical values.
Only applies to
ACTION_MOVE
or
ACTION_HOVER_MOVE
events.
eventTime | The time stamp (in ms) for this data. |
---|---|
pointerCoords | The new pointer coordinates. |
metaState | Meta key state. |
Add a new movement to the batch of movements in this event. The event's
current location, position and size is updated to the new values.
The current values in the event are added to a list of historical values.
Only applies to
ACTION_MOVE
or
ACTION_HOVER_MOVE
events.
eventTime | The time stamp (in ms) for this data. |
---|---|
x | The new X position. |
y | The new Y position. |
pressure | The new pressure. |
size | The new size. |
metaState | Meta key state. |
Gets an axis by its symbolic name such as "AXIS_X" or an equivalent numeric constant such as "42".
symbolicName | The symbolic name of the 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.
axis | The axis. |
---|
Given a pointer identifier, find the index of its data in the event.
pointerId | The identifier of the pointer to be found. |
---|
getX(int)
et al.), or -1 if there is no data available for
that pointer identifier.
Return the kind of action being performed.
Consider using
getActionMasked()
and
getActionIndex()
to retrieve
the separate masked action and pointer index.
ACTION_DOWN
or
the combination of
ACTION_POINTER_DOWN
with a shifted pointer index.
For
ACTION_POINTER_DOWN
or
ACTION_POINTER_UP
as returned by
getActionMasked()
, this returns the associated
pointer index.
The index may be used with
getPointerId(int)
,
getX(int)
,
getY(int)
,
getPressure(int)
,
and
getSize(int)
to get information about the pointer that has
gone down or up.
Return the masked action being performed, without pointer index information.
Use
getActionIndex()
to return the index associated with pointer actions.
ACTION_DOWN
or
ACTION_POINTER_DOWN
.
getAxisValue(int)
for the first pointer index (may be an
arbitrary pointer identifier).
axis | The axis identifier for the axis value to retrieve. |
---|
Returns the value of the requested axis for the given pointer
index
(use
getPointerId(int)
to find the pointer identifier for this index).
axis | The axis identifier for the axis value to retrieve. |
---|---|
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
Gets the state of all buttons that are pressed such as a mouse or stylus button.
Gets the id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device and maps to the default keymap. The other numbers are arbitrary and you shouldn't depend on the values.
Returns the time (in ms) when the user originally pressed down to start a stream of position events.
Returns a bitfield indicating which edges, if any, were touched by this
MotionEvent. For touch events, clients can use this to determine if the
user's finger was touching the edge of the display.
This property is only set for
ACTION_DOWN
events.
Retrieve the time this event occurred,
in the
uptimeMillis()
time base.
uptimeMillis()
time base.
Returns the historical value of the requested axis, as per
getAxisValue(int, int)
,
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
axis | The axis identifier for the axis value to retrieve. |
---|---|
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalAxisValue(int, int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
axis | The axis identifier for the axis value to retrieve. |
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
Returns the time that a historical movement occurred between this event
and the previous event, in the
uptimeMillis()
time base.
This only applies to ACTION_MOVE events.
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
uptimeMillis()
time base.
Returns a historical orientation coordinate, as per
getOrientation(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalOrientation(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Populates a
MotionEvent.PointerCoords
object with historical pointer coordinate data,
as per
getPointerCoords(int, MotionEvent.PointerCoords)
, that occurred between this event and the previous
event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
outPointerCoords | The pointer coordinate object to populate. |
getHistoricalPressure(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical pressure coordinate, as per
getPressure(int)
,
that occurred between this event and the previous event for the given
pointer. Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalSize(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical size coordinate, as per
getSize(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
Returns a historical tool major axis coordinate, as per
getToolMajor(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalToolMajor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical tool minor axis coordinate, as per
getToolMinor(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalToolMinor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical touch major axis coordinate, as per
getTouchMajor(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalTouchMajor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical touch minor axis coordinate, as per
getTouchMinor(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalTouchMinor(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
getHistoricalX(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical X coordinate, as per
getX(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
getHistoricalY(int, int)
for the first pointer index (may be an
arbitrary pointer identifier).
pos |
Which historical value to return; must be less than
getHistorySize()
|
---|
Returns a historical Y coordinate, as per
getY(int)
, that
occurred between this event and the previous event for the given pointer.
Only applies to ACTION_MOVE events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
pos |
Which historical value to return; must be less than
getHistorySize()
|
Returns the number of historical points in this event. These are movements that have occurred between this event and the previous event. This only applies to ACTION_MOVE events -- all other actions will have a size of 0.
Returns the state of any meta / modifier keys that were in effect when
the event was generated. This is the same values as those
returned by
KeyEvent.getMetaState
.
Returns the orientation of the touch area and tool area in radians clockwise from vertical
for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
An angle of 0 radians indicates that the major axis of contact is oriented
upwards, is perfectly circular or is of unknown orientation. A positive angle
indicates that the major axis of contact is oriented to the right. A negative angle
indicates that the major axis of contact is oriented to the left.
The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
(finger pointing fully right).
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
getOrientation(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Populates a
MotionEvent.PointerCoords
object with pointer coordinate data for
the specified pointer index.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
outPointerCoords | The pointer coordinate object to populate. |
The number of pointers of data contained in this event. Always >= 1.
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.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
Populates a
MotionEvent.PointerProperties
object with pointer properties for
the specified pointer index.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|---|
outPointerProperties | The pointer properties object to populate. |
getPressure(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Returns the current pressure of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
The pressure generally
ranges from 0 (no pressure at all) to 1 (normal pressure), however
values higher than 1 may be generated depending on the calibration of
the input device.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
Returns a scaled value of the approximate size for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
This represents some approximation of the area of the screen being
pressed; the actual value in pixels corresponding to the
touch is normalized with the device specific range of values
and scaled to a value between 0 and 1. The value of size can be used to
determine fat touch events.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
getSize(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Gets the source of the event.
SOURCE_UNKNOWN
if unknown.
Returns the length of the major axis of an ellipse that describes the size of
the approaching tool for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
The tool area represents the estimated size of the finger or pen that is
touching the device independent of its actual touch area at the point of contact.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
getToolMajor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
getToolMinor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Returns the length of the minor axis of an ellipse that describes the size of
the approaching tool for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
The tool area represents the estimated size of the finger or pen that is
touching the device independent of its actual touch area at the point of contact.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
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.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
getTouchMajor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Returns the length of the major axis of an ellipse that describes the touch
area at the point of contact for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
getTouchMinor(int)
for the first pointer index (may be an
arbitrary pointer identifier).
Returns the length of the minor axis of an ellipse that describes the touch
area at the point of contact for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
Returns the X coordinate of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
Returns the Y coordinate of this event for the given pointer
index
(use
getPointerId(int)
to find the pointer
identifier for this index).
Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
pointerIndex |
Raw index of pointer to retrieve. Value may be from 0
(the first pointer that is down) to
getPointerCount()
-1.
|
---|
Create a new MotionEvent, filling in all of the basic values that define the motion.
downTime |
The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from
uptimeMillis()
.
|
---|---|
eventTime |
The the time (in ms) when this specific event was generated. This
must be obtained from
uptimeMillis()
.
|
action |
The kind of action being performed, such as
ACTION_DOWN
.
|
pointerCount | The number of pointers that will be in this event. |
pointerProperties |
An array of
pointerCount
values providing
a
MotionEvent.PointerProperties
property object for each pointer, which must
include the pointer identifier.
|
pointerCoords |
An array of
pointerCount
values providing
a
MotionEvent.PointerCoords
coordinate object for each pointer.
|
metaState | The state of any meta / modifier keys that were in effect when the event was generated. |
buttonState | The state of buttons that are pressed. |
xPrecision | The precision of the X coordinate being reported. |
yPrecision | The precision of the Y coordinate being reported. |
deviceId | The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values. |
edgeFlags | A bitfield indicating which edges, if any, were touched by this MotionEvent. |
source | The source of this event. |
flags | The motion event flags. |
Create a new MotionEvent, filling in all of the basic values that define the motion.
downTime |
The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from
uptimeMillis()
.
|
---|---|
eventTime |
The the time (in ms) when this specific event was generated. This
must be obtained from
uptimeMillis()
.
|
action |
The kind of action being performed, such as
ACTION_DOWN
.
|
x | The X coordinate of this event. |
y | The Y coordinate of this event. |
pressure | The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device. |
size | A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1. |
metaState | The state of any meta / modifier keys that were in effect when the event was generated. |
xPrecision | The precision of the X coordinate being reported. |
yPrecision | The precision of the Y coordinate being reported. |
deviceId | The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values. |
edgeFlags | A bitfield indicating which edges, if any, were touched by this MotionEvent. |
This method was deprecated
in API level 9.
Use
obtain(long, long, int, float, float, float, float, int, float, float, int, int)
instead.
Create a new MotionEvent, filling in all of the basic values that define the motion.
downTime |
The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from
uptimeMillis()
.
|
---|---|
eventTime |
The the time (in ms) when this specific event was generated. This
must be obtained from
uptimeMillis()
.
|
action |
The kind of action being performed, such as
ACTION_DOWN
.
|
pointerCount | The number of pointers that are active in this event. |
x | The X coordinate of this event. |
y | The Y coordinate of this event. |
pressure | The current pressure of this event. The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device. |
size | A scaled value of the approximate size of the area being pressed when touched with the finger. The actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1. |
metaState | The state of any meta / modifier keys that were in effect when the event was generated. |
xPrecision | The precision of the X coordinate being reported. |
yPrecision | The precision of the Y coordinate being reported. |
deviceId | The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values. |
edgeFlags | A bitfield indicating which edges, if any, were touched by this MotionEvent. |
This method was deprecated
in API level 14.
Use
obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)
instead.
Create a new MotionEvent, filling in all of the basic values that define the motion.
downTime |
The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from
uptimeMillis()
.
|
---|---|
eventTime |
The the time (in ms) when this specific event was generated. This
must be obtained from
uptimeMillis()
.
|
action |
The kind of action being performed, such as
ACTION_DOWN
.
|
pointerCount | The number of pointers that will be in this event. |
pointerIds | An array of pointerCount values providing an identifier for each pointer. |
pointerCoords |
An array of
pointerCount
values providing
a
MotionEvent.PointerCoords
coordinate object for each pointer.
|
metaState | The state of any meta / modifier keys that were in effect when the event was generated. |
xPrecision | The precision of the X coordinate being reported. |
yPrecision | The precision of the Y coordinate being reported. |
deviceId | The id for the device that this event came from. An id of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values. |
edgeFlags | A bitfield indicating which edges, if any, were touched by this MotionEvent. |
source | The source of this event. |
flags | The motion event flags. |
Create a new MotionEvent, copying from an existing one.
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).
downTime |
The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from
uptimeMillis()
.
|
---|---|
eventTime |
The the time (in ms) when this specific event was generated. This
must be obtained from
uptimeMillis()
.
|
action |
The kind of action being performed, such as
ACTION_DOWN
.
|
x | The X coordinate of this event. |
y | The Y coordinate of this event. |
metaState | The state of any meta / modifier keys that were in effect when the event was generated. |
Create a new MotionEvent, copying from an existing one, but not including any historical point information.
Adjust this event's location.
deltaX | Amount to add to the current X coordinate of the event. |
---|---|
deltaY | Amount to add to the current Y coordinate of the event. |
Recycle the MotionEvent, to be re-used by a later caller. After calling this function you must not ever touch the event again.
Sets the bitfield indicating which edges, if any, were touched by this MotionEvent.
Set this event's location. Applies
offsetLocation(float, float)
with a
delta from the current location to the given new location.
x | New absolute X location. |
---|---|
y | New absolute Y location. |
Modifies the source of the event.
source | The new source. |
---|
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See
Writing a useful
toString
method
if you intend implementing your own
toString
method.
Applies a transformation matrix to all of the points in the event.
matrix | The transformation matrix to apply. |
---|
Flatten this object in to a Parcel.
out | The Parcel in which the object should be written. |
---|---|
flags |
Additional flags about how the object should be written.
May be 0 or
PARCELABLE_WRITE_RETURN_VALUE
.
|
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override
finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit
close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a
BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you
must
use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling
super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|