aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputMethodManager.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index ef946c8bc..3beb51d68 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -32,6 +32,7 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils;
@@ -428,6 +429,46 @@ public class RichInputMethodManager {
return null;
}
+ public InputMethodSubtype findSubtypeByLocale(final Locale locale) {
+ // Find the best subtype based on a straightforward matching algorithm.
+ // TODO: Use LocaleList#getFirstMatch() instead.
+ final List<InputMethodSubtype> subtypes =
+ getMyEnabledInputMethodSubtypeList(true /* allowsImplicitlySelectedSubtypes */);
+ final int count = subtypes.size();
+ for (int i = 0; i < count; ++i) {
+ final InputMethodSubtype subtype = subtypes.get(i);
+ final Locale subtypeLocale = InputMethodSubtypeCompatUtils.getLocaleObject(subtype);
+ if (subtypeLocale.equals(locale)) {
+ return subtype;
+ }
+ }
+ for (int i = 0; i < count; ++i) {
+ final InputMethodSubtype subtype = subtypes.get(i);
+ final Locale subtypeLocale = InputMethodSubtypeCompatUtils.getLocaleObject(subtype);
+ if (subtypeLocale.getLanguage().equals(locale.getLanguage()) &&
+ subtypeLocale.getCountry().equals(locale.getCountry()) &&
+ subtypeLocale.getVariant().equals(locale.getVariant())) {
+ return subtype;
+ }
+ }
+ for (int i = 0; i < count; ++i) {
+ final InputMethodSubtype subtype = subtypes.get(i);
+ final Locale subtypeLocale = InputMethodSubtypeCompatUtils.getLocaleObject(subtype);
+ if (subtypeLocale.getLanguage().equals(locale.getLanguage()) &&
+ subtypeLocale.getCountry().equals(locale.getCountry())) {
+ return subtype;
+ }
+ }
+ for (int i = 0; i < count; ++i) {
+ final InputMethodSubtype subtype = subtypes.get(i);
+ final Locale subtypeLocale = InputMethodSubtypeCompatUtils.getLocaleObject(subtype);
+ if (subtypeLocale.getLanguage().equals(locale.getLanguage())) {
+ return subtype;
+ }
+ }
+ return null;
+ }
+
public void setInputMethodAndSubtype(final IBinder token, final InputMethodSubtype subtype) {
mImmWrapper.mImm.setInputMethodAndSubtype(
token, getInputMethodIdOfThisIme(), subtype);