diff options
author | 2012-08-27 20:09:46 +0900 | |
---|---|---|
committer | 2012-08-29 16:49:39 +0900 | |
commit | a05a0f20776b4c33f41f043f1bff245331937580 (patch) | |
tree | 690fd7e71cb45bf3ac119a8e4a9c03d0c779ada8 /java/src/com/android/inputmethod/latin/Utils.java | |
parent | 6c70b9200340537d05ff8932d7cd990269eb486d (diff) | |
download | latinime-a05a0f20776b4c33f41f043f1bff245331937580.tar.gz latinime-a05a0f20776b4c33f41f043f1bff245331937580.tar.xz latinime-a05a0f20776b4c33f41f043f1bff245331937580.zip |
Allow Latin IME to cancel smiley-auto-correct consistenly
This change makes Latin IME behave consistently with regards
to other auto-correction cancellations in cases of auto-correction
cancellation after smiley-triggered auto-correction. That is,
pressing the smiley key when the keyboard signals it's about to
auto-correct will get the auto-correction there plus a smiley,
and pressing backspace will cancel the auto-correction, and
pressing backspace again will delete the smiley.
Bug: 7067593
Change-Id: Ia7eef70a5d06b8b9afa1f1fbb0ed1dbc21a3059f
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/Utils.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index fc7a42100..912f895fd 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -29,7 +29,6 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Process; import android.text.TextUtils; -import android.text.format.DateUtils; import android.util.Log; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -404,23 +403,39 @@ public class Utils { } public static class Stats { + static final int NOT_A_SEPARATOR_CODE_POINT = -1; + public static void onNonSeparator(final char code, final int x, final int y) { RingCharBuffer.getInstance().push(code, x, y); LatinImeLogger.logOnInputChar(); } - public static void onSeparator(final int code, final int x, - final int y) { - // TODO: accept code points - RingCharBuffer.getInstance().push((char)code, x, y); + public static void onSeparator(final int code, final int x, final int y) { + // Helper method to log a single code point separator + // TODO: cache this mapping of a code point to a string in a sparse array in StringUtils + onSeparator(new String(new int[]{code}, 0, 1), x, y); + } + + public static void onSeparator(final String separator, final int x, final int y) { + final int length = separator.length(); + for (int i = 0; i < length; i = Character.offsetByCodePoints(separator, i, 1)) { + int codePoint = Character.codePointAt(separator, i); + // TODO: accept code points + RingCharBuffer.getInstance().push((char)codePoint, x, y); + } LatinImeLogger.logOnInputSeparator(); } public static void onAutoCorrection(final String typedWord, final String correctedWord, - final int separatorCode) { + final String separatorString) { if (TextUtils.isEmpty(typedWord)) return; - LatinImeLogger.logOnAutoCorrection(typedWord, correctedWord, separatorCode); + // TODO: this fails when the separator is more than 1 code point long, but + // the backend can't handle it yet. The only case when this happens is with + // smileys and other multi-character keys. + final int codePoint = TextUtils.isEmpty(separatorString) ? NOT_A_SEPARATOR_CODE_POINT + : separatorString.codePointAt(0); + LatinImeLogger.logOnAutoCorrection(typedWord, correctedWord, codePoint); } public static void onAutoCorrectionCancellation() { |