summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-06-03 21:19:13 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-06-03 21:19:13 -0700
commit7d3fa093bbd34e19f6b580b6258c8ea4e138c777 (patch)
tree33ed4f33968d5cfabad258135588f9c3aa1e7e71 /core
parent66a10964b0aa56e07263005e6a41a87ecd2dd2d7 (diff)
parentf47e76e2c78e78e26110786e99548d718d177c32 (diff)
downloadframeworks_base-7d3fa093bbd34e19f6b580b6258c8ea4e138c777.zip
frameworks_base-7d3fa093bbd34e19f6b580b6258c8ea4e138c777.tar.gz
frameworks_base-7d3fa093bbd34e19f6b580b6258c8ea4e138c777.tar.bz2
am f47e76e2: Merge "Make velocity tracker strategy configurable." into jb-dev
* commit 'f47e76e2c78e78e26110786e99548d718d177c32': Make velocity tracker strategy configurable.
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/VelocityTracker.java33
-rw-r--r--core/java/com/android/internal/widget/PointerLocationView.java52
-rw-r--r--core/jni/android_view_VelocityTracker.cpp18
3 files changed, 90 insertions, 13 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.
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java
index 85e6c16..34cdd93 100644
--- a/core/java/com/android/internal/widget/PointerLocationView.java
+++ b/core/java/com/android/internal/widget/PointerLocationView.java
@@ -23,6 +23,7 @@ import android.graphics.RectF;
import android.graphics.Paint.FontMetricsInt;
import android.hardware.input.InputManager;
import android.hardware.input.InputManager.InputDeviceListener;
+import android.os.SystemProperties;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
@@ -36,7 +37,11 @@ import java.util.ArrayList;
public class PointerLocationView extends View implements InputDeviceListener {
private static final String TAG = "Pointer";
-
+
+ // The system property key used to specify an alternate velocity tracker strategy
+ // to plot alongside the default one. Useful for testing and comparison purposes.
+ private static final String ALT_STRATEGY_PROPERY_KEY = "debug.velocitytracker.alt";
+
public static class PointerState {
// Trace of previous points.
private float[] mTraceX = new float[32];
@@ -53,9 +58,12 @@ public class PointerLocationView extends View implements InputDeviceListener {
// Most recent velocity.
private float mXVelocity;
private float mYVelocity;
+ private float mAltXVelocity;
+ private float mAltYVelocity;
// Position estimator.
private VelocityTracker.Estimator mEstimator = new VelocityTracker.Estimator();
+ private VelocityTracker.Estimator mAltEstimator = new VelocityTracker.Estimator();
public void clearTrace() {
mTraceCount = 0;
@@ -103,7 +111,8 @@ public class PointerLocationView extends View implements InputDeviceListener {
private final PointerCoords mTempCoords = new PointerCoords();
private final VelocityTracker mVelocity;
-
+ private final VelocityTracker mAltVelocity;
+
private final FasterStringBuilder mText = new FasterStringBuilder();
private boolean mPrintCoords = true;
@@ -145,6 +154,14 @@ public class PointerLocationView extends View implements InputDeviceListener {
mActivePointerId = 0;
mVelocity = VelocityTracker.obtain();
+
+ String altStrategy = SystemProperties.get(ALT_STRATEGY_PROPERY_KEY);
+ if (altStrategy.length() != 0) {
+ Log.d(TAG, "Comparing default velocity tracker strategy with " + altStrategy);
+ mAltVelocity = VelocityTracker.obtain(altStrategy);
+ } else {
+ mAltVelocity = null;
+ }
}
public void setPrintCoords(boolean state) {
@@ -296,6 +313,25 @@ public class PointerLocationView extends View implements InputDeviceListener {
float xVel = ps.mXVelocity * (1000 / 60);
float yVel = ps.mYVelocity * (1000 / 60);
canvas.drawLine(lastX, lastY, lastX + xVel, lastY + yVel, mPaint);
+
+ // Draw alternate estimate.
+ if (mAltVelocity != null) {
+ mPaint.setARGB(128, 0, 128, 128);
+ lx = ps.mAltEstimator.estimateX(-ESTIMATE_PAST_POINTS * ESTIMATE_INTERVAL);
+ ly = ps.mAltEstimator.estimateY(-ESTIMATE_PAST_POINTS * ESTIMATE_INTERVAL);
+ for (int i = -ESTIMATE_PAST_POINTS + 1; i <= ESTIMATE_FUTURE_POINTS; i++) {
+ float x = ps.mAltEstimator.estimateX(i * ESTIMATE_INTERVAL);
+ float y = ps.mAltEstimator.estimateY(i * ESTIMATE_INTERVAL);
+ canvas.drawLine(lx, ly, x, y, mPaint);
+ lx = x;
+ ly = y;
+ }
+
+ mPaint.setARGB(255, 64, 255, 128);
+ xVel = ps.mAltXVelocity * (1000 / 60);
+ yVel = ps.mAltYVelocity * (1000 / 60);
+ canvas.drawLine(lastX, lastY, lastX + xVel, lastY + yVel, mPaint);
+ }
}
if (mCurDown && ps.mCurDown) {
@@ -470,6 +506,9 @@ public class PointerLocationView extends View implements InputDeviceListener {
mCurNumPointers = 0;
mMaxNumPointers = 0;
mVelocity.clear();
+ if (mAltVelocity != null) {
+ mAltVelocity.clear();
+ }
}
mCurNumPointers += 1;
@@ -497,6 +536,10 @@ public class PointerLocationView extends View implements InputDeviceListener {
mVelocity.addMovement(event);
mVelocity.computeCurrentVelocity(1);
+ if (mAltVelocity != null) {
+ mAltVelocity.addMovement(event);
+ mAltVelocity.computeCurrentVelocity(1);
+ }
final int N = event.getHistorySize();
for (int historyPos = 0; historyPos < N; historyPos++) {
@@ -528,6 +571,11 @@ public class PointerLocationView extends View implements InputDeviceListener {
ps.mXVelocity = mVelocity.getXVelocity(id);
ps.mYVelocity = mVelocity.getYVelocity(id);
mVelocity.getEstimator(id, ps.mEstimator);
+ if (mAltVelocity != null) {
+ ps.mAltXVelocity = mAltVelocity.getXVelocity(id);
+ ps.mAltYVelocity = mAltVelocity.getYVelocity(id);
+ mAltVelocity.getEstimator(id, ps.mAltEstimator);
+ }
ps.mToolType = event.getToolType(i);
}
}
diff --git a/core/jni/android_view_VelocityTracker.cpp b/core/jni/android_view_VelocityTracker.cpp
index 0180e0a..c2fa3be 100644
--- a/core/jni/android_view_VelocityTracker.cpp
+++ b/core/jni/android_view_VelocityTracker.cpp
@@ -24,6 +24,8 @@
#include <androidfw/VelocityTracker.h>
#include "android_view_MotionEvent.h"
+#include <ScopedUtfChars.h>
+
namespace android {
@@ -42,7 +44,7 @@ static struct {
class VelocityTrackerState {
public:
- VelocityTrackerState();
+ VelocityTrackerState(const char* strategy);
void clear();
void addMovement(const MotionEvent* event);
@@ -61,7 +63,8 @@ private:
Velocity mCalculatedVelocity[MAX_POINTERS];
};
-VelocityTrackerState::VelocityTrackerState() : mActivePointerId(-1) {
+VelocityTrackerState::VelocityTrackerState(const char* strategy) :
+ mVelocityTracker(strategy), mActivePointerId(-1) {
}
void VelocityTrackerState::clear() {
@@ -135,8 +138,13 @@ bool VelocityTrackerState::getEstimator(int32_t id, VelocityTracker::Estimator*
// --- JNI Methods ---
-static jint android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz) {
- return reinterpret_cast<jint>(new VelocityTrackerState());
+static jint android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz,
+ jstring strategyStr) {
+ if (strategyStr) {
+ ScopedUtfChars strategy(env, strategyStr);
+ return reinterpret_cast<jint>(new VelocityTrackerState(strategy.c_str()));
+ }
+ return reinterpret_cast<jint>(new VelocityTrackerState(NULL));
}
static void android_view_VelocityTracker_nativeDispose(JNIEnv* env, jclass clazz, jint ptr) {
@@ -209,7 +217,7 @@ static jboolean android_view_VelocityTracker_nativeGetEstimator(JNIEnv* env, jcl
static JNINativeMethod gVelocityTrackerMethods[] = {
/* name, signature, funcPtr */
{ "nativeInitialize",
- "()I",
+ "(Ljava/lang/String;)I",
(void*)android_view_VelocityTracker_nativeInitialize },
{ "nativeDispose",
"(I)V",