diff options
author | 2012-09-20 16:39:40 +0900 | |
---|---|---|
committer | 2012-09-20 19:38:29 +0900 | |
commit | 61dcaaf17e4d1f9e941b961559a46823e6e25c99 (patch) | |
tree | 7f423a6a0aae957b75202805375d067cfd988b70 /java/src | |
parent | 84c1bbd76d144c2d777952079b9e8d8fea98c9b2 (diff) | |
download | latinime-61dcaaf17e4d1f9e941b961559a46823e6e25c99.tar.gz latinime-61dcaaf17e4d1f9e941b961559a46823e6e25c99.tar.xz latinime-61dcaaf17e4d1f9e941b961559a46823e6e25c99.zip |
Use device independent parameter for gesture
Change-Id: Iea95992e4482108a498f14ec595f3eacc7d7fc4b
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java index 5ba57f565..f0be0ee94 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java @@ -31,15 +31,18 @@ public class GestureStroke { private int mLastPointX; private int mLastPointY; - private int mMinGestureLength; - private int mMinGestureSampleLength; + private int mMinGestureLength; // pixel + private int mMinGestureSampleLength; // pixel + private int mGestureRecognitionThreshold; // pixel / sec // TODO: Move some of these to resource. private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f; 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 GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec + private static final float GESTURE_RECOGNITION_SPEED_THRESHOLD_RATIO_TO_KEY_WIDTH = + 5.5f; // keyWidth / sec + private static final int MSEC_PER_SEC = 1000; public static final boolean hasRecognitionTimePast( final long currentTime, final long lastRecognitionTime) { @@ -54,6 +57,8 @@ public class GestureStroke { // TODO: Find an appropriate base metric for these length. Maybe diagonal length of the key? mMinGestureLength = (int)(keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH); mMinGestureSampleLength = (int)(keyWidth * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH); + mGestureRecognitionThreshold = + (int)(keyWidth * GESTURE_RECOGNITION_SPEED_THRESHOLD_RATIO_TO_KEY_WIDTH); } public boolean isStartOfAGesture() { @@ -72,45 +77,41 @@ public class GestureStroke { mYCoordinates.setLength(0); } - private void updateLastPoint(final int x, final int y, final int time) { - mLastPointTime = time; - mLastPointX = x; - mLastPointY = y; - } - public void addPoint(final int x, final int y, final int time, final boolean isHistorical) { + final boolean needsSampling; final int size = mEventTimes.getLength(); if (size == 0) { - mEventTimes.add(time); - mXCoordinates.add(x); - mYCoordinates.add(y); - if (!isHistorical) { - updateLastPoint(x, y, time); - } - return; + needsSampling = true; + } else { + final int lastIndex = size - 1; + final int lastX = mXCoordinates.get(lastIndex); + final int lastY = mYCoordinates.get(lastIndex); + final float dist = getDistance(lastX, lastY, x, y); + needsSampling = dist > mMinGestureSampleLength; + mLength += dist; } - - final int lastX = mXCoordinates.get(size - 1); - final int lastY = mYCoordinates.get(size - 1); - final float dist = getDistance(lastX, lastY, x, y); - if (dist > mMinGestureSampleLength) { + if (needsSampling) { mEventTimes.add(time); mXCoordinates.add(x); mYCoordinates.add(y); - mLength += dist; } - if (!isHistorical) { - final int duration = (int)(time - mLastPointTime); - if (mLastPointTime != 0 && duration > 0) { - final float distance = getDistance(mLastPointX, mLastPointY, x, y); - final float speed = distance / duration; - if (speed < GESTURE_RECOG_SPEED_THRESHOLD) { - mIncrementalRecognitionSize = size; - } + updateIncrementalRecognitionSize(x, y, time); + } + } + + private void updateIncrementalRecognitionSize(final int x, final int y, final int time) { + final int msecs = (int)(time - mLastPointTime); + if (msecs > 0) { + final int pixels = (int)getDistance(mLastPointX, mLastPointY, x, y); + // Equivalent to (pixels / msecs < mGestureRecognitionThreshold / MSEC_PER_SEC) + if (pixels * MSEC_PER_SEC < mGestureRecognitionThreshold * msecs) { + mIncrementalRecognitionSize = mEventTimes.getLength(); } - updateLastPoint(x, y, time); } + mLastPointTime = time; + mLastPointX = x; + mLastPointY = y; } public void appendAllBatchPoints(final InputPointers out) { |