Build 1.0_r1(from source)

android.view
Class MotionEvent

java.lang.Object
  extended by android.view.MotionEvent
All Implemented Interfaces:
Parcelable

public final class MotionEvent
extends Object
implements Parcelable

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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.Creator<T>
 
Field Summary
static int ACTION_CANCEL
           
static int ACTION_DOWN
           
static int ACTION_MOVE
           
static int ACTION_UP
           
static Parcelable.Creator<MotionEvent> CREATOR
           
static int EDGE_BOTTOM
          Flag indicating the motion event intersected the bottom edge of the screen.
static int EDGE_LEFT
          Flag indicating the motion event intersected the left edge of the screen.
static int EDGE_RIGHT
          Flag indicating the motion event intersected the right edge of the screen.
static int EDGE_TOP
          Flag indicating the motion event intersected the top edge of the screen.
 
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
 
Method Summary
 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.
 int describeContents()
          Describe the kinds of special objects contained in this Parcelable's marshalled representation.
 int getAction()
          Return the kind of action being performed -- one of either ACTION_DOWN, ACTION_MOVE, ACTION_UP, or ACTION_CANCEL.
 int getDeviceId()
          Return the id for the device that this event came from.
 long getDownTime()
          Returns the time (in ms) when the user originally pressed down to start a stream of position events.
 int getEdgeFlags()
          Returns a bitfield indicating which edges, if any, where touched by this MotionEvent.
 long getEventTime()
          Returns the time (in ms) when this specific event was generated.
 long getHistoricalEventTime(int pos)
          Returns the time that a historical movement occurred between this event and the previous event.
 float getHistoricalPressure(int pos)
          Returns a historical pressure coordinate that occurred between this event and the previous event.
 float getHistoricalSize(int pos)
          Returns a historical size coordinate that occurred between this event and the previous event.
 float getHistoricalX(int pos)
          Returns a historical X coordinate that occurred between this event and the previous event.
 float getHistoricalY(int pos)
          Returns a historical Y coordinate that occurred between this event and the previous event.
 int getHistorySize()
          Returns the number of historical points in this event.
 int getMetaState()
          Returns the state of any meta / modifier keys that were in effect when the event was generated.
 float getPressure()
          Returns the current pressure of this event.
 float getRawX()
          Returns the original raw X coordinate of this event.
 float getRawY()
          Returns the original raw Y coordinate of this event.
 float getSize()
          Returns a scaled value of the approximate size, of the area being pressed when touched with the finger.
 float getX()
          Returns the X coordinate of this event.
 float getXPrecision()
          Return the precision of the X coordinates being reported.
 float getY()
          Returns the Y coordinate of this event.
 float getYPrecision()
          Return the precision of the Y coordinates being reported.
static MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)
          Create a new MotionEvent, filling in all of the basic values that define the motion.
static MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, int metaState)
          Create a new MotionEvent, filling in a subset of the basic motion values.
static MotionEvent obtain(MotionEvent o)
          Create a new MotionEvent, copying from an existing one.
 void offsetLocation(float deltaX, float deltaY)
          Adjust this event's location.
 void recycle()
          Recycle the MotionEvent, to be re-used by a later caller.
 void setAction(int action)
          Sets this event's action.
 void setEdgeFlags(int flags)
          Sets the bitfield indicating which edges, if any, where touched by this MotionEvent.
 void setLocation(float x, float y)
          Set this event's location.
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
 void writeToParcel(Parcel out, int flags)
          Flatten this object in to a Parcel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTION_DOWN

public static final int ACTION_DOWN
See Also:
Constant Field Values

ACTION_UP

public static final int ACTION_UP
See Also:
Constant Field Values

ACTION_MOVE

public static final int ACTION_MOVE
See Also:
Constant Field Values

ACTION_CANCEL

public static final int ACTION_CANCEL
See Also:
Constant Field Values

EDGE_TOP

public static final int EDGE_TOP
Flag indicating the motion event intersected the top edge of the screen.

See Also:
Constant Field Values

EDGE_BOTTOM

public static final int EDGE_BOTTOM
Flag indicating the motion event intersected the bottom edge of the screen.

See Also:
Constant Field Values

EDGE_LEFT

public static final int EDGE_LEFT
Flag indicating the motion event intersected the left edge of the screen.

See Also:
Constant Field Values

EDGE_RIGHT

public static final int EDGE_RIGHT
Flag indicating the motion event intersected the right edge of the screen.

See Also:
Constant Field Values

CREATOR

public static final Parcelable.Creator<MotionEvent> CREATOR
Method Detail

obtain

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 SystemClock.uptimeMillis().
eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.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.

obtain

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 SystemClock.uptimeMillis().
eventTime - The the time (in ms) when this specific event was generated. This must be obtained from SystemClock.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.

obtain

public static MotionEvent obtain(MotionEvent o)
Create a new MotionEvent, copying from an existing one.


recycle

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.


getAction

public final int getAction()
Return the kind of action being performed -- one of either ACTION_DOWN, ACTION_MOVE, ACTION_UP, or ACTION_CANCEL.


getDownTime

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


getEventTime

public final long getEventTime()
Returns the time (in ms) when this specific event was generated.


getX

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.


getY

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.


getPressure

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.


getSize

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.


getMetaState

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
See Also:
KeyEvent.getMetaState()

getRawX

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.


getRawY

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.


getXPrecision

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.

getYPrecision

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.

getHistorySize

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.

getHistoricalEventTime

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.

Parameters:
pos - Which historical value to return; must be less than getHistorySize()
See Also:
getHistorySize(), getEventTime()

getHistoricalX

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.

Parameters:
pos - Which historical value to return; must be less than getHistorySize()
See Also:
getHistorySize(), getX()

getHistoricalY

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.

Parameters:
pos - Which historical value to return; must be less than getHistorySize()
See Also:
getHistorySize(), getY()

getHistoricalPressure

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.

Parameters:
pos - Which historical value to return; must be less than getHistorySize()
See Also:
getHistorySize(), getPressure()

getHistoricalSize

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.

Parameters:
pos - Which historical value to return; must be less than getHistorySize()
See Also:
getHistorySize(), getSize()

getDeviceId

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.


getEdgeFlags

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.

See Also:
EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM

setEdgeFlags

public final void setEdgeFlags(int flags)
Sets the bitfield indicating which edges, if any, where touched by this MotionEvent.

See Also:
getEdgeFlags()

setAction

public final void setAction(int action)
Sets this event's action.


offsetLocation

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.

setLocation

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.

addBatch

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.

toString

public String toString()
Description copied from class: Object
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
String a printable representation for the receiver.

describeContents

public int describeContents()
Description copied from interface: Parcelable
Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Specified by:
describeContents in interface Parcelable
Returns:
a bitmask indicating the set of special object types marshalled by the Parcelable.

writeToParcel

public void writeToParcel(Parcel out,
                          int flags)
Description copied from interface: Parcelable
Flatten this object in to a Parcel.

Specified by:
writeToParcel in interface Parcelable
Parameters:
out - The Parcel in which the object should be written.
flags - Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature