From 7a17c1fcb52f0249108cfcbd789928320706718a Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 9 Oct 2012 14:31:13 +0900 Subject: [PATCH 1/3] Tuning gesture detection parameters Bug: 7032858 Change-Id: Ie4f952aa33b99ce16027500a596d723ee9bafae9 --- java/res/values/config.xml | 2 +- .../inputmethod/keyboard/PointerTracker.java | 49 +++++++------------ .../keyboard/internal/GestureStroke.java | 17 +++++-- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/java/res/values/config.xml b/java/res/values/config.xml index b3dbb0ee5..32b54447c 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -81,7 +81,7 @@ 20 600% - 35% + 50% 16.6666% diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 82c77d6cd..361053337 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -192,47 +192,32 @@ public final class PointerTracker implements PointerTrackerQueue.Element { gestureStrokeParams.mStaticTimeThresholdAfterFastTyping; } - private void recordTyping(final long eventTime) { - mLastTypingTime = eventTime; - } - - private void recordLetterTyping(final long eventTime) { - mLastLetterTypingTime = eventTime; - // Reset gesture typing time - mLastBatchInputTime = 0; - } - - private void recordGestureTyping(final long eventTime) { - mLastBatchInputTime = eventTime; - // Reset typing time. - mLastTypingTime = 0; - } - - private boolean isInTyping() { - return mLastTypingTime != 0; - } - - private boolean isInBatchInput() { - return mLastBatchInputTime != 0; + private boolean wasLastInputTyping() { + return mLastTypingTime >= mLastBatchInputTime; } public void onCodeInput(final int code, final long eventTime) { - if (Keyboard.isLetterCode(code) && code != Keyboard.CODE_SPACE) { - if (isInTyping() - && eventTime - mLastTypingTime < mStaticTimeThresholdAfterFastTyping) { - recordLetterTyping(eventTime); + // Record the letter typing time when + // 1. Letter keys are typed successively without any batch input in between. + // 2. A letter key is typed within the threshold time since the last any key typing. + // 3. A non-letter key is typed within the threshold time since the last letter key + // typing. + if (Character.isLetter(code)) { + if (wasLastInputTyping() + || eventTime - mLastTypingTime < mStaticTimeThresholdAfterFastTyping) { + mLastLetterTypingTime = eventTime; } } else { if (eventTime - mLastLetterTypingTime < mStaticTimeThresholdAfterFastTyping) { // This non-letter typing should be treated as a part of fast typing. - recordLetterTyping(eventTime); + mLastLetterTypingTime = eventTime; } } - recordTyping(eventTime); + mLastTypingTime = eventTime; } public void onEndBatchInput(final long eventTime) { - recordGestureTyping(eventTime); + mLastBatchInputTime = eventTime; } public long getLastLetterTypingTime() { @@ -240,7 +225,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { } public boolean needsToSuppressKeyPreviewPopup(final long eventTime) { - return !isInTyping() && isInBatchInput() + return !wasLastInputTyping() && eventTime - mLastBatchInputTime < mSuppressKeyPreviewAfterBatchInputDuration; } } @@ -851,11 +836,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element { // Register move event on gesture tracker. onGestureMoveEvent(x, y, eventTime, true /* isMajorEvent */, key); if (sInGesture) { - mTimerProxy.cancelLongPressTimer(); mCurrentKey = null; setReleasedKeyGraphics(oldKey); return; } + if (mGestureStrokeWithPreviewPoints.hasDetectedFastMove()) { + mTimerProxy.cancelLongPressTimer(); + } } if (key != null) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java index 9b1a20159..c406f0c4f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java @@ -190,8 +190,8 @@ public class GestureStroke { return mParams.mDynamicTimeThresholdFrom - decayedThreshold; } - public boolean isStartOfAGesture() { - if (mDetectFastMoveTime == 0) { + public final boolean isStartOfAGesture() { + if (!hasDetectedFastMove()) { return false; } final int size = mEventTimes.getLength(); @@ -200,6 +200,9 @@ public class GestureStroke { } final int lastIndex = size - 1; final int deltaTime = mEventTimes.get(lastIndex) - mDetectFastMoveTime; + if (deltaTime < 0) { + return false; + } final int deltaDistance = getDistance( mXCoordinates.get(lastIndex), mYCoordinates.get(lastIndex), mDetectFastMoveX, mDetectFastMoveY); @@ -240,6 +243,10 @@ public class GestureStroke { mLastMajorEventY = y; } + public final boolean hasDetectedFastMove() { + return mDetectFastMoveTime > 0; + } + private int detectFastMove(final int x, final int y, final int time) { final int size = mEventTimes.getLength(); final int lastIndex = size - 1; @@ -255,7 +262,7 @@ public class GestureStroke { Log.d(TAG, String.format("[%d] detectFastMove: speed=%5.2f", mPointerId, speed)); } // Equivalent to (pixels / msecs < mStartSpeedThreshold / MSEC_PER_SEC) - if (mDetectFastMoveTime == 0 && pixelsPerSec > mDetectFastMoveSpeedThreshold * msecs) { + if (!hasDetectedFastMove() && pixelsPerSec > mDetectFastMoveSpeedThreshold * msecs) { if (DEBUG) { final float speed = (float)pixelsPerSec / msecs / mKeyWidth; Log.d(TAG, String.format( @@ -306,11 +313,11 @@ public class GestureStroke { return currentTime > lastRecognitionTime + mParams.mRecognitionMinimumTime; } - public void appendAllBatchPoints(final InputPointers out) { + public final void appendAllBatchPoints(final InputPointers out) { appendBatchPoints(out, mEventTimes.getLength()); } - public void appendIncrementalBatchPoints(final InputPointers out) { + public final void appendIncrementalBatchPoints(final InputPointers out) { appendBatchPoints(out, mIncrementalRecognitionSize); } From 99b84b42f9517cbf7856aec93a6d5de30daaa325 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 9 Oct 2012 19:15:06 +0900 Subject: [PATCH 2/3] Use a freq of 1 instead of 0 for non-word shortcuts. Also fix a spelling mistake in a comment Bug: 7301525 Change-Id: I4437403dce620fed03871485ee04f13c51ce34fc --- .../com/android/inputmethod/latin/BinaryDictionaryGetter.java | 2 +- .../android/inputmethod/latin/dicttool/XmlDictInputOutput.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index fa9f79ecd..201a10187 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -350,7 +350,7 @@ final class BinaryDictionaryGetter { // of the dictionary would lose whitelist functionality. private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) { // Only for English - other languages didn't have a whitelist, hence this - // ad-hock ## HACK ## + // ad-hoc ## HACK ## if (!Locale.ENGLISH.getLanguage().equals(locale.getLanguage())) return true; FileInputStream inStream = null; diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java index c31cd724a..252c3d655 100644 --- a/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java +++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/XmlDictInputOutput.java @@ -93,7 +93,7 @@ public class XmlDictInputOutput { final FusionDictionary dict = mDictionary; for (final String shortcutOnly : mShortcutsMap.keySet()) { if (dict.hasWord(shortcutOnly)) continue; - dict.add(shortcutOnly, 0, mShortcutsMap.get(shortcutOnly), true /* isNotAWord */); + dict.add(shortcutOnly, 1, mShortcutsMap.get(shortcutOnly), true /* isNotAWord */); } mDictionary = null; mShortcutsMap.clear(); From 516f9d6ea40cbd74e4e166fb5e8ec568bab45bf1 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 9 Oct 2012 20:24:13 +0900 Subject: [PATCH 3/3] Fix a bug in multiple shortcut handling code. Bug: 7301525 Change-Id: Ib38f5ab4b7e4f7996bccbc6830d46f52fd71c6f9 --- native/jni/src/terminal_attributes.h | 1 - 1 file changed, 1 deletion(-) diff --git a/native/jni/src/terminal_attributes.h b/native/jni/src/terminal_attributes.h index 53ae385ea..e72e7e3be 100644 --- a/native/jni/src/terminal_attributes.h +++ b/native/jni/src/terminal_attributes.h @@ -57,7 +57,6 @@ class TerminalAttributes { outWord[i] = (uint16_t)codePoint; } *outFreq = BinaryFormat::getAttributeFrequencyFromFlags(shortcutFlags); - mPos += BinaryFormat::CHARACTER_ARRAY_TERMINATOR_SIZE; return i; } };