aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-02 15:08:16 +0900
committerJean Chalard <jchalard@google.com>2014-10-02 18:15:35 +0900
commit1c0876dc49eee44170cb86ba3d78e759d5bbd573 (patch)
treec8d8f37c2e5daac5243a06c4d30959ef31e7a802 /java/src/com/android/inputmethod
parentc91166de54137f1d22959ec61f8468fc4a4e1444 (diff)
downloadlatinime-1c0876dc49eee44170cb86ba3d78e759d5bbd573.tar.gz
latinime-1c0876dc49eee44170cb86ba3d78e759d5bbd573.tar.xz
latinime-1c0876dc49eee44170cb86ba3d78e759d5bbd573.zip
[ML12] Add a getPrimaryLocale function and some refactoring
Bug: 11230254 Change-Id: Ic579b93702c24f47e6cdb0c9a4da6b11f1fa76c8
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFacilitator.java36
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java33
2 files changed, 52 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
index 6dc1e8273..1f0317288 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java
@@ -99,6 +99,30 @@ public class DictionaryFacilitator {
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.
*/
private static class DictionaryGroup {
@@ -199,6 +223,18 @@ public class DictionaryFacilitator {
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,
final Context context, final Locale locale, final File dictFile,
final String dictNamePrefix) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 099d4850e..714f62f3e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -89,7 +89,6 @@ import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils;
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.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils;
@@ -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
// changed.
postWaitForDictionaryLoad();
- latinIme.resetSuggest();
+ latinIme.resetDictionaryFacilitatorIfNecessary();
break;
case MSG_UPDATE_TAIL_BATCH_INPUT_COMPLETED:
latinIme.mInputLogic.onUpdateTailBatchInputCompleted(
@@ -537,9 +536,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.onCreate();
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();
- resetSuggest();
+ resetDictionaryFacilitatorIfNecessary();
// Register to receive ringer mode change and network state change.
// Also receive installation and removal of a dictionary pack.
@@ -580,7 +580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// been displayed. Opening dictionaries never affects responsivity as dictionaries are
// asynchronously loaded.
if (!mHandler.hasPendingReopenDictionaries()) {
- resetSuggestForLocale(locale);
+ resetDictionaryFacilitatorForLocale(locale);
}
mDictionaryFacilitator.updateEnabledSubtypes(mRichImm.getMyEnabledInputMethodSubtypeList(
true /* allowsImplicitlySelectedSubtypes */));
@@ -621,8 +621,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void resetSuggest() {
+ private void resetDictionaryFacilitatorIfNecessary() {
final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
+ if (mDictionaryFacilitator.isForLocales(new Locale[] { switcherSubtypeLocale })) {
+ return;
+ }
final String switcherLocaleStr = switcherSubtypeLocale.toString();
final Locale subtypeLocale;
if (TextUtils.isEmpty(switcherLocaleStr)) {
@@ -637,15 +640,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else {
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
*/
- 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();
mDictionaryFacilitator.resetDictionaries(this /* context */, locale,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
@@ -901,12 +905,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(),
currentSettingsValues);
- // Note: the following does a round-trip IPC on the main thread: be careful
- final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
- if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) {
- // TODO: Do this automatically.
- resetSuggest();
- }
+ resetDictionaryFacilitatorIfNecessary();
// TODO[IL]: Can the following be moved to InputLogic#startInput?
if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess(
@@ -1554,7 +1553,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
final String wordToShow;
if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) {
- wordToShow = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
+ wordToShow = word.toLowerCase(mDictionaryFacilitator.getPrimaryLocale());
} else {
wordToShow = word;
}
@@ -1840,7 +1839,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void dumpDictionaryForDebug(final String dictName) {
if (mDictionaryFacilitator.getLocale() == null) {
- resetSuggest();
+ resetDictionaryFacilitatorIfNecessary();
}
mDictionaryFacilitator.dumpDictionaryForDebug(dictName);
}