aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java32
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java48
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeUtils.java12
3 files changed, 52 insertions, 40 deletions
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index 2bc22a6f9..05f91688e 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -18,6 +18,8 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.res.Resources;
+import android.view.inputmethod.InputMethodSubtype;
+
import java.util.Locale;
@@ -33,6 +35,9 @@ public class SubtypeLocale {
private static String[] sExceptionKeys;
private static String[] sExceptionValues;
+ private static final String DEFAULT_KEYBOARD_LAYOUT_SET = "qwerty";
+ private static final char KEYBOARD_LAYOUT_SET_LOCALE_DELIMITER = ':';
+
private SubtypeLocale() {
// Intentional empty constructor for utility class.
}
@@ -72,7 +77,8 @@ public class SubtypeLocale {
return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
}
if (value.indexOf("%s") >= 0) {
- final String languageName = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
+ final String languageName = StringUtils.toTitleCase(
+ locale.getDisplayLanguage(locale), locale);
return String.format(value, languageName);
}
return value;
@@ -105,4 +111,28 @@ public class SubtypeLocale {
return StringUtils.toTitleCase(locale.getLanguage(), locale);
}
}
+
+ public static String getKeyboardLayoutSetName(InputMethodSubtype subtype) {
+ final String keyboardLayoutSet = subtype.getExtraValueOf(
+ LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET);
+ // TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
+ // fixed.
+ if (keyboardLayoutSet == null) return DEFAULT_KEYBOARD_LAYOUT_SET;
+ final int pos = keyboardLayoutSet.indexOf(KEYBOARD_LAYOUT_SET_LOCALE_DELIMITER);
+ return (pos > 0) ? keyboardLayoutSet.substring(0, pos) : keyboardLayoutSet;
+ }
+
+ public static String getKeyboardLayoutSetLocaleString(InputMethodSubtype subtype) {
+ final String keyboardLayoutSet = subtype.getExtraValueOf(
+ LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET);
+ // TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
+ // fixed.
+ if (keyboardLayoutSet == null) return subtype.getLocale();
+ final int pos = keyboardLayoutSet.indexOf(KEYBOARD_LAYOUT_SET_LOCALE_DELIMITER);
+ return (pos > 0) ? keyboardLayoutSet.substring(pos + 1) : subtype.getLocale();
+ }
+
+ public static Locale getKeyboardLayoutSetLocale(InputMethodSubtype subtype) {
+ return LocaleUtils.constructLocaleFromString(getKeyboardLayoutSetLocaleString(subtype));
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 99f0ee184..2ba742303 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -31,7 +31,6 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import java.util.ArrayList;
@@ -105,8 +104,8 @@ public class SubtypeSwitcher {
mInputLocaleStr = null;
mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
mAllEnabledSubtypesOfCurrentInputMethod = null;
- mNoLanguageSubtype = SubtypeUtils.findSubtypeByKeyboardLayoutSetLocale(
- service, SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY);
+ mNoLanguageSubtype = SubtypeUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ service, SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY, "qwerty");
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
mIsNetworkConnected = (info != null && info.isConnected());
@@ -129,14 +128,14 @@ public class SubtypeSwitcher {
// Reload enabledSubtypes from the framework.
private void updateEnabledSubtypes() {
- final String currentMode = getCurrentSubtypeMode();
+ final String currentMode = mCurrentSubtype.getMode();
boolean foundCurrentSubtypeBecameDisabled = true;
mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(
null, true);
mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
- final String locale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(ims);
+ final String locale = SubtypeLocale.getKeyboardLayoutSetLocaleString(ims);
final String mode = ims.getMode();
mLocaleSplitter.setString(locale);
if (mLocaleSplitter.hasNext()) {
@@ -166,7 +165,7 @@ public class SubtypeSwitcher {
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (
- KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ SubtypeLocale.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
@@ -189,16 +188,16 @@ public class SubtypeSwitcher {
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (
- KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ SubtypeLocale.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode())));
}
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
public void updateSubtype(InputMethodSubtype newSubtype) {
- final String newLocale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(newSubtype);
+ final String newLocale = SubtypeLocale.getKeyboardLayoutSetLocaleString(newSubtype);
final String newMode = newSubtype.getMode();
- final String oldMode = getCurrentSubtypeMode();
+ final String oldMode = mCurrentSubtype.getMode();
if (DBG) {
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
+ ", from: " + mInputLocaleStr + ", " + oldMode);
@@ -218,7 +217,7 @@ public class SubtypeSwitcher {
}
mCurrentSubtype = newSubtype;
- if (isKeyboardMode()) {
+ if (KEYBOARD_MODE.equals(mCurrentSubtype.getMode())) {
if (modeChanged || languageChanged) {
updateShortcutIME();
mService.onRefreshKeyboard();
@@ -233,12 +232,10 @@ public class SubtypeSwitcher {
}
Log.w(TAG, "Unknown subtype mode: " + newMode + "," + version + ", " + packageName
+ ". IME is already changed to other IME.");
- if (newSubtype != null) {
- Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
- Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
- Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
- Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
- }
+ Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
+ Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
+ Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
+ Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
}
}
@@ -282,10 +279,11 @@ public class SubtypeSwitcher {
if (token == null) {
return;
}
+ final InputMethodManagerCompatWrapper imm = mImm;
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- mImm.setInputMethodAndSubtype(token, imiId, subtype);
+ imm.setInputMethodAndSubtype(token, imiId, subtype);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@@ -385,22 +383,6 @@ public class SubtypeSwitcher {
return mIsDictionaryAvailable;
}
- // TODO: Remove this method
- private boolean isKeyboardMode() {
- return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
- }
-
- // TODO: Remove this method
- private String getCurrentSubtypeMode() {
- return mCurrentSubtype.getMode();
- }
-
- // TODO: Remove this method
- public boolean currentSubtypeContainsExtraValueKey(String key) {
- // If null, return what an empty ExtraValue would return : false.
- return mCurrentSubtype.containsExtraValueKey(key);
- }
-
public InputMethodSubtype getCurrentSubtype() {
return mCurrentSubtype;
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
index a747c9ad7..4ad72fb9f 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
@@ -21,7 +21,6 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import java.util.Collections;
import java.util.List;
@@ -125,21 +124,22 @@ public class SubtypeUtils {
throw new RuntimeException("Input method manager not found");
}
- for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
+ for (final InputMethodInfo imi : imm.getInputMethodList()) {
if (imi.getPackageName().equals(packageName))
return imi;
}
throw new RuntimeException("Can not find input method id for " + packageName);
}
- public static InputMethodSubtype findSubtypeByKeyboardLayoutSetLocale(
- Context context, Locale locale) {
+ public static InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(
+ Context context, Locale locale, String keyoardLayoutSet) {
final String localeString = locale.toString();
- final InputMethodInfo imi = SubtypeUtils.getInputMethodInfo(context.getPackageName());
+ final InputMethodInfo imi = getInputMethodInfo(context.getPackageName());
final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
- if (localeString.equals(KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype))) {
+ final String layout = SubtypeLocale.getKeyboardLayoutSetName(subtype);
+ if (localeString.equals(subtype.getLocale()) && keyoardLayoutSet.equals(layout)) {
return subtype;
}
}