summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-06-01 12:39:25 -0700
committerJeff Brown <jeffbrown@google.com>2012-06-03 19:21:49 -0700
commit9eb7d86181729c3eb769d71123c4ce9ffc868f08 (patch)
tree5844b6bfd4c9eac8bc5015fa54f5255a376805c8 /core/java/android
parent6e8e41a336dfc0c43b672fd105a23aa48c93ec67 (diff)
downloadframeworks_base-9eb7d86181729c3eb769d71123c4ce9ffc868f08.zip
frameworks_base-9eb7d86181729c3eb769d71123c4ce9ffc868f08.tar.gz
frameworks_base-9eb7d86181729c3eb769d71123c4ce9ffc868f08.tar.bz2
Make velocity tracker strategy configurable.
This change is very useful for testing purposes because it makes it easy to compare different implementations to see how they behave. There is no change to the current default strategy. Bug: 6413587 Change-Id: I4d8567aa4160571ba9fa397ce419882cd9366749
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/VelocityTracker.java33
1 files changed, 27 insertions, 6 deletions
diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java
index f5870e1..82b3963 100644
--- a/core/java/android/view/VelocityTracker.java
+++ b/core/java/android/view/VelocityTracker.java
@@ -35,7 +35,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
private static final Pool<VelocityTracker> sPool = Pools.synchronizedPool(
Pools.finitePool(new PoolableManager<VelocityTracker>() {
public VelocityTracker newInstance() {
- return new VelocityTracker();
+ return new VelocityTracker(null);
}
public void onAcquired(VelocityTracker element) {
@@ -50,10 +50,12 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
private static final int ACTIVE_POINTER_ID = -1;
private int mPtr;
+ private final String mStrategy;
+
private VelocityTracker mNext;
private boolean mIsPooled;
- private static native int nativeInitialize();
+ private static native int nativeInitialize(String strategy);
private static native void nativeDispose(int ptr);
private static native void nativeClear(int ptr);
private static native void nativeAddMovement(int ptr, MotionEvent event);
@@ -75,11 +77,29 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
}
/**
+ * Obtains a velocity tracker with the specified strategy.
+ * For testing and comparison purposes only.
+ *
+ * @param strategy The strategy, or null to use the default.
+ * @return The velocity tracker.
+ *
+ * @hide
+ */
+ public static VelocityTracker obtain(String strategy) {
+ if (strategy == null) {
+ return obtain();
+ }
+ return new VelocityTracker(strategy);
+ }
+
+ /**
* Return a VelocityTracker object back to be re-used by others. You must
* not touch the object after calling this function.
*/
public void recycle() {
- sPool.release(this);
+ if (mStrategy == null) {
+ sPool.release(this);
+ }
}
/**
@@ -110,8 +130,9 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
mIsPooled = isPooled;
}
- private VelocityTracker() {
- mPtr = nativeInitialize();
+ private VelocityTracker(String strategy) {
+ mPtr = nativeInitialize(strategy);
+ mStrategy = strategy;
}
@Override
@@ -253,7 +274,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
*/
public static final class Estimator {
// Must match VelocityTracker::Estimator::MAX_DEGREE
- private static final int MAX_DEGREE = 2;
+ private static final int MAX_DEGREE = 4;
/**
* Polynomial coefficients describing motion in X.