aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java54
1 files changed, 32 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 5e2a04124..8a2341d5e 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -60,13 +60,11 @@ public class Suggest {
// Locale used for upper- and title-casing words
private final Locale mLocale;
- private final SuggestInitializationListener mListener;
public Suggest(final Context context, final Locale locale,
final SuggestInitializationListener listener) {
- initAsynchronously(context, locale);
+ initAsynchronously(context, locale, listener);
mLocale = locale;
- mListener = listener;
}
/* package for test */ Suggest(final Context context, final File dictionary,
@@ -74,7 +72,6 @@ public class Suggest {
final Dictionary mainDict = DictionaryFactory.createDictionaryForTest(context, dictionary,
startOffset, length /* useFullEditDistance */, false, locale);
mLocale = locale;
- mListener = null;
mMainDictionary = mainDict;
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, mainDict);
initWhitelistAndAutocorrectAndPool(context, locale);
@@ -85,8 +82,9 @@ public class Suggest {
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_WHITELIST, mWhiteListDictionary);
}
- private void initAsynchronously(final Context context, final Locale locale) {
- resetMainDict(context, locale);
+ private void initAsynchronously(final Context context, final Locale locale,
+ final SuggestInitializationListener listener) {
+ resetMainDict(context, locale, listener);
// TODO: read the whitelist and init the pool asynchronously too.
// initPool should be done asynchronously now that the pool is thread-safe.
@@ -104,10 +102,11 @@ public class Suggest {
}
}
- public void resetMainDict(final Context context, final Locale locale) {
+ public void resetMainDict(final Context context, final Locale locale,
+ final SuggestInitializationListener listener) {
mMainDictionary = null;
- if (mListener != null) {
- mListener.onUpdateMainDictionaryAvailability(hasMainDictionary());
+ if (listener != null) {
+ listener.onUpdateMainDictionaryAvailability(hasMainDictionary());
}
new Thread("InitializeBinaryDictionary") {
@Override
@@ -116,8 +115,8 @@ public class Suggest {
DictionaryFactory.createMainDictionaryFromManager(context, locale);
addOrReplaceDictionary(mDictionaries, Dictionary.TYPE_MAIN, newMainDict);
mMainDictionary = newMainDict;
- if (mListener != null) {
- mListener.onUpdateMainDictionaryAvailability(hasMainDictionary());
+ if (listener != null) {
+ listener.onUpdateMainDictionaryAvailability(hasMainDictionary());
}
}
}.start();
@@ -209,23 +208,34 @@ public class Suggest {
wordComposerForLookup, prevWordForBigram, proximityInfo));
}
- // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
- // but still autocorrected from - in the case the whitelist only capitalizes the word.
- // The whitelist should be case-insensitive, so it's not possible to be consistent with
- // a boolean flag. Right now this is handled with a slight hack in
- // WhitelistDictionary#shouldForciblyAutoCorrectFrom.
- final boolean allowsToBeAutoCorrected = AutoCorrection.isWhitelistedOrNotAWord(
- mDictionaries, consideredWord, wordComposer.isFirstCharCapitalized());
-
- final CharSequence whitelistedWord =
+ final CharSequence whitelistedWordFromWhitelistDictionary =
mWhiteListDictionary.getWhitelistedWord(consideredWord);
- if (whitelistedWord != null) {
+ if (whitelistedWordFromWhitelistDictionary != null) {
// MAX_SCORE ensures this will be considered strong enough to be auto-corrected
- suggestionsSet.add(new SuggestedWordInfo(whitelistedWord,
+ suggestionsSet.add(new SuggestedWordInfo(whitelistedWordFromWhitelistDictionary,
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST,
Dictionary.TYPE_WHITELIST));
}
+ final CharSequence whitelistedWord;
+ if (suggestionsSet.isEmpty()) {
+ whitelistedWord = null;
+ } else if (SuggestedWordInfo.KIND_WHITELIST != suggestionsSet.first().mKind) {
+ whitelistedWord = null;
+ } else {
+ whitelistedWord = suggestionsSet.first().mWord;
+ }
+
+ // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
+ // but still autocorrected from - in the case the whitelist only capitalizes the word.
+ // The whitelist should be case-insensitive, so it's not possible to be consistent with
+ // a boolean flag. Right now this is handled with a slight hack in
+ // WhitelistDictionary#shouldForciblyAutoCorrectFrom.
+ final boolean allowsToBeAutoCorrected = (null != whitelistedWord
+ && !whitelistedWord.equals(consideredWord))
+ || AutoCorrection.isNotAWord(mDictionaries, consideredWord,
+ wordComposer.isFirstCharCapitalized());
+
final boolean hasAutoCorrection;
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
// any attempt to do auto-correction is already shielded with a test for this flag; at the