From 237f5e4f9b984d58199916396ba68dc9958235de Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Aug 2012 16:10:16 +0900 Subject: [PATCH 001/116] Remove unused methods from Utils class Change-Id: I209b75f1cca381610f25cd219f35ea62b9762be2 --- java/src/com/android/inputmethod/latin/Utils.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index fc7a42100..f3eb2d7af 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -393,16 +393,6 @@ public class Utils { } } - public static float getDipScale(Context context) { - final float scale = context.getResources().getDisplayMetrics().density; - return scale; - } - - /** Convert pixel to DIP */ - public static int dipToPixel(float scale, int dip) { - return (int) (dip * scale + 0.5); - } - public static class Stats { public static void onNonSeparator(final char code, final int x, final int y) { From 0023a57eeaac2efd3d3eb7592a7a893e157806bb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Aug 2012 16:23:42 +0900 Subject: [PATCH 002/116] Move some methods from Utils to LocaleUtils class Change-Id: I4a834549c2ea96ac30d7e2cb692d69af219cab1a --- .../inputmethod/latin/LocaleUtils.java | 37 +++++++++++++++++++ .../inputmethod/latin/SettingsValues.java | 6 +-- .../com/android/inputmethod/latin/Utils.java | 36 ------------------ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java index 3b08cab01..01c281b89 100644 --- a/java/src/com/android/inputmethod/latin/LocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java @@ -32,6 +32,9 @@ import java.util.Locale; * dictionary pack. */ public class LocaleUtils { + private static final HashMap EMPTY_LT_HASH_MAP = CollectionUtils.newHashMap(); + private static final String LOCALE_AND_TIME_STR_SEPARATER = ","; + private LocaleUtils() { // Intentional empty constructor for utility class. } @@ -219,4 +222,38 @@ public class LocaleUtils { return retval; } } + + public static HashMap localeAndTimeStrToHashMap(String str) { + if (TextUtils.isEmpty(str)) { + return EMPTY_LT_HASH_MAP; + } + final String[] ss = str.split(LOCALE_AND_TIME_STR_SEPARATER); + final int N = ss.length; + if (N < 2 || N % 2 != 0) { + return EMPTY_LT_HASH_MAP; + } + final HashMap retval = CollectionUtils.newHashMap(); + for (int i = 0; i < N / 2; ++i) { + final String localeStr = ss[i * 2]; + final long time = Long.valueOf(ss[i * 2 + 1]); + retval.put(localeStr, time); + } + return retval; + } + + public static String localeAndTimeHashMapToStr(HashMap map) { + if (map == null || map.isEmpty()) { + return ""; + } + final StringBuilder builder = new StringBuilder(); + for (String localeStr : map.keySet()) { + if (builder.length() > 0) { + builder.append(LOCALE_AND_TIME_STR_SEPARATER); + } + final Long time = map.get(localeStr); + builder.append(localeStr).append(LOCALE_AND_TIME_STR_SEPARATER); + builder.append(String.valueOf(time)); + } + return builder.toString(); + } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index dcd2532c1..d34da5e34 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -401,7 +401,7 @@ public class SettingsValues { public static long getLastUserHistoryWriteTime( final SharedPreferences prefs, final String locale) { final String str = prefs.getString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, ""); - final HashMap map = Utils.localeAndTimeStrToHashMap(str); + final HashMap map = LocaleUtils.localeAndTimeStrToHashMap(str); if (map.containsKey(locale)) { return map.get(locale); } @@ -411,9 +411,9 @@ public class SettingsValues { public static void setLastUserHistoryWriteTime( final SharedPreferences prefs, final String locale) { final String oldStr = prefs.getString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, ""); - final HashMap map = Utils.localeAndTimeStrToHashMap(oldStr); + final HashMap map = LocaleUtils.localeAndTimeStrToHashMap(oldStr); map.put(locale, System.currentTimeMillis()); - final String newStr = Utils.localeAndTimeHashMapToStr(map); + final String newStr = LocaleUtils.localeAndTimeHashMapToStr(map); prefs.edit().putString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, newStr).apply(); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index fc7a42100..eeec1eb6d 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -456,40 +456,4 @@ public class Utils { } return sDeviceOverrideValueMap.get(key); } - - private static final HashMap EMPTY_LT_HASH_MAP = CollectionUtils.newHashMap(); - private static final String LOCALE_AND_TIME_STR_SEPARATER = ","; - public static HashMap localeAndTimeStrToHashMap(String str) { - if (TextUtils.isEmpty(str)) { - return EMPTY_LT_HASH_MAP; - } - final String[] ss = str.split(LOCALE_AND_TIME_STR_SEPARATER); - final int N = ss.length; - if (N < 2 || N % 2 != 0) { - return EMPTY_LT_HASH_MAP; - } - final HashMap retval = CollectionUtils.newHashMap(); - for (int i = 0; i < N / 2; ++i) { - final String localeStr = ss[i * 2]; - final long time = Long.valueOf(ss[i * 2 + 1]); - retval.put(localeStr, time); - } - return retval; - } - - public static String localeAndTimeHashMapToStr(HashMap map) { - if (map == null || map.isEmpty()) { - return ""; - } - final StringBuilder builder = new StringBuilder(); - for (String localeStr : map.keySet()) { - if (builder.length() > 0) { - builder.append(LOCALE_AND_TIME_STR_SEPARATER); - } - final Long time = map.get(localeStr); - builder.append(localeStr).append(LOCALE_AND_TIME_STR_SEPARATER); - builder.append(String.valueOf(time)); - } - return builder.toString(); - } } From 9879f65651a748e4c0a45715eb7d5663652f1127 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 29 Aug 2012 16:31:50 +0900 Subject: [PATCH 003/116] Add ResourceUtils Change-Id: Ia198f8d95eae8c007623cd52d73cc1528d22fee9 --- .../inputmethod/keyboard/Keyboard.java | 4 +- .../keyboard/MainKeyboardView.java | 4 +- .../SuddenJumpingTouchEventHandler.java | 4 +- .../inputmethod/latin/ResourceUtils.java | 48 +++++++++++++++++++ .../inputmethod/latin/SettingsValues.java | 8 ++-- .../com/android/inputmethod/latin/Utils.java | 20 -------- 6 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/ResourceUtils.java diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index e37868b3f..e12e5f301 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -37,8 +37,8 @@ import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.ResourceUtils; import com.android.inputmethod.latin.SubtypeLocale; -import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -746,7 +746,7 @@ public class Keyboard { R.styleable.Keyboard_Key); try { final int displayHeight = mDisplayMetrics.heightPixels; - final String keyboardHeightString = Utils.getDeviceOverrideValue( + final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue( mResources, R.array.keyboard_heights, null); final float keyboardHeight; if (keyboardHeightString != null) { diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index df84271e8..358061b47 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -48,10 +48,10 @@ import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.ResourceUtils; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SubtypeLocale; -import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.research.ResearchLogger; @@ -334,7 +334,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT); final Resources res = getResources(); final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean( - Utils.getDeviceOverrideValue(res, + ResourceUtils.getDeviceOverrideValue(res, R.array.phantom_sudden_move_event_device_list, "false")); PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack); diff --git a/java/src/com/android/inputmethod/keyboard/internal/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/internal/SuddenJumpingTouchEventHandler.java index 9e2cbec52..a591a7ac3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/SuddenJumpingTouchEventHandler.java +++ b/java/src/com/android/inputmethod/keyboard/internal/SuddenJumpingTouchEventHandler.java @@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.ResourceUtils; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.research.ResearchLogger; @@ -53,7 +53,7 @@ public class SuddenJumpingTouchEventHandler { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { mView = view; - mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue( + mNeedsSuddenJumpingHack = Boolean.parseBoolean(ResourceUtils.getDeviceOverrideValue( context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false")); } diff --git a/java/src/com/android/inputmethod/latin/ResourceUtils.java b/java/src/com/android/inputmethod/latin/ResourceUtils.java new file mode 100644 index 000000000..93a9c88f3 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/ResourceUtils.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.latin; + +import android.content.res.Resources; +import android.os.Build; + +import java.util.HashMap; + +public class ResourceUtils { + private ResourceUtils() { + // This utility class is not publicly instantiable. + } + + private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; + private static final HashMap sDeviceOverrideValueMap = + CollectionUtils.newHashMap(); + + public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { + final int orientation = res.getConfiguration().orientation; + final String key = overrideResId + "-" + orientation; + if (!sDeviceOverrideValueMap.containsKey(key)) { + String overrideValue = defValue; + for (final String element : res.getStringArray(overrideResId)) { + if (element.startsWith(HARDWARE_PREFIX)) { + overrideValue = element.substring(HARDWARE_PREFIX.length()); + break; + } + } + sDeviceOverrideValueMap.put(key, overrideValue); + } + return sDeviceOverrideValueMap.get(key); + } +} diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d34da5e34..5e355a3b8 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -375,8 +375,8 @@ public class SettingsValues { return volume; } - return Float.parseFloat( - Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f")); + return Float.parseFloat(ResourceUtils.getDeviceOverrideValue( + res, R.array.keypress_volumes, "-1.0f")); } // Likewise @@ -388,8 +388,8 @@ public class SettingsValues { return ms; } - return Integer.parseInt( - Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1")); + return Integer.parseInt(ResourceUtils.getDeviceOverrideValue( + res, R.array.keypress_vibration_durations, "-1")); } // Likewise diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 7dffc12da..5f95f6656 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -426,24 +426,4 @@ public class Utils { if (TextUtils.isEmpty(info)) return null; return info; } - - private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; - private static final HashMap sDeviceOverrideValueMap = - CollectionUtils.newHashMap(); - - public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { - final int orientation = res.getConfiguration().orientation; - final String key = overrideResId + "-" + orientation; - if (!sDeviceOverrideValueMap.containsKey(key)) { - String overrideValue = defValue; - for (final String element : res.getStringArray(overrideResId)) { - if (element.startsWith(HARDWARE_PREFIX)) { - overrideValue = element.substring(HARDWARE_PREFIX.length()); - break; - } - } - sDeviceOverrideValueMap.put(key, overrideValue); - } - return sDeviceOverrideValueMap.get(key); - } } From a05a0f20776b4c33f41f043f1bff245331937580 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 27 Aug 2012 20:09:46 +0900 Subject: [PATCH 004/116] 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 --- .../inputmethod/latin/LastComposedWord.java | 12 ++-- .../android/inputmethod/latin/LatinIME.java | 60 ++++++++++--------- .../com/android/inputmethod/latin/Utils.java | 29 ++++++--- .../inputmethod/latin/WordComposer.java | 4 +- 4 files changed, 61 insertions(+), 44 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index bb39ce4f7..dd73a978c 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -38,12 +38,12 @@ public class LastComposedWord { // an auto-correction. public static final int COMMIT_TYPE_CANCEL_AUTO_CORRECT = 3; - public static final int NOT_A_SEPARATOR = -1; + public static final String NOT_A_SEPARATOR = ""; public final int[] mPrimaryKeyCodes; public final String mTypedWord; public final String mCommittedWord; - public final int mSeparatorCode; + public final String mSeparatorString; public final CharSequence mPrevWord; public final InputPointers mInputPointers = new InputPointers(BinaryDictionary.MAX_WORD_LENGTH); @@ -56,14 +56,14 @@ public class LastComposedWord { // immutable. Do not fiddle with their contents after you passed them to this constructor. public LastComposedWord(final int[] primaryKeyCodes, final InputPointers inputPointers, final String typedWord, final String committedWord, - final int separatorCode, final CharSequence prevWord) { + final String separatorString, final CharSequence prevWord) { mPrimaryKeyCodes = primaryKeyCodes; if (inputPointers != null) { mInputPointers.copy(inputPointers); } mTypedWord = typedWord; mCommittedWord = committedWord; - mSeparatorCode = separatorCode; + mSeparatorString = separatorString; mActive = true; mPrevWord = prevWord; } @@ -80,7 +80,7 @@ public class LastComposedWord { return TextUtils.equals(mTypedWord, mCommittedWord); } - public static int getSeparatorLength(final int separatorCode) { - return NOT_A_SEPARATOR == separatorCode ? 0 : 1; + public static int getSeparatorLength(final String separatorString) { + return StringUtils.codePointCount(separatorString); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 83a306818..76f495729 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1055,7 +1055,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; } - private void commitTyped(final int separatorCode) { + private void commitTyped(final String separatorString) { if (!mWordComposer.isComposingWord()) return; final CharSequence typedWord = mWordComposer.getTypedWord(); if (typedWord.length() > 0) { @@ -1063,7 +1063,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final CharSequence prevWord = addToUserHistoryDictionary(typedWord); mLastComposedWord = mWordComposer.commitWord( LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(), - separatorCode, prevWord); + separatorString, prevWord); } } @@ -1340,7 +1340,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (!didAutoCorrect && primaryCode != Keyboard.CODE_SHIFT && primaryCode != Keyboard.CODE_SWITCH_ALPHA_SYMBOL) mLastComposedWord.deactivate(); - mEnteredText = null; + if (Keyboard.CODE_DELETE != primaryCode) { + mEnteredText = null; + } mConnection.endBatchEdit(); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onCodeInput(primaryCode, x, y); @@ -1352,7 +1354,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void onTextInput(CharSequence rawText) { mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { - commitCurrentAutoCorrection(LastComposedWord.NOT_A_SEPARATOR); + commitCurrentAutoCorrection(rawText.toString()); + } else { + resetComposingState(true /* alsoResetLastComposedWord */); } mHandler.postUpdateSuggestionStrip(); final CharSequence text = specificTldProcessingOnTextInput(rawText); @@ -1365,7 +1369,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mKeyboardSwitcher.onCodeInput(Keyboard.CODE_OUTPUT_TEXT); mSpaceState = SPACE_STATE_NONE; mEnteredText = text; - resetComposingState(true /* alsoResetLastComposedWord */); } @Override @@ -1451,18 +1454,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // In many cases, we may have to put the keyboard in auto-shift state again. mHandler.postUpdateShiftState(); - if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) { - // Cancel multi-character input: remove the text we just entered. - // This is triggered on backspace after a key that inputs multiple characters, - // like the smiley key or the .com key. - final int length = mEnteredText.length(); - mConnection.deleteSurroundingText(length, 0); - // If we have mEnteredText, then we know that mHasUncommittedTypedChars == false. - // In addition we know that spaceState is false, and that we should not be - // reverting any autocorrect at this point. So we can safely return. - return; - } - if (mWordComposer.isComposingWord()) { final int length = mWordComposer.size(); if (length > 0) { @@ -1483,6 +1474,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen revertCommit(); return; } + if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) { + // Cancel multi-character input: remove the text we just entered. + // This is triggered on backspace after a key that inputs multiple characters, + // like the smiley key or the .com key. + final int length = mEnteredText.length(); + mConnection.deleteSurroundingText(length, 0); + mEnteredText = null; + // If we have mEnteredText, then we know that mHasUncommittedTypedChars == false. + // In addition we know that spaceState is false, and that we should not be + // reverting any autocorrect at this point. So we can safely return. + return; + } if (SPACE_STATE_DOUBLE == spaceState) { mHandler.cancelDoubleSpacesTimer(); if (mConnection.revertDoubleSpace()) { @@ -1626,10 +1629,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Handle separator if (mWordComposer.isComposingWord()) { if (mCurrentSettings.mCorrectionEnabled) { - commitCurrentAutoCorrection(primaryCode); + // TODO: maybe cache Strings in an sparse array or something + commitCurrentAutoCorrection(new String(new int[]{primaryCode}, 0, 1)); didAutoCorrect = true; } else { - commitTyped(primaryCode); + commitTyped(new String(new int[]{primaryCode}, 0, 1)); } } @@ -1834,7 +1838,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen setSuggestionStripShown(isSuggestionsStripVisible()); } - private void commitCurrentAutoCorrection(final int separatorCodePoint) { + private void commitCurrentAutoCorrection(final String separatorString) { // Complete any pending suggestions query first if (mHandler.hasPendingUpdateSuggestions()) { updateSuggestionStrip(); @@ -1848,10 +1852,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen throw new RuntimeException("We have an auto-correction but the typed word " + "is empty? Impossible! I must commit suicide."); } - Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint); + Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorString); mExpectingUpdateSelection = true; commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD, - separatorCodePoint); + separatorString); if (!typedWord.equals(autoCorrection)) { // This will make the correction flash for a short while as a visual clue // to the user that auto-correction happened. @@ -1949,7 +1953,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen * Commits the chosen word to the text field and saves it for later retrieval. */ private void commitChosenWord(final CharSequence chosenWord, final int commitType, - final int separatorCode) { + final String separatorString) { final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions(); mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1); @@ -1960,7 +1964,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // LastComposedWord#didCommitTypedWord by string equality of the remembered // strings. mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord.toString(), - separatorCode, prevWord); + separatorString, prevWord); } private void setPunctuationSuggestions() { @@ -2030,7 +2034,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final CharSequence committedWord = mLastComposedWord.mCommittedWord; final int cancelLength = committedWord.length(); final int separatorLength = LastComposedWord.getSeparatorLength( - mLastComposedWord.mSeparatorCode); + mLastComposedWord.mSeparatorString); // TODO: should we check our saved separator against the actual contents of the text view? final int deleteLength = cancelLength + separatorLength; if (DEBUG) { @@ -2051,10 +2055,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mUserHistoryDictionary.cancelAddingUserHistory( previousWord.toString(), committedWord.toString()); } - mConnection.commitText(originallyTypedWord, 1); - // Re-insert the separator - sendKeyCodePoint(mLastComposedWord.mSeparatorCode); - Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, + mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1); + Utils.Stats.onSeparator(mLastComposedWord.mSeparatorString, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_revertCommit(originallyTypedWord); 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() { diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index ecec60f89..4b7adf26b 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -336,14 +336,14 @@ public class WordComposer { // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. public LastComposedWord commitWord(final int type, final String committedWord, - final int separatorCode, final CharSequence prevWord) { + final String separatorString, final CharSequence prevWord) { // Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK // or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate // the last composed word to ensure this does not happen. final int[] primaryKeyCodes = mPrimaryKeyCodes; mPrimaryKeyCodes = new int[N]; final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, - mInputPointers, mTypedWord.toString(), committedWord, separatorCode, + mInputPointers, mTypedWord.toString(), committedWord, separatorString, prevWord); mInputPointers.reset(); if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD From d20652c878aae2e0e46a33310672a2786ee55b0c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Aug 2012 11:28:42 +0900 Subject: [PATCH 005/116] Use non-bold text for Arabic and Thai keyboard The key text style can be specified in each keyboard layout in addition to by KeyboardView theme. Bug: 6753168 Change-Id: I4b5abda9322600eb8c6421f20ceef136ef103c05 --- java/res/values/attrs.xml | 2 +- java/res/values/styles.xml | 8 +-- java/res/xml-sw600dp-land/kbd_thai.xml | 1 + java/res/xml-sw600dp/kbd_thai.xml | 1 + java/res/xml-sw768dp-land/kbd_thai.xml | 1 + java/res/xml-sw768dp/kbd_thai.xml | 1 + java/res/xml/kbd_arabic.xml | 1 + java/res/xml/kbd_thai.xml | 1 + .../inputmethod/keyboard/Keyboard.java | 18 ++++++ .../inputmethod/keyboard/KeyboardView.java | 58 ++++++++++--------- 10 files changed, 59 insertions(+), 33 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 76e76cc82..27bf32935 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -109,7 +109,7 @@ - + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 0220c836e..a52ee06d4 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -42,7 +42,7 @@ @fraction/key_hint_letter_ratio @fraction/key_hint_label_ratio @fraction/key_uppercase_letter_ratio - normal + normal #FFFFFFFF #FFFFFFFF #80000000 @@ -243,7 +243,7 @@ name="KeyboardView.Stone.Bold" parent="KeyboardView.Stone" > - bold + bold