Loading java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +36 −0 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,30 @@ public class DictionaryFacilitator { Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */, Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */, DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS.length); DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS.length); /** * Returns whether this facilitator is exactly for this list of locales. * @param locales the list of locales to test against * @return true if this facilitator handles exactly this list of locales, false otherwise */ public boolean isForLocales(final Locale[] locales) { if (locales.length != mDictionaryGroups.length) { return false; } for (final Locale locale : locales) { boolean found = false; for (final DictionaryGroup group : mDictionaryGroups) { if (locale.equals(group.mLocale)) { found = true; break; } } if (!found) { return false; } } return true; } /** /** * A group of dictionaries that work together for a single language. * A group of dictionaries that work together for a single language. */ */ Loading Loading @@ -199,6 +223,18 @@ public class DictionaryFacilitator { return mDictionaryGroups[0].mLocale; return mDictionaryGroups[0].mLocale; } } /** * Returns the primary locale among all currently active locales. BE CAREFUL using this. * * DO NOT USE THIS just because it's convenient. Use it when it's correct, for example when * choosing what dictionary to put a word in, or when changing the capitalization of a typed * string. * @return the primary active locale */ public Locale getPrimaryLocale() { return mDictionaryGroups[0].mLocale; } private static ExpandableBinaryDictionary getSubDict(final String dictType, private static ExpandableBinaryDictionary getSubDict(final String dictType, final Context context, final Locale locale, final File dictFile, final Context context, final Locale locale, final File dictFile, final String dictNamePrefix) { final String dictNamePrefix) { Loading java/src/com/android/inputmethod/latin/LatinIME.java +16 −17 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,6 @@ import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils; import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatchesAndSuggestions; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.JniUtils; Loading Loading @@ -253,7 +252,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // We need to re-evaluate the currently composing word in case the script has // We need to re-evaluate the currently composing word in case the script has // changed. // changed. postWaitForDictionaryLoad(); postWaitForDictionaryLoad(); latinIme.resetSuggest(); latinIme.resetDictionaryFacilitatorIfNecessary(); break; break; case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED: case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED: latinIme.mInputLogic.onUpdateTailBatchInputCompleted( latinIme.mInputLogic.onUpdateTailBatchInputCompleted( Loading Loading @@ -537,9 +536,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.onCreate(); mHandler.onCreate(); DEBUG = DebugFlags.DEBUG_ENABLED; DEBUG = DebugFlags.DEBUG_ENABLED; // TODO: Resolve mutual dependencies of {@link #loadSettings()} and {@link #initSuggest()}. // TODO: Resolve mutual dependencies of {@link #loadSettings()} and // {@link #resetDictionaryFacilitatorIfNecessary()}. loadSettings(); loadSettings(); resetSuggest(); resetDictionaryFacilitatorIfNecessary(); // Register to receive ringer mode change and network state change. // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. // Also receive installation and removal of a dictionary pack. Loading Loading @@ -580,7 +580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // been displayed. Opening dictionaries never affects responsivity as dictionaries are // been displayed. Opening dictionaries never affects responsivity as dictionaries are // asynchronously loaded. // asynchronously loaded. if (!mHandler.hasPendingReopenDictionaries()) { if (!mHandler.hasPendingReopenDictionaries()) { resetSuggestForLocale(locale); resetDictionaryFacilitatorForLocale(locale); } } mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList( mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList( true /* allowsImplicitlySelectedSubtypes */)); true /* allowsImplicitlySelectedSubtypes */)); Loading Loading @@ -621,8 +621,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } } } private void resetSuggest() { private void resetDictionaryFacilitatorIfNecessary() { final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); if (mDictionaryFacilitator.isForLocales(new Locale[] { switcherSubtypeLocale })) { return; } final String switcherLocaleStr = switcherSubtypeLocale.toString(); final String switcherLocaleStr = switcherSubtypeLocale.toString(); final Locale subtypeLocale; final Locale subtypeLocale; if (TextUtils.isEmpty(switcherLocaleStr)) { if (TextUtils.isEmpty(switcherLocaleStr)) { Loading @@ -637,15 +640,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { } else { subtypeLocale = switcherSubtypeLocale; subtypeLocale = switcherSubtypeLocale; } } resetSuggestForLocale(subtypeLocale); resetDictionaryFacilitatorForLocale(subtypeLocale); } } /** /** * Reset suggest by loading dictionaries for the locale and the current settings values. * Reset the facilitator by loading dictionaries for the locale and the current settings values. * * * @param locale the locale * @param locale the locale */ */ private void resetSuggestForLocale(final Locale locale) { // TODO: make sure the current settings always have the right locale, and read from them private void resetDictionaryFacilitatorForLocale(final Locale locale) { final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent(); mDictionaryFacilitator.resetDictionaries(this /* context */, locale, mDictionaryFacilitator.resetDictionaries(this /* context */, locale, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, Loading Loading @@ -901,12 +905,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(), mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(), currentSettingsValues); currentSettingsValues); // Note: the following does a round-trip IPC on the main thread: be careful resetDictionaryFacilitatorIfNecessary(); final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) { // TODO: Do this automatically. resetSuggest(); } // TODO[IL]: Can the following be moved to InputLogic#startInput? // TODO[IL]: Can the following be moved to InputLogic#startInput? if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( Loading Loading @@ -1554,7 +1553,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } final String wordToShow; final String wordToShow; if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) { if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) { wordToShow = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); wordToShow = word.toLowerCase(mDictionaryFacilitator.getPrimaryLocale()); } else { } else { wordToShow = word; wordToShow = word; } } Loading Loading @@ -1840,7 +1839,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void dumpDictionaryForDebug(final String dictName) { public void dumpDictionaryForDebug(final String dictName) { if (mDictionaryFacilitator.getLocale() == null) { if (mDictionaryFacilitator.getLocale() == null) { resetSuggest(); resetDictionaryFacilitatorIfNecessary(); } } mDictionaryFacilitator.dumpDictionaryForDebug(dictName); mDictionaryFacilitator.dumpDictionaryForDebug(dictName); } } Loading Loading
java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +36 −0 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,30 @@ public class DictionaryFacilitator { Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */, Arrays.copyOfRange(DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS, 1 /* start */, DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS.length); DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS.length); /** * Returns whether this facilitator is exactly for this list of locales. * @param locales the list of locales to test against * @return true if this facilitator handles exactly this list of locales, false otherwise */ public boolean isForLocales(final Locale[] locales) { if (locales.length != mDictionaryGroups.length) { return false; } for (final Locale locale : locales) { boolean found = false; for (final DictionaryGroup group : mDictionaryGroups) { if (locale.equals(group.mLocale)) { found = true; break; } } if (!found) { return false; } } return true; } /** /** * A group of dictionaries that work together for a single language. * A group of dictionaries that work together for a single language. */ */ Loading Loading @@ -199,6 +223,18 @@ public class DictionaryFacilitator { return mDictionaryGroups[0].mLocale; return mDictionaryGroups[0].mLocale; } } /** * Returns the primary locale among all currently active locales. BE CAREFUL using this. * * DO NOT USE THIS just because it's convenient. Use it when it's correct, for example when * choosing what dictionary to put a word in, or when changing the capitalization of a typed * string. * @return the primary active locale */ public Locale getPrimaryLocale() { return mDictionaryGroups[0].mLocale; } private static ExpandableBinaryDictionary getSubDict(final String dictType, private static ExpandableBinaryDictionary getSubDict(final String dictType, final Context context, final Locale locale, final File dictFile, final Context context, final Locale locale, final File dictFile, final String dictNamePrefix) { final String dictNamePrefix) { Loading
java/src/com/android/inputmethod/latin/LatinIME.java +16 −17 Original line number Original line Diff line number Diff line Loading @@ -89,7 +89,6 @@ import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils; import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DialogUtils; import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatchesAndSuggestions; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.JniUtils; Loading Loading @@ -253,7 +252,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // We need to re-evaluate the currently composing word in case the script has // We need to re-evaluate the currently composing word in case the script has // changed. // changed. postWaitForDictionaryLoad(); postWaitForDictionaryLoad(); latinIme.resetSuggest(); latinIme.resetDictionaryFacilitatorIfNecessary(); break; break; case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED: case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED: latinIme.mInputLogic.onUpdateTailBatchInputCompleted( latinIme.mInputLogic.onUpdateTailBatchInputCompleted( Loading Loading @@ -537,9 +536,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.onCreate(); mHandler.onCreate(); DEBUG = DebugFlags.DEBUG_ENABLED; DEBUG = DebugFlags.DEBUG_ENABLED; // TODO: Resolve mutual dependencies of {@link #loadSettings()} and {@link #initSuggest()}. // TODO: Resolve mutual dependencies of {@link #loadSettings()} and // {@link #resetDictionaryFacilitatorIfNecessary()}. loadSettings(); loadSettings(); resetSuggest(); resetDictionaryFacilitatorIfNecessary(); // Register to receive ringer mode change and network state change. // Register to receive ringer mode change and network state change. // Also receive installation and removal of a dictionary pack. // Also receive installation and removal of a dictionary pack. Loading Loading @@ -580,7 +580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // been displayed. Opening dictionaries never affects responsivity as dictionaries are // been displayed. Opening dictionaries never affects responsivity as dictionaries are // asynchronously loaded. // asynchronously loaded. if (!mHandler.hasPendingReopenDictionaries()) { if (!mHandler.hasPendingReopenDictionaries()) { resetSuggestForLocale(locale); resetDictionaryFacilitatorForLocale(locale); } } mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList( mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList( true /* allowsImplicitlySelectedSubtypes */)); true /* allowsImplicitlySelectedSubtypes */)); Loading Loading @@ -621,8 +621,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } } } private void resetSuggest() { private void resetDictionaryFacilitatorIfNecessary() { final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); if (mDictionaryFacilitator.isForLocales(new Locale[] { switcherSubtypeLocale })) { return; } final String switcherLocaleStr = switcherSubtypeLocale.toString(); final String switcherLocaleStr = switcherSubtypeLocale.toString(); final Locale subtypeLocale; final Locale subtypeLocale; if (TextUtils.isEmpty(switcherLocaleStr)) { if (TextUtils.isEmpty(switcherLocaleStr)) { Loading @@ -637,15 +640,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { } else { subtypeLocale = switcherSubtypeLocale; subtypeLocale = switcherSubtypeLocale; } } resetSuggestForLocale(subtypeLocale); resetDictionaryFacilitatorForLocale(subtypeLocale); } } /** /** * Reset suggest by loading dictionaries for the locale and the current settings values. * Reset the facilitator by loading dictionaries for the locale and the current settings values. * * * @param locale the locale * @param locale the locale */ */ private void resetSuggestForLocale(final Locale locale) { // TODO: make sure the current settings always have the right locale, and read from them private void resetDictionaryFacilitatorForLocale(final Locale locale) { final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent(); mDictionaryFacilitator.resetDictionaries(this /* context */, locale, mDictionaryFacilitator.resetDictionaries(this /* context */, locale, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts, Loading Loading @@ -901,12 +905,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(), mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(), currentSettingsValues); currentSettingsValues); // Note: the following does a round-trip IPC on the main thread: be careful resetDictionaryFacilitatorIfNecessary(); final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) { // TODO: Do this automatically. resetSuggest(); } // TODO[IL]: Can the following be moved to InputLogic#startInput? // TODO[IL]: Can the following be moved to InputLogic#startInput? if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( Loading Loading @@ -1554,7 +1553,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } final String wordToShow; final String wordToShow; if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) { if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) { wordToShow = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale()); wordToShow = word.toLowerCase(mDictionaryFacilitator.getPrimaryLocale()); } else { } else { wordToShow = word; wordToShow = word; } } Loading Loading @@ -1840,7 +1839,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void dumpDictionaryForDebug(final String dictName) { public void dumpDictionaryForDebug(final String dictName) { if (mDictionaryFacilitator.getLocale() == null) { if (mDictionaryFacilitator.getLocale() == null) { resetSuggest(); resetDictionaryFacilitatorIfNecessary(); } } mDictionaryFacilitator.dumpDictionaryForDebug(dictName); mDictionaryFacilitator.dumpDictionaryForDebug(dictName); } } Loading