public final class VelocityDetector extends Object
| 限定符和类型 | 类 | 说明 |
|---|---|---|
protected static class |
VelocityDetector.VelocityDetectorCleaner |
The callback for releasing native Style object.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
addEvent(TouchEvent event) |
Adds a user's movement to the Detector.
|
void |
calculateCurrentVelocity(int units) |
Calculates the current velocity based on points that have been collected.
|
void |
calculateCurrentVelocity(int units,
float maxVxVelocity,
float maxVyVelocity) |
Calculates the current velocity based on points that have been collected and specifies upper limits for
calculated X and Y velocities.
|
void |
clear() |
Resets a
VelocityDetector instance to the initial state. |
float |
getHorizontalVelocity() |
Obtains the X velocity calculated most recently.
|
float[] |
getVelocity() |
Obtains the velocity calculated most recently.
|
float |
getVerticalVelocity() |
Obtains the Y velocity calculated most recently.
|
static VelocityDetector |
obtainInstance() |
Obtains a new
VelocityDetector instance to detect the velocity of a motion. |
public static VelocityDetector obtainInstance()
VelocityDetector instance to detect the velocity of a motion.VelocityDetector instance.public void clear()
VelocityDetector instance to the initial state.public void addEvent(TouchEvent event)
You can call this method to detect any movement.
event - Indicates the event that you want to detect, which is a TouchEvent instance.public void calculateCurrentVelocity(int units)
After the calculation is completed, you can use getHorizontalVelocity()
and getVerticalVelocity() to retrieve the velocity result.
units - Indicates the unit for the velocity result. The value 1 indicates pixels per millisecond,
1000 indicates pixels per second, and so on.public void calculateCurrentVelocity(int units,
float maxVxVelocity,
float maxVyVelocity)
After the calculation is completed, you can use getHorizontalVelocity()
and getVerticalVelocity() to retrieve the velocity result.
units - Indicates the for the velocity result. The value 1 indicates pixels per millisecond,
1000 indicates pixels per second, and so on.maxVxVelocity - Indicates the maximum X velocity.maxVyVelocity - Indicates the maximum Y velocity.public float getHorizontalVelocity()
You must first call calculateCurrentVelocity(int) before calling this function.
public float getVerticalVelocity()
You must call calculateCurrentVelocity(int) before calling this function.
public float[] getVelocity()
Before calling this method, you must call calculateCurrentVelocity(int).