Stay organized with collections Save and categorize content based on your preferences.

VelocityTrackerCompat

public final class VelocityTrackerCompat


Helper for accessing features in VelocityTracker.

Summary

Public methods

static float
getAxisVelocity(@NonNull VelocityTracker tracker, int axis)

Equivalent to calling getAxisVelocity for axis and the active pointer.

static float
getAxisVelocity(@NonNull VelocityTracker tracker, int axis, int pointerId)

Retrieve the last computed velocity for a given motion axis.

static float
getXVelocity(VelocityTracker tracker, int pointerId)

This method is deprecated.

Use getXVelocity directly.

static float
getYVelocity(VelocityTracker tracker, int pointerId)

This method is deprecated.

Use getYVelocity directly.

static boolean
isAxisSupported(@NonNull VelocityTracker tracker, int axis)

Checks whether a given velocity-trackable MotionEvent axis is supported for velocity tracking by this VelocityTracker instance (refer to getAxisVelocity for a list of potentially velocity-trackable axes).

Public methods

getAxisVelocity

public static float getAxisVelocity(@NonNull VelocityTracker tracker, int axis)

Equivalent to calling getAxisVelocity for axis and the active pointer.

Parameters
@NonNull VelocityTracker tracker

The VelocityTracker from which to get axis velocity.

int axis

Which axis' velocity to return.

Returns
float

The previously computed velocity for axis for the active pointer if axis is supported for velocity tracking, or 0 if velocity tracking is not supported for the axis.

getAxisVelocity

public static float getAxisVelocity(@NonNull VelocityTracker tracker, int axis, int pointerId)

Retrieve the last computed velocity for a given motion axis. You must first call computeCurrentVelocity or computeCurrentVelocity before calling this function.

In addition to AXIS_X and AXIS_Y which have been supported since the introduction of this class, the following axes can be candidates for this method:

Before accessing velocities of an axis using this method, check that your VelocityTracker instance supports the axis by using isAxisSupported.

Parameters
@NonNull VelocityTracker tracker

The VelocityTracker from which to get axis velocity.

int axis

Which axis' velocity to return.

int pointerId

Which pointer's velocity to return.

Returns
float

The previously computed velocity for axis for pointer ID of id if axis is supported for velocity tracking, or 0 if velocity tracking is not supported for the axis.

See also
isAxisSupported

getXVelocity

public static float getXVelocity(VelocityTracker tracker, int pointerId)

Call getXVelocity. If running on a pre-HONEYCOMB device, returns getXVelocity.

getYVelocity

public static float getYVelocity(VelocityTracker tracker, int pointerId)

Call getYVelocity. If running on a pre-HONEYCOMB device, returns getYVelocity.

isAxisSupported

public static boolean isAxisSupported(@NonNull VelocityTracker tracker, int axis)

Checks whether a given velocity-trackable MotionEvent axis is supported for velocity tracking by this VelocityTracker instance (refer to getAxisVelocity for a list of potentially velocity-trackable axes).

Note that the value returned from this method will stay the same for a given instance, so a single check for axis support is enough per a VelocityTracker instance.

Parameters
@NonNull VelocityTracker tracker

The VelocityTracker for which to check axis support.

int axis

The axis to check for velocity support.

Returns
boolean

true if axis is supported for velocity tracking, or false otherwise.