From e9a86e2cdb58dd8d5601138294521e966d164520 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 28 Jun 2012 21:01:29 +0900 Subject: Search bigrams for the lower case version of the word (A46) ...if there aren't any for the exact case version. Bug: 6752830 Change-Id: I2737148b01ba04a64febe009ceb2ef53c265d224 --- java/src/com/android/inputmethod/latin/Suggest.java | 10 ---------- .../inputmethod/latin/UserHistoryDictionaryBigramList.java | 10 +++++----- 2 files changed, 5 insertions(+), 15 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index dcfda86ea..f810eccf4 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -177,19 +177,9 @@ public class Suggest { if (wordComposer.size() <= 1 && isCorrectionEnabled) { // At first character typed, search only the bigrams if (!TextUtils.isEmpty(prevWordForBigram)) { - final CharSequence lowerPrevWord; - if (StringUtils.hasUpperCase(prevWordForBigram)) { - // TODO: Must pay attention to locale when changing case. - lowerPrevWord = prevWordForBigram.toString().toLowerCase(); - } else { - lowerPrevWord = null; - } for (final String key : mDictionaries.keySet()) { final Dictionary dictionary = mDictionaries.get(key); suggestionsSet.addAll(dictionary.getBigrams(wordComposer, prevWordForBigram)); - if (null != lowerPrevWord) { - suggestionsSet.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord)); - } } } } else if (wordComposer.size() > 1) { diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java index 28847745e..610652ac1 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java @@ -98,11 +98,11 @@ public class UserHistoryDictionaryBigramList { } public HashMap getBigrams(String word1) { - if (!mBigramMap.containsKey(word1)) { - return EMPTY_BIGRAM_MAP; - } else { - return mBigramMap.get(word1); - } + if (mBigramMap.containsKey(word1)) return mBigramMap.get(word1); + // TODO: lower case according to locale + final String lowerWord1 = word1.toLowerCase(); + if (mBigramMap.containsKey(lowerWord1)) return mBigramMap.get(lowerWord1); + return EMPTY_BIGRAM_MAP; } public boolean removeBigram(String word1, String word2) { -- cgit v1.2.3-83-g751a From 7b40c682778a544cf61b211e74b74961ff6e1206 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 29 Jun 2012 14:50:48 +0900 Subject: Refactoring which will help with future changes (A47) Change-Id: Ibc2d28f9f95966f77d4d7bdf9ae4688baaed5989 --- java/src/com/android/inputmethod/latin/LatinIME.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 722f323a2..127a07d13 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1708,8 +1708,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } if (!mWordComposer.isComposingWord()) { - // This is dead code: we can't come here with an empty word composer. - setPunctuationSuggestions(); + // We are never called with an empty word composer, but if because of a bug + // we are, what we should do here is just call updateBigramsPredictions. This will + // update the predictions if the "predict next word" option is on, or display + // punctuation signs if it's off. + updateBigramPredictions(); return; } -- cgit v1.2.3-83-g751a From e47c728dd517a150fe19340aebcfbd170f61f9f9 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 29 Jun 2012 15:12:16 +0900 Subject: Add a wrapper to updateSuggestions / Predictions (A48) The goal is to have those converge, as they contain almost 100% duplicated code. Change-Id: I6921791d47efce9fb396efd9626839d706664a91 --- .../com/android/inputmethod/latin/LatinIME.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 127a07d13..21f0ea007 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -208,13 +208,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; switch (msg.what) { case MSG_UPDATE_SUGGESTIONS: - latinIme.updateSuggestions(); + latinIme.updateSuggestionsOrPredictions(false /* isPredictions */); break; case MSG_UPDATE_SHIFT_STATE: switcher.updateShiftState(); break; case MSG_SET_BIGRAM_PREDICTIONS: - latinIme.updateBigramPredictions(); + latinIme.updateSuggestionsOrPredictions(true /* isPredictions */); break; } } @@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the composing word, reset the last composed word, tell the inputconnection about it. private void resetEntireInputState() { resetComposingState(true /* alsoResetLastComposedWord */); - updateSuggestions(); + updateSuggestionsOrPredictions(false /* isPredictions */); mConnection.finishComposingText(); } @@ -1026,7 +1026,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(), separatorCode, prevWord); } - updateSuggestions(); + updateSuggestionsOrPredictions(false /* isPredictions */); } public int getCurrentAutoCapsState() { @@ -1694,7 +1694,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - public void updateSuggestions() { + public void updateSuggestionsOrPredictions(final boolean isPredictions) { + if (isPredictions) { + updateBigramPredictions(); + } else { + updateSuggestions(); + } + } + + private void updateSuggestions() { mHandler.cancelUpdateSuggestions(); mHandler.cancelUpdateBigramPredictions(); @@ -1775,7 +1783,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Complete any pending suggestions query first if (mHandler.hasPendingUpdateSuggestions()) { mHandler.cancelUpdateSuggestions(); - updateSuggestions(); + updateSuggestionsOrPredictions(false /* isPredictions */); } final CharSequence autoCorrection = mWordComposer.getAutoCorrectionOrNull(); if (autoCorrection != null) { @@ -1885,7 +1893,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (!showingAddToDictionaryHint) { // If we're not showing the "Touch again to save", then show corrections again. // In case the cursor position doesn't change, make sure we show the suggestions again. - updateBigramPredictions(); + updateSuggestionsOrPredictions(true /* isPredictions */); // Updating the predictions right away may be slow and feel unresponsive on slower // terminals. On the other hand if we just postUpdateBigramPredictions() it will // take a noticeable delay to update them which may feel uneasy. -- cgit v1.2.3-83-g751a From 8f6c603b3bc9b1f81a0ab2299429d725b463b92f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 5 Jul 2012 10:44:10 +0900 Subject: Fix Keyboard.getKey as thread safe This is a follow up of Id962e670. Change-Id: I9e8542bff9e8faf57f934051fe612463c99ad61f --- .../com/android/inputmethod/keyboard/Keyboard.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 1b4cea2e7..1aec00129 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -185,19 +185,21 @@ public class Keyboard { if (code == CODE_UNSPECIFIED) { return null; } - final int index = mKeyCache.indexOfKey(code); - if (index >= 0) { - return mKeyCache.valueAt(index); - } + synchronized (mKeyCache) { + final int index = mKeyCache.indexOfKey(code); + if (index >= 0) { + return mKeyCache.valueAt(index); + } - for (final Key key : mKeys) { - if (key.mCode == code) { - mKeyCache.put(code, key); - return key; + for (final Key key : mKeys) { + if (key.mCode == code) { + mKeyCache.put(code, key); + return key; + } } + mKeyCache.put(code, null); + return null; } - mKeyCache.put(code, null); - return null; } public boolean hasKey(Key aKey) { -- cgit v1.2.3-83-g751a