aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/compat/AbstractCompatWrapper.java39
-rw-r--r--java/src/com/android/inputmethod/compat/CompatUtils.java13
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java72
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java16
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java188
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSet.java1
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java9
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java66
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeUtils.java19
9 files changed, 51 insertions, 372 deletions
diff --git a/java/src/com/android/inputmethod/compat/AbstractCompatWrapper.java b/java/src/com/android/inputmethod/compat/AbstractCompatWrapper.java
deleted file mode 100644
index 2c31c55b0..000000000
--- a/java/src/com/android/inputmethod/compat/AbstractCompatWrapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.compat;
-
-import android.util.Log;
-
-public abstract class AbstractCompatWrapper {
- private static final String TAG = AbstractCompatWrapper.class.getSimpleName();
- protected final Object mObj;
-
- public AbstractCompatWrapper(Object obj) {
- if (obj == null) {
- Log.e(TAG, "Invalid input to AbstractCompatWrapper");
- }
- mObj = obj;
- }
-
- public Object getOriginalObject() {
- return mObj;
- }
-
- public boolean hasOriginalObject() {
- return mObj != null;
- }
-}
diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java
index f1f6a1220..ce427e9c9 100644
--- a/java/src/com/android/inputmethod/compat/CompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/CompatUtils.java
@@ -23,8 +23,6 @@ import android.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
public class CompatUtils {
private static final String TAG = CompatUtils.class.getSimpleName();
@@ -131,15 +129,4 @@ public class CompatUtils {
Log.e(TAG, "Exception in setFieldValue: " + e.getClass().getSimpleName());
}
}
-
- public static List<InputMethodSubtypeCompatWrapper> copyInputMethodSubtypeListToWrapper(
- Object listObject) {
- if (!(listObject instanceof List<?>)) return null;
- final List<InputMethodSubtypeCompatWrapper> subtypes =
- new ArrayList<InputMethodSubtypeCompatWrapper>();
- for (Object o: (List<?>)listObject) {
- subtypes.add(new InputMethodSubtypeCompatWrapper(o));
- }
- return subtypes;
- }
}
diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
index 0f03c2ef8..7f0b071a3 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
@@ -21,10 +21,9 @@ import android.os.IBinder;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
+import android.view.inputmethod.InputMethodSubtype;
import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,21 +31,6 @@ import java.util.Map;
// performance.
public class InputMethodManagerCompatWrapper {
private static final String TAG = InputMethodManagerCompatWrapper.class.getSimpleName();
- private static final Method METHOD_getCurrentInputMethodSubtype =
- CompatUtils.getMethod(InputMethodManager.class, "getCurrentInputMethodSubtype");
- private static final Method METHOD_getLastInputMethodSubtype =
- CompatUtils.getMethod(InputMethodManager.class, "getLastInputMethodSubtype");
- private static final Method METHOD_getEnabledInputMethodSubtypeList =
- CompatUtils.getMethod(InputMethodManager.class, "getEnabledInputMethodSubtypeList",
- InputMethodInfo.class, boolean.class);
- private static final Method METHOD_getShortcutInputMethodsAndSubtypes =
- CompatUtils.getMethod(InputMethodManager.class, "getShortcutInputMethodsAndSubtypes");
- private static final Method METHOD_setInputMethodAndSubtype =
- CompatUtils.getMethod(
- InputMethodManager.class, "setInputMethodAndSubtype", IBinder.class,
- String.class, InputMethodSubtypeCompatWrapper.CLASS_InputMethodSubtype);
- private static final Method METHOD_switchToLastInputMethod = CompatUtils.getMethod(
- InputMethodManager.class, "switchToLastInputMethod", IBinder.class);
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
@@ -66,62 +50,30 @@ public class InputMethodManagerCompatWrapper {
Context.INPUT_METHOD_SERVICE);
}
- public InputMethodSubtypeCompatWrapper getCurrentInputMethodSubtype() {
- Object o = CompatUtils.invoke(mImm, null, METHOD_getCurrentInputMethodSubtype);
- return new InputMethodSubtypeCompatWrapper(o);
+ public InputMethodSubtype getCurrentInputMethodSubtype() {
+ return mImm.getCurrentInputMethodSubtype();
}
- public InputMethodSubtypeCompatWrapper getLastInputMethodSubtype() {
- Object o = CompatUtils.invoke(mImm, null, METHOD_getLastInputMethodSubtype);
- return new InputMethodSubtypeCompatWrapper(o);
+ public InputMethodSubtype getLastInputMethodSubtype() {
+ return mImm.getLastInputMethodSubtype();
}
- public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
+ public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
- Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
- imi, allowsImplicitlySelectedSubtypes);
- if (retval == null || !(retval instanceof List<?>) || ((List<?>)retval).isEmpty()) {
- // Returns an empty list
- return Collections.emptyList();
- }
- return CompatUtils.copyInputMethodSubtypeListToWrapper(retval);
+ return mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes);
}
- public Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
- getShortcutInputMethodsAndSubtypes() {
- Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
- if (retval == null || !(retval instanceof Map<?, ?>) || ((Map<?, ?>)retval).isEmpty()) {
- // Returns an empty map
- return Collections.emptyMap();
- }
- Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcutMap =
- new HashMap<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>();
- final Map<?, ?> retvalMap = (Map<?, ?>)retval;
- for (Object key : retvalMap.keySet()) {
- if (!(key instanceof InputMethodInfo)) {
- Log.e(TAG, "Class type error.");
- return null;
- }
- shortcutMap.put((InputMethodInfo)key,
- CompatUtils.copyInputMethodSubtypeListToWrapper(retvalMap.get(key)));
- }
- return shortcutMap;
+ public Map<InputMethodInfo, List<InputMethodSubtype>> getShortcutInputMethodsAndSubtypes() {
+ return mImm.getShortcutInputMethodsAndSubtypes();
}
// We don't call this method when we switch between subtypes within this IME.
- public void setInputMethodAndSubtype(
- IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
- // TODO: Support subtype change on non-subtype-supported platform.
- if (subtype != null && subtype.hasOriginalObject()) {
- CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
- token, id, subtype.getOriginalObject());
- } else {
- mImm.setInputMethod(token, id);
- }
+ public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
+ mImm.setInputMethodAndSubtype(token, id, subtype);
}
public boolean switchToLastInputMethod(IBinder token) {
- return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToLastInputMethod, token);
+ return mImm.switchToLastInputMethod(token);
}
public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
index 6386fed78..363b4b095 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java
@@ -21,10 +21,8 @@ import android.inputmethodservice.InputMethodService;
import android.os.IBinder;
import android.view.Window;
import android.view.WindowManager;
-import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
-import com.android.inputmethod.latin.SubtypeSwitcher;
public class InputMethodServiceCompatWrapper extends InputMethodService {
// For compatibility of {@link InputMethodManager#showInputMethodPicker}.
@@ -50,20 +48,6 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
dialog.show();
}
- @Override
- public void onCreate() {
- super.onCreate();
- }
-
- //////////////////////////////////////
- // Functions using API v11 or later //
- //////////////////////////////////////
- @Override
- public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
- SubtypeSwitcher.getInstance().updateSubtype(
- new InputMethodSubtypeCompatWrapper(subtype));
- }
-
protected static void setTouchableRegionCompat(InputMethodService.Insets outInsets,
int x, int y, int width, int height) {
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
diff --git a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java
deleted file mode 100644
index 574158825..000000000
--- a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.compat;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.inputmethod.latin.LatinImeLogger;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Locale;
-
-// TODO: Override this class with the concrete implementation if we need to take care of the
-// performance.
-public class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper {
- private static final boolean DBG = LatinImeLogger.sDBG;
- private static final String TAG = InputMethodSubtypeCompatWrapper.class.getSimpleName();
- private static final String DEFAULT_LOCALE = "en_US";
- private static final String DEFAULT_MODE = "keyboard";
-
- public static final Class<?> CLASS_InputMethodSubtype =
- CompatUtils.getClass("android.view.inputmethod.InputMethodSubtype");
- private static final Method METHOD_getNameResId =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getNameResId");
- private static final Method METHOD_getIconResId =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getIconResId");
- private static final Method METHOD_getLocale =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getLocale");
- private static final Method METHOD_getMode =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getMode");
- private static final Method METHOD_getExtraValue =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getExtraValue");
- private static final Method METHOD_containsExtraValueKey =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "containsExtraValueKey", String.class);
- private static final Method METHOD_getExtraValueOf =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getExtraValueOf", String.class);
- private static final Method METHOD_isAuxiliary =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "isAuxiliary");
- private static final Method METHOD_getDisplayName =
- CompatUtils.getMethod(CLASS_InputMethodSubtype, "getDisplayName", Context.class,
- String.class, ApplicationInfo.class);
-
- private final int mDummyNameResId;
- private final int mDummyIconResId;
- private final String mDummyLocale;
- private final String mDummyMode;
- private final String mDummyExtraValues;
-
- public InputMethodSubtypeCompatWrapper(Object subtype) {
- super((CLASS_InputMethodSubtype != null && CLASS_InputMethodSubtype.isInstance(subtype))
- ? subtype : new Object());
- mDummyNameResId = 0;
- mDummyIconResId = 0;
- mDummyLocale = DEFAULT_LOCALE;
- mDummyMode = DEFAULT_MODE;
- mDummyExtraValues = "";
- }
-
- // Constructor for creating a dummy subtype.
- public InputMethodSubtypeCompatWrapper(int nameResId, int iconResId, String locale,
- String mode, String extraValues) {
- super(new Object());
- if (DBG) {
- Log.d(TAG, "CreateInputMethodSubtypeCompatWrapper");
- }
- mDummyNameResId = nameResId;
- mDummyIconResId = iconResId;
- mDummyLocale = locale != null ? locale : "";
- mDummyMode = mode != null ? mode : "";
- mDummyExtraValues = extraValues != null ? extraValues : "";
- }
-
- public int getNameResId() {
- if (mObj == null) return mDummyNameResId;
- return (Integer)CompatUtils.invoke(mObj, 0, METHOD_getNameResId);
- }
-
- public int getIconResId() {
- if (mObj == null) return mDummyIconResId;
- return (Integer)CompatUtils.invoke(mObj, 0, METHOD_getIconResId);
- }
-
- public String getLocale() {
- if (mObj == null) return mDummyLocale;
- final String s = (String)CompatUtils.invoke(mObj, null, METHOD_getLocale);
- return s != null ? s : DEFAULT_LOCALE;
- }
-
- public String getMode() {
- if (mObj == null) return mDummyMode;
- String s = (String)CompatUtils.invoke(mObj, null, METHOD_getMode);
- if (TextUtils.isEmpty(s)) return DEFAULT_MODE;
- return s;
- }
-
- public String getExtraValue() {
- if (mObj == null) return mDummyExtraValues;
- return (String)CompatUtils.invoke(mObj, null, METHOD_getExtraValue);
- }
-
- public boolean containsExtraValueKey(String key) {
- return (Boolean)CompatUtils.invoke(mObj, false, METHOD_containsExtraValueKey, key);
- }
-
- public String getExtraValueOf(String key) {
- return (String)CompatUtils.invoke(mObj, null, METHOD_getExtraValueOf, key);
- }
-
- public boolean isAuxiliary() {
- return (Boolean)CompatUtils.invoke(mObj, false, METHOD_isAuxiliary);
- }
-
- public CharSequence getDisplayName(Context context, String packageName,
- ApplicationInfo appInfo) {
- if (mObj != null) {
- return (CharSequence)CompatUtils.invoke(
- mObj, "", METHOD_getDisplayName, context, packageName, appInfo);
- }
-
- // The code below are based on {@link InputMethodSubtype#getDisplayName}.
-
- final Locale locale = new Locale(getLocale());
- final String localeStr = locale.getDisplayName();
- if (getNameResId() == 0) {
- return localeStr;
- }
- final CharSequence subtypeName = context.getText(getNameResId());
- if (!TextUtils.isEmpty(localeStr)) {
- return String.format(subtypeName.toString(), localeStr);
- } else {
- return localeStr;
- }
- }
-
- public boolean isDummy() {
- return !hasOriginalObject();
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof InputMethodSubtypeCompatWrapper) {
- InputMethodSubtypeCompatWrapper subtype = (InputMethodSubtypeCompatWrapper)o;
- if (mObj == null) {
- // easy check of dummy subtypes
- return (mDummyNameResId == subtype.mDummyNameResId
- && mDummyIconResId == subtype.mDummyIconResId
- && mDummyLocale.equals(subtype.mDummyLocale)
- && mDummyMode.equals(subtype.mDummyMode)
- && mDummyExtraValues.equals(subtype.mDummyExtraValues));
- }
- return mObj.equals(subtype.getOriginalObject());
- } else {
- return mObj.equals(o);
- }
- }
-
- @Override
- public int hashCode() {
- if (mObj == null) {
- return hashCodeInternal(mDummyNameResId, mDummyIconResId, mDummyLocale,
- mDummyMode, mDummyExtraValues);
- }
- return mObj.hashCode();
- }
-
- private static int hashCodeInternal(int nameResId, int iconResId, String locale,
- String mode, String extraValue) {
- return Arrays
- .hashCode(new Object[] { nameResId, iconResId, locale, mode, extraValue });
- }
-}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
index f0c773ff4..4d0f00380 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java
@@ -237,7 +237,6 @@ public class KeyboardSet {
return this;
}
- // TODO: Use InputMethodSubtype object as argument.
public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 69780d0fd..2cd291add 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -49,6 +49,7 @@ import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
@@ -56,7 +57,6 @@ import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
@@ -627,6 +627,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHandler.onFinishInput();
}
+ @Override
+ public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
+ SubtypeSwitcher.getInstance().updateSubtype(subtype);
+ }
+
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
super.onStartInput(editorInfo, restarting);
}
@@ -1178,7 +1183,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean includesOtherImes = mSettingsValues.mIncludesOtherImesInLanguageSwitchList;
final IBinder token = getWindow().getWindow().getAttributes().token;
if (mShouldSwitchToLastSubtype) {
- final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype();
+ final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
this, lastSubtype);
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 794e5dc3a..e35364420 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -30,9 +30,9 @@ import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import java.util.ArrayList;
@@ -57,9 +57,8 @@ public class SubtypeSwitcher {
private /* final */ InputMethodManagerCompatWrapper mImm;
private /* final */ Resources mResources;
private /* final */ ConnectivityManager mConnectivityManager;
- private final ArrayList<InputMethodSubtypeCompatWrapper>
- mEnabledKeyboardSubtypesOfCurrentInputMethod =
- new ArrayList<InputMethodSubtypeCompatWrapper>();
+ private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
+ new ArrayList<InputMethodSubtype>();
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
/*-----------------------------------------------------------*/
@@ -67,9 +66,10 @@ public class SubtypeSwitcher {
private boolean mNeedsToDisplayLanguage;
private boolean mIsSystemLanguageSameAsInputLanguage;
private InputMethodInfo mShortcutInputMethodInfo;
- private InputMethodSubtypeCompatWrapper mShortcutSubtype;
- private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
- private InputMethodSubtypeCompatWrapper mCurrentSubtype;
+ private InputMethodSubtype mShortcutSubtype;
+ private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
+ // Note: This variable is always non-null after {@link #initialize(LatinIME)}.
+ private InputMethodSubtype mCurrentSubtype;
private Locale mSystemLocale;
private Locale mInputLocale;
private String mInputLocaleStr;
@@ -102,7 +102,7 @@ public class SubtypeSwitcher {
mSystemLocale = null;
mInputLocale = null;
mInputLocaleStr = null;
- mCurrentSubtype = null;
+ mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
mAllEnabledSubtypesOfCurrentInputMethod = null;
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
@@ -132,7 +132,7 @@ public class SubtypeSwitcher {
null, true);
mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
- for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
+ for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
final String locale = getSubtypeLocale(ims);
final String mode = ims.getMode();
mLocaleSplitter.setString(locale);
@@ -166,12 +166,12 @@ public class SubtypeSwitcher {
+ ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
- final Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcuts =
+ final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts =
mImm.getShortcutInputMethodsAndSubtypes();
mShortcutInputMethodInfo = null;
mShortcutSubtype = null;
for (InputMethodInfo imi : shortcuts.keySet()) {
- List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
+ List<InputMethodSubtype> subtypes = shortcuts.get(imi);
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
// appropriate.
mShortcutInputMethodInfo = imi;
@@ -189,27 +189,17 @@ public class SubtypeSwitcher {
}
}
- private static String getSubtypeLocale(InputMethodSubtypeCompatWrapper subtype) {
+ private static String getSubtypeLocale(InputMethodSubtype subtype) {
final String keyboardLocale = subtype.getExtraValueOf(
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
- public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) {
- final String newLocale;
- final String newMode;
+ public void updateSubtype(InputMethodSubtype newSubtype) {
+ final String newLocale = getSubtypeLocale(newSubtype);
+ final String newMode = newSubtype.getMode();
final String oldMode = getCurrentSubtypeMode();
- if (newSubtype == null) {
- // Normally, newSubtype shouldn't be null. But just in case newSubtype was null,
- // fallback to the default locale.
- Log.w(TAG, "Couldn't get the current subtype.");
- newLocale = "en_US";
- newMode = KEYBOARD_MODE;
- } else {
- newLocale = getSubtypeLocale(newSubtype);
- newMode = newSubtype.getMode();
- }
if (DBG) {
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
+ ", from: " + mInputLocaleStr + ", " + oldMode);
@@ -284,12 +274,10 @@ public class SubtypeSwitcher {
}
final String imiId = mShortcutInputMethodInfo.getId();
- final InputMethodSubtypeCompatWrapper subtype = mShortcutSubtype;
- switchToTargetIME(imiId, subtype);
+ switchToTargetIME(imiId, mShortcutSubtype);
}
- private void switchToTargetIME(
- final String imiId, final InputMethodSubtypeCompatWrapper subtype) {
+ private void switchToTargetIME(final String imiId, final InputMethodSubtype subtype) {
final IBinder token = mService.getWindow().getWindow().getAttributes().token;
if (token == null) {
return;
@@ -307,7 +295,7 @@ public class SubtypeSwitcher {
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
}
- private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtypeCompatWrapper subtype) {
+ private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
final PackageManager pm = mService.getPackageManager();
if (imi != null) {
final String imiPackageName = imi.getPackageName();
@@ -348,15 +336,9 @@ public class SubtypeSwitcher {
if (mShortcutSubtype == null) {
return true;
}
- // For compatibility, if the shortcut subtype is dummy, we assume the shortcut IME
- // (built-in voice dummy subtype) is available.
- if (!mShortcutSubtype.hasOriginalObject()) {
- return true;
- }
final boolean allowsImplicitlySelectedSubtypes = true;
- for (final InputMethodSubtypeCompatWrapper enabledSubtype :
- mImm.getEnabledInputMethodSubtypeList(
- mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
+ for (final InputMethodSubtype enabledSubtype : mImm.getEnabledInputMethodSubtypeList(
+ mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
if (enabledSubtype.equals(mShortcutSubtype)) {
return true;
}
@@ -448,20 +430,20 @@ public class SubtypeSwitcher {
public String getCurrentSubtypeExtraValue() {
// If null, return what an empty ExtraValue would return : the empty string.
- return null != mCurrentSubtype ? mCurrentSubtype.getExtraValue() : "";
+ return mCurrentSubtype.getExtraValue();
}
public boolean currentSubtypeContainsExtraValueKey(String key) {
// If null, return what an empty ExtraValue would return : false.
- return null != mCurrentSubtype ? mCurrentSubtype.containsExtraValueKey(key) : false;
+ return mCurrentSubtype.containsExtraValueKey(key);
}
public String getCurrentSubtypeExtraValueOf(String key) {
// If null, return what an empty ExtraValue would return : null.
- return null != mCurrentSubtype ? mCurrentSubtype.getExtraValueOf(key) : null;
+ return mCurrentSubtype.getExtraValueOf(key);
}
public String getCurrentSubtypeMode() {
- return null != mCurrentSubtype ? mCurrentSubtype.getMode() : KEYBOARD_MODE;
+ return mCurrentSubtype.getMode();
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
index 8beb71bf1..2c5d58200 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
@@ -18,9 +18,9 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import java.util.Collections;
import java.util.List;
@@ -31,15 +31,13 @@ public class SubtypeUtils {
}
// TODO: Cache my InputMethodInfo and/or InputMethodSubtype list.
- public static boolean checkIfSubtypeBelongsToThisIme(Context context,
- InputMethodSubtypeCompatWrapper ims) {
+ public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) {
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
if (imm == null) return false;
final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
- final List<InputMethodSubtypeCompatWrapper> subtypes =
- imm.getEnabledInputMethodSubtypeList(myImi, true);
- for (final InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true);
+ for (final InputMethodSubtype subtype : subtypes) {
if (subtype.equals(ims)) {
return true;
}
@@ -74,7 +72,7 @@ public class SubtypeUtils {
for (InputMethodInfo imi : imiList) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true;
- final List<InputMethodSubtypeCompatWrapper> subtypes =
+ final List<InputMethodSubtype> subtypes =
imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
@@ -83,7 +81,7 @@ public class SubtypeUtils {
}
int auxCount = 0;
- for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
@@ -102,13 +100,12 @@ public class SubtypeUtils {
if (filteredImisCount > 1) {
return true;
}
- final List<InputMethodSubtypeCompatWrapper> subtypes =
- imm.getEnabledInputMethodSubtypeList(null, true);
+ final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(null, true);
int keyboardCount = 0;
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
// both explicitly and implicitly enabled input method subtype.
// (The current IME should be LatinIME.)
- for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ for (InputMethodSubtype subtype : subtypes) {
if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) {
++keyboardCount;
}