aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorSatoshi Kataoka <satok@google.com>2012-07-05 16:53:56 +0900
committerSatoshi Kataoka <satok@google.com>2012-07-05 16:53:56 +0900
commit3d2f5f848764252ecd2f15c2d0d857c1fe7f7eaf (patch)
tree9d3db512a4541c8728545aa474647216d44765cb /java
parent1930f194c2f3b3a6182906c4378388025dff5686 (diff)
parent0726f466f7789ca112697adf6505870bb821ea17 (diff)
downloadlatinime-3d2f5f848764252ecd2f15c2d0d857c1fe7f7eaf.tar.gz
latinime-3d2f5f848764252ecd2f15c2d0d857c1fe7f7eaf.tar.xz
latinime-3d2f5f848764252ecd2f15c2d0d857c1fe7f7eaf.zip
Merge remote-tracking branch 'goog/master' into mergescript
Conflicts: java/src/com/android/inputmethod/keyboard/Keyboard.java java/src/com/android/inputmethod/latin/LatinIME.java java/src/com/android/inputmethod/latin/Suggest.java Change-Id: I73c1cec1f4bca5139372392e93d55081d814fa6c
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java22
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java31
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java28
-rw-r--r--java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java10
4 files changed, 43 insertions, 48 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 6fc630d05..6d85fea27 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -184,19 +184,21 @@ public class Keyboard {
if (code == CODE_UNSPECIFIED) {
return null;
}
- final Integer keyCode = code;
- if (mKeyCache.containsKey(keyCode)) {
- return mKeyCache.get(keyCode);
- }
+ 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(keyCode, 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(keyCode, null);
- return null;
}
public boolean hasKey(Key aKey) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6e3540485..5cbf40400 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;
}
}
@@ -1006,7 +1006,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();
}
@@ -1029,7 +1029,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() {
@@ -1697,7 +1697,18 @@ 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();
+
// Check if we have a suggestion engine attached.
if ((mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation))) {
if (mWordComposer.isComposingWord()) {
@@ -1711,7 +1722,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.cancelUpdateBigramPredictions();
if (!mWordComposer.isComposingWord()) {
- 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;
}
@@ -1775,7 +1790,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 +1900,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.
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 892245402..5aecc1371 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -272,31 +272,9 @@ public class Suggest implements Dictionary.WordCallback {
mBigramSuggestions = new ArrayList<SuggestedWordInfo>(PREF_MAX_BIGRAMS);
if (!TextUtils.isEmpty(prevWordForBigram)) {
- getAllBigrams(prevWordForBigram, wordComposer);
- if (TextUtils.isEmpty(consideredWord)) {
- // Nothing entered: return all bigrams for the previous word
- int insertCount = Math.min(mBigramSuggestions.size(), MAX_SUGGESTIONS);
- for (int i = 0; i < insertCount; ++i) {
- addBigramToSuggestions(mBigramSuggestions.get(i));
- }
- } else {
- // Word entered: return only bigrams that match the first char of the typed word
- final char currentChar = consideredWord.charAt(0);
- // TODO: Must pay attention to locale when changing case.
- // TODO: Use codepoint instead of char
- final char currentCharUpper = Character.toUpperCase(currentChar);
- int count = 0;
- final int bigramSuggestionSize = mBigramSuggestions.size();
- for (int i = 0; i < bigramSuggestionSize; i++) {
- final SuggestedWordInfo bigramSuggestion = mBigramSuggestions.get(i);
- final char bigramSuggestionFirstChar =
- (char)bigramSuggestion.codePointAt(0);
- if (bigramSuggestionFirstChar == currentChar
- || bigramSuggestionFirstChar == currentCharUpper) {
- addBigramToSuggestions(bigramSuggestion);
- if (++count > MAX_SUGGESTIONS) break;
- }
- }
+ for (final String key : mDictionaries.keySet()) {
+ final Dictionary dictionary = mDictionaries.get(key);
+ suggestionsSet.addAll(dictionary.getBigrams(wordComposer, prevWordForBigram));
}
}
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<String, Byte> 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) {