summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-05-14 19:18:15 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-14 19:18:15 -0700
commite4db99cf87c47730e80dc1431f07f4f1062c648e (patch)
treede24f68470ac6de5d7ccc274a0a424e8aa632cef /libs
parent08b544c7be67343b10a4130611318b8273d06433 (diff)
parent90729403d50488566eb4ae0e09bb1be21979a633 (diff)
downloadframeworks_base-e4db99cf87c47730e80dc1431f07f4f1062c648e.zip
frameworks_base-e4db99cf87c47730e80dc1431f07f4f1062c648e.tar.gz
frameworks_base-e4db99cf87c47730e80dc1431f07f4f1062c648e.tar.bz2
Merge "Detect when pointer has stopped moving." into jb-dev
Diffstat (limited to 'libs')
-rw-r--r--libs/androidfw/VelocityTracker.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/libs/androidfw/VelocityTracker.cpp b/libs/androidfw/VelocityTracker.cpp
index a212948..5dbafd8 100644
--- a/libs/androidfw/VelocityTracker.cpp
+++ b/libs/androidfw/VelocityTracker.cpp
@@ -33,6 +33,16 @@
namespace android {
+// Nanoseconds per milliseconds.
+static const nsecs_t NANOS_PER_MS = 1000000;
+
+// Threshold for determining that a pointer has stopped moving.
+// Some input devices do not send ACTION_MOVE events in the case where a pointer has
+// stopped. We need to detect this case so that we can accurately predict the
+// velocity after the pointer starts moving again.
+static const nsecs_t ASSUME_POINTER_STOPPED_TIME = 40 * NANOS_PER_MS;
+
+
static float vectorDot(const float* a, const float* b, uint32_t m) {
float r = 0;
while (m--) {
@@ -89,15 +99,10 @@ static String8 matrixToString(const float* a, uint32_t m, uint32_t n, bool rowMa
// --- VelocityTracker ---
VelocityTracker::VelocityTracker() :
- mCurrentPointerIdBits(0), mActivePointerId(-1),
+ mLastEventTime(0), mCurrentPointerIdBits(0), mActivePointerId(-1),
mStrategy(new LeastSquaresVelocityTrackerStrategy()) {
}
-VelocityTracker::VelocityTracker(VelocityTrackerStrategy* strategy) :
- mCurrentPointerIdBits(0), mActivePointerId(-1),
- mStrategy(strategy) {
-}
-
VelocityTracker::~VelocityTracker() {
delete mStrategy;
}
@@ -125,6 +130,18 @@ void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits, const Posi
idBits.clearLastMarkedBit();
}
+ if ((mCurrentPointerIdBits.value & idBits.value)
+ && eventTime >= mLastEventTime + ASSUME_POINTER_STOPPED_TIME) {
+#if DEBUG_VELOCITY
+ ALOGD("VelocityTracker: stopped for %0.3f ms, clearing state.",
+ (eventTime - mLastEventTime) * 0.000001f);
+#endif
+ // We have not received any movements for too long. Assume that all pointers
+ // have stopped.
+ mStrategy->clear();
+ }
+ mLastEventTime = eventTime;
+
mCurrentPointerIdBits = idBits;
if (mActivePointerId < 0 || !idBits.hasBit(mActivePointerId)) {
mActivePointerId = idBits.isEmpty() ? -1 : idBits.firstMarkedBit();
@@ -467,6 +484,7 @@ bool LeastSquaresVelocityTrackerStrategy::getEstimator(uint32_t id,
uint32_t n = degree + 1;
if (solveLeastSquares(time, x, m, n, outEstimator->xCoeff, &xdet)
&& solveLeastSquares(time, y, m, n, outEstimator->yCoeff, &ydet)) {
+ outEstimator->time = newestMovement.eventTime;
outEstimator->degree = degree;
outEstimator->confidence = xdet * ydet;
#if DEBUG_LEAST_SQUARES
@@ -483,6 +501,7 @@ bool LeastSquaresVelocityTrackerStrategy::getEstimator(uint32_t id,
// No velocity data available for this pointer, but we do have its current position.
outEstimator->xCoeff[0] = x[0];
outEstimator->yCoeff[0] = y[0];
+ outEstimator->time = newestMovement.eventTime;
outEstimator->degree = 0;
outEstimator->confidence = 1;
return true;