aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java18
-rw-r--r--java/src/com/android/inputmethod/latin/WhitelistDictionary.java23
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java11
3 files changed, 27 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 208fd13ec..f6f55819d 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -113,14 +113,15 @@ public class Suggest implements Dictionary.WordCallback {
initAsynchronously(context, dictionaryResId, locale);
}
- /* package for test */ Suggest(Context context, File dictionary, long startOffset, long length,
- Flag[] flagArray) {
+ /* package for test */ Suggest(final Context context, final File dictionary,
+ final long startOffset, final long length, final Flag[] flagArray,
+ final Locale locale) {
initSynchronously(null, DictionaryFactory.createDictionaryForTest(context, dictionary,
- startOffset, length, flagArray));
+ startOffset, length, flagArray), locale);
}
- private void initWhitelistAndAutocorrectAndPool(final Context context) {
- mWhiteListDictionary = WhitelistDictionary.init(context);
+ private void initWhitelistAndAutocorrectAndPool(final Context context, final Locale locale) {
+ mWhiteListDictionary = new WhitelistDictionary(context, locale);
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_WHITELIST, mWhiteListDictionary);
mAutoCorrection = new AutoCorrection();
StringBuilderPool.ensureCapacity(mPrefMaxSuggestions, getApproxMaxWordLength());
@@ -132,14 +133,15 @@ public class Suggest implements Dictionary.WordCallback {
// TODO: read the whitelist and init the pool asynchronously too.
// initPool should be done asynchronously now that the pool is thread-safe.
- initWhitelistAndAutocorrectAndPool(context);
+ initWhitelistAndAutocorrectAndPool(context, locale);
}
- private void initSynchronously(Context context, Dictionary mainDict) {
+ private void initSynchronously(final Context context, final Dictionary mainDict,
+ final Locale locale) {
mMainDict = mainDict;
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_MAIN, mainDict);
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_MAIN, mainDict);
- initWhitelistAndAutocorrectAndPool(context);
+ initWhitelistAndAutocorrectAndPool(context, locale);
}
private void addOrReplaceDictionary(Map<String, Dictionary> dictionaries, String key,
diff --git a/java/src/com/android/inputmethod/latin/WhitelistDictionary.java b/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
index 639c96681..93474b654 100644
--- a/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
+++ b/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
@@ -17,6 +17,7 @@
package com.android.inputmethod.latin;
import android.content.Context;
+import android.content.res.Resources;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -24,6 +25,7 @@ import android.util.Pair;
import com.android.inputmethod.keyboard.ProximityInfo;
import java.util.HashMap;
+import java.util.Locale;
public class WhitelistDictionary extends Dictionary {
@@ -33,22 +35,13 @@ public class WhitelistDictionary extends Dictionary {
private final HashMap<String, Pair<Integer, String>> mWhitelistWords =
new HashMap<String, Pair<Integer, String>>();
- private static final WhitelistDictionary sInstance = new WhitelistDictionary();
-
- private WhitelistDictionary() {
- }
-
- public static WhitelistDictionary init(Context context) {
- synchronized (sInstance) {
- if (context != null) {
- // Wordlist is initialized by the proper language in Suggestion.java#init
- sInstance.initWordlist(
- context.getResources().getStringArray(R.array.wordlist_whitelist));
- } else {
- sInstance.mWhitelistWords.clear();
- }
+ public WhitelistDictionary(final Context context, final Locale locale) {
+ final Resources res = context.getResources();
+ final Locale previousLocale = LocaleUtils.setSystemLocale(res, locale);
+ if (context != null) {
+ initWordlist(context.getResources().getStringArray(R.array.wordlist_whitelist));
}
- return sInstance;
+ LocaleUtils.setSystemLocale(res, previousLocale);
}
private void initWordlist(String[] wordlist) {
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index b197c5bea..4d569b808 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -156,6 +156,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// }
return true;
}
+ if (insertIndex >= mMaxLength) {
+ // We found a suggestion, but its score is too weak to be kept considering
+ // the suggestion limit.
+ return true;
+ }
// Compute the normalized score and skip this word if it's normalized score does not
// make the threshold.
@@ -438,8 +443,10 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
Log.i(TAG, "IsInDict = " + isInDict);
Log.i(TAG, "LooksLikeTypo = " + (!isInDict));
Log.i(TAG, "HasLikelySuggestions = " + result.mHasLikelySuggestions);
- for (String suggestion : result.mSuggestions) {
- Log.i(TAG, suggestion);
+ if (null != result.mSuggestions) {
+ for (String suggestion : result.mSuggestions) {
+ Log.i(TAG, suggestion);
+ }
}
}