From 6b23749dec8f71ad277911d62cd1389e8c57767d Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 20 Feb 2014 12:54:26 +0900 Subject: [PATCH] Check all enabled IME's subtypes to enable personalization. Bug: 13067743 Change-Id: I6fc68b5151430a5ab51777f4c381e20f5a657924 --- .../android/inputmethod/latin/LatinIME.java | 2 +- .../inputmethod/latin/SubtypeSwitcher.java | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5d90e10a0..b12f8700e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -541,7 +541,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen shouldKeepUserHistoryDictionaries = true; // TODO: Eliminate this restriction shouldKeepPersonalizationDictionaries = - mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypes(); + mSubtypeSwitcher.isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes(); } else { shouldKeepUserHistoryDictionaries = false; shouldKeepPersonalizationDictionaries = false; diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 860575a1f..935dd9667 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -37,9 +37,11 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; public final class SubtypeSwitcher { private static boolean DBG = LatinImeLogger.sDBG; @@ -273,12 +275,26 @@ public final class SubtypeSwitcher { return mNeedsToDisplayLanguage.getValue(); } - public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypes() { + public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() { final Locale systemLocale = mResources.getConfiguration().locale; - final List enabledSubtypesOfThisIme = - mRichImm.getMyEnabledInputMethodSubtypeList(true); - for (final InputMethodSubtype subtype : enabledSubtypesOfThisIme) { - if (!systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) { + final Set enabledSubtypesOfEnabledImes = + new HashSet(); + final InputMethodManager inputMethodManager = mRichImm.getInputMethodManager(); + final List enabledInputMethodInfoList = + inputMethodManager.getEnabledInputMethodList(); + for (final InputMethodInfo info : enabledInputMethodInfoList) { + final List enabledSubtypes = + inputMethodManager.getEnabledInputMethodSubtypeList( + info, true /* allowsImplicitlySelectedSubtypes */); + if (enabledSubtypes.isEmpty()) { + // An IME with no subtypes is found. + return false; + } + enabledSubtypesOfEnabledImes.addAll(enabledSubtypes); + } + for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) { + if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty() + && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) { return false; } }