diff --git a/core/api/current.txt b/core/api/current.txt index 18d8fc72a40d8..6cb615374ad1c 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -49939,10 +49939,13 @@ package android.view { method public void clear(); method public void computeCurrentVelocity(int); method public void computeCurrentVelocity(int, float); + method public float getAxisVelocity(int, int); + method public float getAxisVelocity(int); method public float getXVelocity(); method public float getXVelocity(int); method public float getYVelocity(); method public float getYVelocity(int); + method public boolean isAxisSupported(int); method public static android.view.VelocityTracker obtain(); method public void recycle(); } diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java index a52fc7586f726..6d25523ac5bcb 100644 --- a/core/java/android/view/VelocityTracker.java +++ b/core/java/android/view/VelocityTracker.java @@ -183,6 +183,7 @@ public final class VelocityTracker { private static native float nativeGetVelocity(long ptr, int axis, int id); private static native boolean nativeGetEstimator( long ptr, int axis, int id, Estimator outEstimator); + private static native boolean nativeIsAxisSupported(int axis); static { // Strategy string and IDs mapping lookup. @@ -304,6 +305,22 @@ public final class VelocityTracker { } } + /** + * Checks whether a given motion axis is supported for velocity tracking. + * + *
The axis values that would make sense to use for this method are the ones defined in the + * {@link MotionEvent} class. + * + * @param axis The axis to check for velocity support. + * @return {@code true} if {@code axis} is supported for velocity tracking, or {@code false} + * otherwise. + * @see #getAxisVelocity(int, int) + * @see #getAxisVelocity(int) + */ + public boolean isAxisSupported(int axis) { + return nativeIsAxisSupported(axis); + } + /** * Reset the velocity tracker back to its initial state. */ @@ -345,7 +362,9 @@ public final class VelocityTracker { * {@link #getYVelocity()}. * * @param units The units you would like the velocity in. A value of 1 - * provides pixels per millisecond, 1000 provides pixels per second, etc. + * provides units per millisecond, 1000 provides units per second, etc. + * Note that the units referred to here are the same units with which motion is reported. For + * axes X and Y, the units are pixels. * @param maxVelocity The maximum velocity that can be computed by this method. * This value must be declared in the same unit as the units parameter. This value * must be positive. @@ -396,6 +415,45 @@ public final class VelocityTracker { return nativeGetVelocity(mPtr, MotionEvent.AXIS_Y, id); } + /** + * Retrieve the last computed velocity for a given motion axis. You must first call + * {@link #computeCurrentVelocity(int)} or {@link #computeCurrentVelocity(int, float)} before + * calling this function. + * + *
In addition to {@link MotionEvent#AXIS_X} and {@link MotionEvent#AXIS_Y} which have been + * supported since the introduction of this class, the following axes are supported for this + * method: + *