aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2016-01-22 02:10:35 -0800
committerYohei Yukawa <yukawa@google.com>2016-01-22 02:24:28 -0800
commit809c93214bd85f038c3abb09d8dee60f778b7746 (patch)
treef446b8e5d79ffeb3d5f48d407245798647a71213 /java/src/com/android/inputmethod/latin/RichInputMethodManager.java
parent16645966a9509c77f02003e6e07c11d3aa3b0634 (diff)
downloadlatinime-809c93214bd85f038c3abb09d8dee60f778b7746.tar.gz
latinime-809c93214bd85f038c3abb09d8dee60f778b7746.tar.xz
latinime-809c93214bd85f038c3abb09d8dee60f778b7746.zip
Experimental automatic language switching support.
With this CL, LatinIME switches the current subtype from its enabled subtypes based on the first locale in EditorInfo#hintLocales. This functionality is still experimental, and will be triggered only when EditorInfo#hintLocales is specified by the application. Bug: 22859862 Change-Id: Ibd0559b370d8aa0d50d1bada8ecfdac0ed8db898
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);