summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/PointerLocationView.java
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-09-14 10:53:18 -0700
committerJeff Brown <jeffbrown@google.com>2011-09-14 19:16:37 -0700
commitb59ab9f41faafb358afb4f951de96f34a656e0b4 (patch)
tree2fe7eefa2f4a044df7440378691264b644fc93f5 /core/java/com/android/internal/widget/PointerLocationView.java
parentaab55bf3e323b73062bd932682886b19c062a8a0 (diff)
downloadframeworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.zip
frameworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.tar.gz
frameworks_base-b59ab9f41faafb358afb4f951de96f34a656e0b4.tar.bz2
Velocity Tracker II: The Revenge of Velocity Tracker
Bug: 5265529 Rewrote the velocity tracker to fit a polynomial curve to pointer movements using least squares linear regression. The velocity is simply the first derivative of this polynomial. Clients can also obtain an Estimator that describes the complete terms of the estimating polynomial including the coefficient of determination which provides a measure of the quality of the fit (confidence). Enhanced PointerLocation to display the movement curve predicted by the estimator in addition to the velocity vector. By default, the algorithm computes a 2nd degree (quadratic) polynomial based on a 100ms recent history horizon. Change-Id: Id377bef44117fce68fee2c41f90134ce3224d3a1
Diffstat (limited to 'core/java/com/android/internal/widget/PointerLocationView.java')
-rw-r--r--core/java/com/android/internal/widget/PointerLocationView.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java
index 158291b..9a0ce3a 100644
--- a/core/java/com/android/internal/widget/PointerLocationView.java
+++ b/core/java/com/android/internal/widget/PointerLocationView.java
@@ -51,7 +51,10 @@ public class PointerLocationView extends View {
// Most recent velocity.
private float mXVelocity;
private float mYVelocity;
-
+
+ // Position estimator.
+ private VelocityTracker.Estimator mEstimator = new VelocityTracker.Estimator();
+
public void clearTrace() {
mTraceCount = 0;
}
@@ -75,6 +78,10 @@ public class PointerLocationView extends View {
}
}
+ private final int ESTIMATE_PAST_POINTS = 4;
+ private final int ESTIMATE_FUTURE_POINTS = 2;
+ private final float ESTIMATE_INTERVAL = 0.02f;
+
private final ViewConfiguration mVC;
private final Paint mTextPaint;
private final Paint mTextBackgroundPaint;
@@ -278,8 +285,20 @@ public class PointerLocationView extends View {
haveLast = true;
}
- // Draw velocity vector.
if (drawn) {
+ // Draw movement estimate curve.
+ mPaint.setARGB(128, 128, 0, 128);
+ float lx = ps.mEstimator.estimateX(-ESTIMATE_PAST_POINTS * ESTIMATE_INTERVAL);
+ float ly = ps.mEstimator.estimateY(-ESTIMATE_PAST_POINTS * ESTIMATE_INTERVAL);
+ for (int i = -ESTIMATE_PAST_POINTS + 1; i <= ESTIMATE_FUTURE_POINTS; i++) {
+ float x = ps.mEstimator.estimateX(i * ESTIMATE_INTERVAL);
+ float y = ps.mEstimator.estimateY(i * ESTIMATE_INTERVAL);
+ canvas.drawLine(lx, ly, x, y, mPaint);
+ lx = x;
+ ly = y;
+ }
+
+ // Draw velocity vector.
mPaint.setARGB(255, 255, 64, 128);
float xVel = ps.mXVelocity * (1000 / 60);
float yVel = ps.mYVelocity * (1000 / 60);
@@ -517,6 +536,7 @@ public class PointerLocationView extends View {
ps.addTrace(coords.x, coords.y);
ps.mXVelocity = mVelocity.getXVelocity(id);
ps.mYVelocity = mVelocity.getYVelocity(id);
+ mVelocity.getEstimator(id, -1, -1, ps.mEstimator);
ps.mToolType = event.getToolType(i);
}
}