From 9eb7d86181729c3eb769d71123c4ce9ffc868f08 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 1 Jun 2012 12:39:25 -0700 Subject: 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 --- core/jni/android_view_VelocityTracker.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'core/jni/android_view_VelocityTracker.cpp') 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 #include "android_view_MotionEvent.h" +#include + 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(new VelocityTrackerState()); +static jint android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz, + jstring strategyStr) { + if (strategyStr) { + ScopedUtfChars strategy(env, strategyStr); + return reinterpret_cast(new VelocityTrackerState(strategy.c_str())); + } + return reinterpret_cast(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", -- cgit v1.1