Fix on-commit bug in AOSP keyboard.

Bug 21272977.

Change-Id: Id561040c29a7f2576cd9ef0514c31751a4360ef8
main
Dan Zivkovic 2015-05-19 10:45:19 -07:00
parent 8796012ac7
commit 0e15ff6b48
1 changed files with 23 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import com.android.inputmethod.latin.NgramContext.WordInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.ComposedData; import com.android.inputmethod.latin.common.ComposedData;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.personalization.UserHistoryDictionary; import com.android.inputmethod.latin.personalization.UserHistoryDictionary;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion; import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import com.android.inputmethod.latin.utils.ExecutorUtils; import com.android.inputmethod.latin.utils.ExecutorUtils;
@ -509,10 +510,27 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
private void putWordIntoValidSpellingWordCache(final String caller, final String word) { private void putWordIntoValidSpellingWordCache(
final String spellingWord = word.toLowerCase(getLocale()); @Nonnull final String caller,
final boolean isValid = isValidSpellingWord(spellingWord); @Nonnull final String originalWord) {
mValidSpellingWordWriteCache.put(spellingWord, isValid); if (mValidSpellingWordWriteCache == null) {
return;
}
final String lowerCaseWord = originalWord.toLowerCase(getLocale());
final boolean lowerCaseValid = isValidSpellingWord(lowerCaseWord);
mValidSpellingWordWriteCache.put(lowerCaseWord, lowerCaseValid);
final String capitalWord =
StringUtils.capitalizeFirstAndDowncaseRest(originalWord, getLocale());
final boolean capitalValid;
if (lowerCaseValid) {
// The lower case form of the word is valid, so the upper case must be valid.
capitalValid = true;
} else {
capitalValid = isValidSpellingWord(capitalWord);
}
mValidSpellingWordWriteCache.put(capitalWord, capitalValid);
} }
private void addWordToUserHistory(final DictionaryGroup dictionaryGroup, private void addWordToUserHistory(final DictionaryGroup dictionaryGroup,
@ -620,8 +638,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
public boolean isValidSpellingWord(final String word) { public boolean isValidSpellingWord(final String word) {
if (mValidSpellingWordReadCache != null) { if (mValidSpellingWordReadCache != null) {
final String spellingWord = word.toLowerCase(getLocale()); final Boolean cachedValue = mValidSpellingWordReadCache.get(word);
final Boolean cachedValue = mValidSpellingWordReadCache.get(spellingWord);
if (cachedValue != null) { if (cachedValue != null) {
return cachedValue; return cachedValue;
} }