|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.view.VelocityTracker
public final class VelocityTracker
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 |
|---|
static final String TAG
static final boolean DEBUG
static final boolean localLOGV
static final int NUM_PAST
static final int LONGEST_PAST_TIME
static final VelocityTracker[] mPool
final float[] mPastX
final float[] mPastY
final long[] mPastTime
float mYVelocity
float mXVelocity
| Method Detail |
|---|
public static VelocityTracker obtain()
recycle() when done. You should
generally only maintain an active object while tracking a movement,
so that the VelocityTracker can be re-used elsewhere.
public void recycle()
public void clear()
public void addMovement(MotionEvent ev)
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.
ev - The MotionEvent you received and would like to track.public void computeCurrentVelocity(int units)
getXVelocity() and
getYVelocity().
units - The units you would like the velocity in. A value of 1
provides pixels per millisecond, 1000 provides pixels per second, etc.public float getXVelocity()
computeCurrentVelocity(int) before calling this function.
public float getYVelocity()
computeCurrentVelocity(int) before calling this function.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||