diff options
Diffstat (limited to 'java/src')
5 files changed, 62 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index d97989d9c..25afef1e6 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -131,16 +131,11 @@ public class SuggestionSpanUtils { sameAsTyped = true; } } - // TODO: Share the implementation for checking typed word validity between the IME - // and the spell checker. - final int flag = (sameAsTyped && !suggestedWords.mTypedWordValid) - ? (OBJ_FLAG_EASY_CORRECT | OBJ_FLAG_MISSPELLED) - : 0; // TODO: We should avoid adding suggestion span candidates that came from the bigram // prediction. final Object[] args = - { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), flag, + { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0, (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); if (ss == null) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b30d1e35c..ddf21f749 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -442,9 +442,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); - mImm.setAdditionalInputMethodSubtypes( - SubtypeUtils.getInputMethodId(getPackageName()), - mSettingsValues.getPrefefinedAdditionalSubtypes()); + SubtypeUtils.setAditionalInputMethodSubtypes( + this, mSettingsValues.getPrefefinedAdditionalSubtypes()); // TODO: remove the following when it's not needed by updateCorrectionMode() any more mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index 37da5e846..03780419e 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -68,14 +68,14 @@ public class SubtypeLocale { } if (isNoLanguage(subtype)) { - return getKeyboardLayoutSetName(subtype).toUpperCase(); + return getKeyboardLayoutSetDisplayName(subtype); } final Locale locale = getSubtypeLocale(subtype); final String language = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); if (AdditionalSubtype.isAdditionalSubtype(subtype)) { return String.format("%s (%s)", - language, getKeyboardLayoutSetName(subtype).toUpperCase()); + language, getKeyboardLayoutSetDisplayName(subtype)); } return StringUtils.toTitleCase(locale.getDisplayName(locale), locale); } @@ -83,7 +83,7 @@ public class SubtypeLocale { // Get InputMethodSubtype's middle display name in its locale. public static String getMiddleDisplayName(InputMethodSubtype subtype) { if (isNoLanguage(subtype)) { - return getKeyboardLayoutSetName(subtype).toUpperCase(); + return getKeyboardLayoutSetDisplayName(subtype); } final Locale locale = getSubtypeLocale(subtype); return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); @@ -108,6 +108,10 @@ public class SubtypeLocale { return LocaleUtils.constructLocaleFromString(localeString); } + public static String getKeyboardLayoutSetDisplayName(InputMethodSubtype subtype) { + return getKeyboardLayoutSetName(subtype).toUpperCase(); + } + public static String getKeyboardLayoutSetName(InputMethodSubtype subtype) { final String keyboardLayoutSet = subtype.getExtraValueOf( LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET); diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java index 4d0f1c262..a361027af 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java +++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java @@ -146,4 +146,14 @@ public class SubtypeUtils { throw new RuntimeException("Can't find subtype for locale " + localeString + " and keyboard layout " + keyoardLayoutSet); } + + public static void setAditionalInputMethodSubtypes(Context context, + InputMethodSubtype[] subtypes) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) { + throw new RuntimeException("Input method manager not found"); + } + final String imiId = getInputMethodId(context.getPackageName()); + imm.setAdditionalInputMethodSubtypes(imiId, subtypes); + } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 34e214da7..aa25faef5 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -18,11 +18,11 @@ package com.android.inputmethod.latin.spellcheck; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Resources; import android.preference.PreferenceManager; import android.service.textservice.SpellCheckerService; import android.text.TextUtils; import android.util.Log; +import android.util.LruCache; import android.view.textservice.SuggestionsInfo; import android.view.textservice.TextInfo; @@ -455,6 +455,35 @@ public class AndroidSpellCheckerService extends SpellCheckerService private final AndroidSpellCheckerService mService; + private final SuggestionsCache mSuggestionsCache = new SuggestionsCache(); + + private static class SuggestionsParams { + public final String[] mSuggestions; + public final int mFlags; + public SuggestionsParams(String[] suggestions, int flags) { + mSuggestions = suggestions; + mFlags = flags; + } + } + + private static class SuggestionsCache { + private static final int MAX_CACHE_SIZE = 50; + // TODO: support bigram + private final LruCache<String, SuggestionsParams> mUnigramSuggestionsInfoCache = + new LruCache<String, SuggestionsParams>(MAX_CACHE_SIZE); + + public SuggestionsParams getSuggestionsFromCache(String query) { + return mUnigramSuggestionsInfoCache.get(query); + } + + public void putSuggestionsToCache(String query, String[] suggestions, int flags) { + if (suggestions == null || TextUtils.isEmpty(query)) { + return; + } + mUnigramSuggestionsInfoCache.put(query, new SuggestionsParams(suggestions, flags)); + } + } + AndroidSpellCheckerSession(final AndroidSpellCheckerService service) { mService = service; } @@ -546,6 +575,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService final int suggestionsLimit) { try { final String text = textInfo.getText(); + final SuggestionsParams cachedSuggestionsParams = + mSuggestionsCache.getSuggestionsFromCache(text); + if (cachedSuggestionsParams != null) { + if (DBG) { + Log.d(TAG, "Cache hit: " + text + ", " + cachedSuggestionsParams.mFlags); + } + return new SuggestionsInfo( + cachedSuggestionsParams.mFlags, cachedSuggestionsParams.mSuggestions); + } if (shouldFilterOut(text, mScript)) { DictAndProximity dictInfo = null; @@ -628,7 +666,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService ? SuggestionsInfoCompatUtils .getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS() : 0); - return new SuggestionsInfo(flags, result.mSuggestions); + final SuggestionsInfo retval = new SuggestionsInfo(flags, result.mSuggestions); + mSuggestionsCache.putSuggestionsToCache(text, result.mSuggestions, flags); + return retval; } catch (RuntimeException e) { // Don't kill the keyboard if there is a bug in the spell checker if (DBG) { |