am faf62426: am 84c1bbd7: Merge "Move PointerTracker.MIN_GESTURE_RECOGNITION_TIME to GestureStroke" into jb-mr1-dev

* commit 'faf62426fda3d17aab070da9a0f0d3f35f33908b':
  Move PointerTracker.MIN_GESTURE_RECOGNITION_TIME to GestureStroke
main
Tadashi G. Takaoka 2012-09-20 09:29:33 -07:00 committed by Android Git Automerger
commit 99220e1d96
2 changed files with 11 additions and 6 deletions

View File

@ -47,8 +47,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private static boolean sGestureHandlingEnabledByInputField = false; private static boolean sGestureHandlingEnabledByInputField = false;
private static boolean sGestureHandlingEnabledByUser = false; private static boolean sGestureHandlingEnabledByUser = false;
private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
public interface KeyEventHandler { public interface KeyEventHandler {
/** /**
* Get KeyDetector object that is used for this PointerTracker. * Get KeyDetector object that is used for this PointerTracker.
@ -562,7 +560,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mGestureStrokeWithPreviewPoints.appendIncrementalBatchPoints(sAggregratedPointers); mGestureStrokeWithPreviewPoints.appendIncrementalBatchPoints(sAggregratedPointers);
final int size = sAggregratedPointers.getPointerSize(); final int size = sAggregratedPointers.getPointerSize();
if (size > sLastRecognitionPointSize if (size > sLastRecognitionPointSize
&& eventTime > sLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) { && GestureStroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) {
sLastRecognitionPointSize = size; sLastRecognitionPointSize = size;
sLastRecognitionTime = eventTime; sLastRecognitionTime = eventTime;
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {

View File

@ -36,10 +36,16 @@ public class GestureStroke {
// TODO: Move some of these to resource. // TODO: Move some of these to resource.
private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f; private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f;
private static final int MIN_GESTURE_DURATION = 100; // msec private static final int MIN_GESTURE_START_DURATION = 100; // msec
private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH = 1.0f / 6.0f; private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH = 1.0f / 6.0f;
private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec
public static final boolean hasRecognitionTimePast(
final long currentTime, final long lastRecognitionTime) {
return currentTime > lastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME;
}
public GestureStroke(final int pointerId) { public GestureStroke(final int pointerId) {
mPointerId = pointerId; mPointerId = pointerId;
} }
@ -53,7 +59,7 @@ public class GestureStroke {
public boolean isStartOfAGesture() { public boolean isStartOfAGesture() {
final int size = mEventTimes.getLength(); final int size = mEventTimes.getLength();
final int downDuration = (size > 0) ? mEventTimes.get(size - 1) : 0; final int downDuration = (size > 0) ? mEventTimes.get(size - 1) : 0;
return downDuration > MIN_GESTURE_DURATION && mLength > mMinGestureLength; return downDuration > MIN_GESTURE_START_DURATION && mLength > mMinGestureLength;
} }
public void reset() { public void reset() {
@ -97,7 +103,8 @@ public class GestureStroke {
if (!isHistorical) { if (!isHistorical) {
final int duration = (int)(time - mLastPointTime); final int duration = (int)(time - mLastPointTime);
if (mLastPointTime != 0 && duration > 0) { if (mLastPointTime != 0 && duration > 0) {
final float speed = getDistance(mLastPointX, mLastPointY, x, y) / duration; final float distance = getDistance(mLastPointX, mLastPointY, x, y);
final float speed = distance / duration;
if (speed < GESTURE_RECOG_SPEED_THRESHOLD) { if (speed < GESTURE_RECOG_SPEED_THRESHOLD) {
mIncrementalRecognitionSize = size; mIncrementalRecognitionSize = size;
} }