android.view
public
final
class
android.view.MotionEvent
Object used to report movement (mouse, pen, finger, trackball) events. This
class may hold either absolute or relative movements, depending on what
it is being used for.
Summary
Constants
|
|
|
Value |
|
int |
ACTION_CANCEL |
|
3 |
0x00000003 |
int |
ACTION_DOWN |
|
0 |
0x00000000 |
int |
ACTION_MOVE |
|
2 |
0x00000002 |
int |
ACTION_UP |
|
1 |
0x00000001 |
Creator<MotionEvent> |
CREATOR |
|
|
|
int |
EDGE_BOTTOM |
Flag indicating the motion event intersected the bottom edge of the screen. |
2 |
0x00000002 |
int |
EDGE_LEFT |
Flag indicating the motion event intersected the left edge of the screen. |
4 |
0x00000004 |
int |
EDGE_RIGHT |
Flag indicating the motion event intersected the right edge of the screen. |
8 |
0x00000008 |
int |
EDGE_TOP |
Flag indicating the motion event intersected the top edge of the screen. |
1 |
0x00000001 |
Public Methods
|
|
final |
|
|
void |
addBatch(long eventTime, float x, float y, float pressure, float size, int metaState) |
|
|
|
|
|
int |
describeContents() |
|
|
final |
|
|
int |
getAction() |
|
|
final |
|
|
int |
getDeviceId() |
|
|
final |
|
|
long |
getDownTime() |
|
|
final |
|
|
int |
getEdgeFlags() |
|
|
final |
|
|
long |
getEventTime() |
|
|
final |
|
|
long |
getHistoricalEventTime(int pos) |
|
|
final |
|
|
float |
getHistoricalPressure(int pos) |
|
|
final |
|
|
float |
getHistoricalSize(int pos) |
|
|
final |
|
|
float |
getHistoricalX(int pos) |
|
|
final |
|
|
float |
getHistoricalY(int pos) |
|
|
final |
|
|
int |
getHistorySize() |
|
|
final |
|
|
int |
getMetaState() |
|
|
final |
|
|
float |
getPressure() |
|
|
final |
|
|
float |
getRawX() |
|
|
final |
|
|
float |
getRawY() |
|
|
final |
|
|
float |
getSize() |
|
|
final |
|
|
float |
getX() |
|
|
final |
|
|
float |
getXPrecision() |
|
|
final |
|
|
float |
getY() |
|
|
final |
|
|
float |
getYPrecision() |
|
|
|
static |
|
MotionEvent |
obtain(MotionEvent o) |
|
|
|
static |
|
MotionEvent |
obtain(long downTime, long eventTime, int action, float x, float y, int metaState) |
|
|
|
static |
|
MotionEvent |
obtain(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags) |
|
|
final |
|
|
void |
offsetLocation(float deltaX, float deltaY) |
|
|
|
|
|
void |
recycle() |
|
|
final |
|
|
void |
setAction(int action) |
|
|
final |
|
|
void |
setEdgeFlags(int flags) |
|
|
final |
|
|
void |
setLocation(float x, float y) |
|
|
|
|
|
String |
toString() |
|
|
|
|
|
void |
writeToParcel(Parcel out, int flags) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
ACTION_CANCEL
Constant Value:
3
(0x00000003)
public
static
final
int
ACTION_DOWN
Constant Value:
0
(0x00000000)
public
static
final
int
ACTION_MOVE
Constant Value:
2
(0x00000002)
public
static
final
int
ACTION_UP
Constant Value:
1
(0x00000001)
public
static
final
int
EDGE_BOTTOM
Flag indicating the motion event intersected the bottom edge of the screen.
Constant Value:
2
(0x00000002)
public
static
final
int
EDGE_LEFT
Flag indicating the motion event intersected the left edge of the screen.
Constant Value:
4
(0x00000004)
public
static
final
int
EDGE_RIGHT
Flag indicating the motion event intersected the right edge of the screen.
Constant Value:
8
(0x00000008)
public
static
final
int
EDGE_TOP
Flag indicating the motion event intersected the top edge of the screen.
Constant Value:
1
(0x00000001)
Public Methods
public
final
void
addBatch(long eventTime, float x, float y, float pressure, float size, int metaState)
Add a new movement to the batch of movements in this event. The event's
current location, position and size is updated to the new values. In
the future, the current values in the event will be added to a list of
historic values.
Parameters
x
| The new X position. |
y
| The new Y position. |
pressure
| The new pressure. |
size
| The new size.
|
public
int
describeContents()
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
public
final
int
getAction()
public
final
int
getDeviceId()
Return 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.
public
final
long
getDownTime()
Returns the time (in ms) when the user originally pressed down to start
a stream of position events.
public
final
int
getEdgeFlags()
Returns a bitfield indicating which edges, if any, where 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.
public
final
long
getEventTime()
Returns the time (in ms) when this specific event was generated.
public
final
long
getHistoricalEventTime(int pos)
Returns the time that a historical movement occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
public
final
float
getHistoricalPressure(int pos)
Returns a historical pressure coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
public
final
float
getHistoricalSize(int pos)
Returns a historical size coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
public
final
float
getHistoricalX(int pos)
Returns a historical X coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
public
final
float
getHistoricalY(int pos)
Returns a historical Y coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
public
final
int
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
- Returns the number of historical points in the event.
public
final
int
getMetaState()
Returns the state of any meta / modifier keys that were in effect when
the event was generated. This is the same values as those
returned by
KeyEvent.getMetaState.
Returns
- an integer in which each bit set to 1 represents a pressed
meta key
public
final
float
getPressure()
Returns 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.
public
final
float
getRawX()
Returns the original raw X coordinate of this event. For touch
events on the screen, this is the original location of the event
on the screen, before it had been adjusted for the containing window
and views.
public
final
float
getRawY()
Returns the original raw Y coordinate of this event. For touch
events on the screen, this is the original location of the event
on the screen, before it had been adjusted for the containing window
and views.
public
final
float
getSize()
Returns 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 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.
public
final
float
getX()
Returns the X coordinate of this event. Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
public
final
float
getXPrecision()
Return the precision of the X coordinates being reported. You can
multiple this number with
getX() to find the actual hardware
value of the X coordinate.
Returns
- Returns the precision of X coordinates being reported.
public
final
float
getY()
Returns the Y coordinate of this event. Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
public
final
float
getYPrecision()
Return the precision of the Y coordinates being reported. You can
multiple this number with
getY() to find the actual hardware
value of the Y coordinate.
Returns
- Returns the precision of Y coordinates being reported.
Create a new MotionEvent, copying from an existing one.
public
static
MotionEvent
obtain(long downTime, long eventTime, int action, float x, float y, int metaState)
Create a new MotionEvent, filling in a subset of the basic motion
values. Those not specified here are: device id (always 0), pressure
and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Parameters
downTime
| The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from uptimeMillis(). |
eventTime
| The the time (in ms) when this specific event was generated. This
must be obtained from uptimeMillis(). |
action
| The kind of action being performed -- one of either
ACTION_DOWN, ACTION_MOVE, ACTION_UP, or
ACTION_CANCEL. |
x
| The X coordinate of this event. |
y
| The Y coordinate of this event. |
metaState
| The state of any meta / modifier keys that were in effect when
the event was generated.
|
public
static
MotionEvent
obtain(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)
Create a new MotionEvent, filling in all of the basic values that
define the motion.
Parameters
downTime
| The time (in ms) when the user originally pressed down to start
a stream of position events. This must be obtained from uptimeMillis(). |
eventTime
| The the time (in ms) when this specific event was generated. This
must be obtained from uptimeMillis(). |
action
| The kind of action being performed -- one of either
ACTION_DOWN, ACTION_MOVE, ACTION_UP, or
ACTION_CANCEL. |
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, where touched by this
MotionEvent.
|
public
final
void
offsetLocation(float deltaX, float deltaY)
Adjust this event's location.
Parameters
deltaX
| Amount to add to the current X coordinate of the event. |
deltaY
| Amount to add to the current Y coordinate of the event.
|
public
void
recycle()
Recycle the MotionEvent, to be re-used by a later caller. After calling
this function you must not ever touch the event again.
public
final
void
setAction(int action)
Sets this event's action.
public
final
void
setEdgeFlags(int flags)
Sets the bitfield indicating which edges, if any, where touched by this
MotionEvent.
public
final
void
setLocation(float x, float y)
Set this event's location. Applies
offsetLocation(float, float) with a
delta from the current location to the given new location.
Parameters
x
| New absolute X location. |
y
| New absolute Y location.
|
public
String
toString()
Returns a string containing a concise, human-readable description of the
receiver.
Returns
- String a printable representation for the receiver.
public
void
writeToParcel(Parcel out, int flags)
Flatten this object in to a Parcel.