Build 1.0_r1(from source)

android.view
Class VelocityTracker

java.lang.Object
  extended by android.view.VelocityTracker

public final class VelocityTracker
extends Object

Helper for tracking the velocity of touch events, for implementing flinging and other such gestures. Use obtain() to retrieve a new instance of the class when you are going to begin tracking, put the motion events you receive into it with addMovement(MotionEvent), and when you want to determine the velocity call computeCurrentVelocity(int) and then getXVelocity() and getXVelocity().


Field Summary
(package private) static boolean DEBUG
           
(package private) static boolean localLOGV
           
(package private) static int LONGEST_PAST_TIME
           
(package private)  long[] mPastTime
           
(package private)  float[] mPastX
           
(package private)  float[] mPastY
           
(package private) static VelocityTracker[] mPool
           
(package private)  float mXVelocity
           
(package private)  float mYVelocity
           
(package private) static int NUM_PAST
           
(package private) static String TAG
           
 
Method Summary
 void addMovement(MotionEvent ev)
          Add a user's movement to the tracker.
 void clear()
          Reset the velocity tracker back to its initial state.
 void computeCurrentVelocity(int units)
          Compute the current velocity based on the points that have been collected.
 float getXVelocity()
          Retrieve the last computed X velocity.
 float getYVelocity()
          Retrieve the last computed Y velocity.
static VelocityTracker obtain()
          Retrieve a new VelocityTracker object to watch the velocity of a motion.
 void recycle()
          Return a VelocityTracker object back to be re-used by others.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

static final String TAG
See Also:
Constant Field Values

DEBUG

static final boolean DEBUG
See Also:
Constant Field Values

localLOGV

static final boolean localLOGV
See Also:
Constant Field Values

NUM_PAST

static final int NUM_PAST
See Also:
Constant Field Values

LONGEST_PAST_TIME

static final int LONGEST_PAST_TIME
See Also:
Constant Field Values

mPool

static final VelocityTracker[] mPool

mPastX

final float[] mPastX

mPastY

final float[] mPastY

mPastTime

final long[] mPastTime

mYVelocity

float mYVelocity

mXVelocity

float mXVelocity
Method Detail

obtain

public static VelocityTracker obtain()
Retrieve a new VelocityTracker object to watch the velocity of a motion. Be sure to call recycle() when done. You should generally only maintain an active object while tracking a movement, so that the VelocityTracker can be re-used elsewhere.

Returns:
Returns a new VelocityTracker.

recycle

public void recycle()
Return a VelocityTracker object back to be re-used by others. You must not touch the object after calling this function.


clear

public void clear()
Reset the velocity tracker back to its initial state.


addMovement

public void addMovement(MotionEvent ev)
Add a user's movement to the tracker. You should call this for the initial MotionEvent.ACTION_DOWN, the following MotionEvent.ACTION_MOVE events that you receive, and the final MotionEvent.ACTION_UP. You can, however, call this for whichever events you desire.

Parameters:
ev - The MotionEvent you received and would like to track.

computeCurrentVelocity

public void computeCurrentVelocity(int units)
Compute the current velocity based on the points that have been collected. Only call this when you actually want to retrieve velocity information, as it is relatively expensive. You can then retrieve the velocity with getXVelocity() and getYVelocity().

Parameters:
units - The units you would like the velocity in. A value of 1 provides pixels per millisecond, 1000 provides pixels per second, etc.

getXVelocity

public float getXVelocity()
Retrieve the last computed X velocity. You must first call computeCurrentVelocity(int) before calling this function.

Returns:
The previously computed X velocity.

getYVelocity

public float getYVelocity()
Retrieve the last computed Y velocity. You must first call computeCurrentVelocity(int) before calling this function.

Returns:
The previously computed Y velocity.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature