mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Remove InputMethodSubtypeCompatWrapper"
This commit is contained in:
commit
8443af57ba
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,8 +23,6 @@ import android.util.Log;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CompatUtils {
|
public class CompatUtils {
|
||||||
private static final String TAG = CompatUtils.class.getSimpleName();
|
private static final String TAG = CompatUtils.class.getSimpleName();
|
||||||
@ -131,15 +129,4 @@ public class CompatUtils {
|
|||||||
Log.e(TAG, "Exception in setFieldValue: " + e.getClass().getSimpleName());
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,9 @@ import android.os.IBinder;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -32,21 +31,6 @@ import java.util.Map;
|
|||||||
// performance.
|
// performance.
|
||||||
public class InputMethodManagerCompatWrapper {
|
public class InputMethodManagerCompatWrapper {
|
||||||
private static final String TAG = InputMethodManagerCompatWrapper.class.getSimpleName();
|
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(
|
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
|
||||||
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
|
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
|
||||||
|
|
||||||
@ -66,62 +50,30 @@ public class InputMethodManagerCompatWrapper {
|
|||||||
Context.INPUT_METHOD_SERVICE);
|
Context.INPUT_METHOD_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodSubtypeCompatWrapper getCurrentInputMethodSubtype() {
|
public InputMethodSubtype getCurrentInputMethodSubtype() {
|
||||||
Object o = CompatUtils.invoke(mImm, null, METHOD_getCurrentInputMethodSubtype);
|
return mImm.getCurrentInputMethodSubtype();
|
||||||
return new InputMethodSubtypeCompatWrapper(o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodSubtypeCompatWrapper getLastInputMethodSubtype() {
|
public InputMethodSubtype getLastInputMethodSubtype() {
|
||||||
Object o = CompatUtils.invoke(mImm, null, METHOD_getLastInputMethodSubtype);
|
return mImm.getLastInputMethodSubtype();
|
||||||
return new InputMethodSubtypeCompatWrapper(o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
|
public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
|
||||||
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
|
InputMethodInfo imi, boolean allowsImplicitlySelectedSubtypes) {
|
||||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
return mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes);
|
||||||
imi, allowsImplicitlySelectedSubtypes);
|
|
||||||
if (retval == null || !(retval instanceof List<?>) || ((List<?>)retval).isEmpty()) {
|
|
||||||
// Returns an empty list
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return CompatUtils.copyInputMethodSubtypeListToWrapper(retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>>
|
public Map<InputMethodInfo, List<InputMethodSubtype>> getShortcutInputMethodsAndSubtypes() {
|
||||||
getShortcutInputMethodsAndSubtypes() {
|
return mImm.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't call this method when we switch between subtypes within this IME.
|
// We don't call this method when we switch between subtypes within this IME.
|
||||||
public void setInputMethodAndSubtype(
|
public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
|
||||||
IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
|
mImm.setInputMethodAndSubtype(token, id, 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 boolean switchToLastInputMethod(IBinder token) {
|
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) {
|
public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
|
||||||
|
@ -21,10 +21,8 @@ import android.inputmethodservice.InputMethodService;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
|
||||||
|
|
||||||
public class InputMethodServiceCompatWrapper extends InputMethodService {
|
public class InputMethodServiceCompatWrapper extends InputMethodService {
|
||||||
// For compatibility of {@link InputMethodManager#showInputMethodPicker}.
|
// For compatibility of {@link InputMethodManager#showInputMethodPicker}.
|
||||||
@ -50,20 +48,6 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
|
|||||||
dialog.show();
|
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,
|
protected static void setTouchableRegionCompat(InputMethodService.Insets outInsets,
|
||||||
int x, int y, int width, int height) {
|
int x, int y, int width, int height) {
|
||||||
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
||||||
|
@ -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 });
|
|
||||||
}
|
|
||||||
}
|
|
@ -237,7 +237,6 @@ public class KeyboardSet {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use InputMethodSubtype object as argument.
|
|
||||||
public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
|
public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
|
||||||
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
|
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
|
||||||
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
|
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
|
||||||
|
@ -49,6 +49,7 @@ import android.view.inputmethod.CompletionInfo;
|
|||||||
import android.view.inputmethod.CorrectionInfo;
|
import android.view.inputmethod.CorrectionInfo;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||||
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
|
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.EditorInfoCompatUtils;
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
|
||||||
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
import com.android.inputmethod.compat.SuggestionSpanUtils;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
||||||
@ -627,6 +627,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
mHandler.onFinishInput();
|
mHandler.onFinishInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
||||||
|
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
||||||
|
}
|
||||||
|
|
||||||
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
|
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
|
||||||
super.onStartInput(editorInfo, restarting);
|
super.onStartInput(editorInfo, restarting);
|
||||||
}
|
}
|
||||||
@ -1178,7 +1183,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||||||
final boolean includesOtherImes = mSettingsValues.mIncludesOtherImesInLanguageSwitchList;
|
final boolean includesOtherImes = mSettingsValues.mIncludesOtherImesInLanguageSwitchList;
|
||||||
final IBinder token = getWindow().getWindow().getAttributes().token;
|
final IBinder token = getWindow().getWindow().getAttributes().token;
|
||||||
if (mShouldSwitchToLastSubtype) {
|
if (mShouldSwitchToLastSubtype) {
|
||||||
final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype();
|
final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
|
||||||
final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
|
final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
|
||||||
this, lastSubtype);
|
this, lastSubtype);
|
||||||
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
|
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
|
||||||
|
@ -30,9 +30,9 @@ import android.os.IBinder;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -57,9 +57,8 @@ public class SubtypeSwitcher {
|
|||||||
private /* final */ InputMethodManagerCompatWrapper mImm;
|
private /* final */ InputMethodManagerCompatWrapper mImm;
|
||||||
private /* final */ Resources mResources;
|
private /* final */ Resources mResources;
|
||||||
private /* final */ ConnectivityManager mConnectivityManager;
|
private /* final */ ConnectivityManager mConnectivityManager;
|
||||||
private final ArrayList<InputMethodSubtypeCompatWrapper>
|
private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
|
||||||
mEnabledKeyboardSubtypesOfCurrentInputMethod =
|
new ArrayList<InputMethodSubtype>();
|
||||||
new ArrayList<InputMethodSubtypeCompatWrapper>();
|
|
||||||
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
|
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@ -67,9 +66,10 @@ public class SubtypeSwitcher {
|
|||||||
private boolean mNeedsToDisplayLanguage;
|
private boolean mNeedsToDisplayLanguage;
|
||||||
private boolean mIsSystemLanguageSameAsInputLanguage;
|
private boolean mIsSystemLanguageSameAsInputLanguage;
|
||||||
private InputMethodInfo mShortcutInputMethodInfo;
|
private InputMethodInfo mShortcutInputMethodInfo;
|
||||||
private InputMethodSubtypeCompatWrapper mShortcutSubtype;
|
private InputMethodSubtype mShortcutSubtype;
|
||||||
private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
|
private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
|
||||||
private InputMethodSubtypeCompatWrapper mCurrentSubtype;
|
// Note: This variable is always non-null after {@link #initialize(LatinIME)}.
|
||||||
|
private InputMethodSubtype mCurrentSubtype;
|
||||||
private Locale mSystemLocale;
|
private Locale mSystemLocale;
|
||||||
private Locale mInputLocale;
|
private Locale mInputLocale;
|
||||||
private String mInputLocaleStr;
|
private String mInputLocaleStr;
|
||||||
@ -102,7 +102,7 @@ public class SubtypeSwitcher {
|
|||||||
mSystemLocale = null;
|
mSystemLocale = null;
|
||||||
mInputLocale = null;
|
mInputLocale = null;
|
||||||
mInputLocaleStr = null;
|
mInputLocaleStr = null;
|
||||||
mCurrentSubtype = null;
|
mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
|
||||||
mAllEnabledSubtypesOfCurrentInputMethod = null;
|
mAllEnabledSubtypesOfCurrentInputMethod = null;
|
||||||
|
|
||||||
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
||||||
@ -132,7 +132,7 @@ public class SubtypeSwitcher {
|
|||||||
null, true);
|
null, true);
|
||||||
mEnabledLanguagesOfCurrentInputMethod.clear();
|
mEnabledLanguagesOfCurrentInputMethod.clear();
|
||||||
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
|
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
|
||||||
for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
|
for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
|
||||||
final String locale = getSubtypeLocale(ims);
|
final String locale = getSubtypeLocale(ims);
|
||||||
final String mode = ims.getMode();
|
final String mode = ims.getMode();
|
||||||
mLocaleSplitter.setString(locale);
|
mLocaleSplitter.setString(locale);
|
||||||
@ -166,12 +166,12 @@ public class SubtypeSwitcher {
|
|||||||
+ ", " + mShortcutSubtype.getMode())));
|
+ ", " + mShortcutSubtype.getMode())));
|
||||||
}
|
}
|
||||||
// TODO: Update an icon for shortcut IME
|
// TODO: Update an icon for shortcut IME
|
||||||
final Map<InputMethodInfo, List<InputMethodSubtypeCompatWrapper>> shortcuts =
|
final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts =
|
||||||
mImm.getShortcutInputMethodsAndSubtypes();
|
mImm.getShortcutInputMethodsAndSubtypes();
|
||||||
mShortcutInputMethodInfo = null;
|
mShortcutInputMethodInfo = null;
|
||||||
mShortcutSubtype = null;
|
mShortcutSubtype = null;
|
||||||
for (InputMethodInfo imi : shortcuts.keySet()) {
|
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
|
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
|
||||||
// appropriate.
|
// appropriate.
|
||||||
mShortcutInputMethodInfo = imi;
|
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(
|
final String keyboardLocale = subtype.getExtraValueOf(
|
||||||
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
|
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
|
||||||
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
|
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
||||||
public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) {
|
public void updateSubtype(InputMethodSubtype newSubtype) {
|
||||||
final String newLocale;
|
final String newLocale = getSubtypeLocale(newSubtype);
|
||||||
final String newMode;
|
final String newMode = newSubtype.getMode();
|
||||||
final String oldMode = getCurrentSubtypeMode();
|
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) {
|
if (DBG) {
|
||||||
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
|
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
|
||||||
+ ", from: " + mInputLocaleStr + ", " + oldMode);
|
+ ", from: " + mInputLocaleStr + ", " + oldMode);
|
||||||
@ -284,12 +274,10 @@ public class SubtypeSwitcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String imiId = mShortcutInputMethodInfo.getId();
|
final String imiId = mShortcutInputMethodInfo.getId();
|
||||||
final InputMethodSubtypeCompatWrapper subtype = mShortcutSubtype;
|
switchToTargetIME(imiId, mShortcutSubtype);
|
||||||
switchToTargetIME(imiId, subtype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchToTargetIME(
|
private void switchToTargetIME(final String imiId, final InputMethodSubtype subtype) {
|
||||||
final String imiId, final InputMethodSubtypeCompatWrapper subtype) {
|
|
||||||
final IBinder token = mService.getWindow().getWindow().getAttributes().token;
|
final IBinder token = mService.getWindow().getWindow().getAttributes().token;
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
return;
|
return;
|
||||||
@ -307,7 +295,7 @@ public class SubtypeSwitcher {
|
|||||||
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
|
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtypeCompatWrapper subtype) {
|
private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
|
||||||
final PackageManager pm = mService.getPackageManager();
|
final PackageManager pm = mService.getPackageManager();
|
||||||
if (imi != null) {
|
if (imi != null) {
|
||||||
final String imiPackageName = imi.getPackageName();
|
final String imiPackageName = imi.getPackageName();
|
||||||
@ -348,15 +336,9 @@ public class SubtypeSwitcher {
|
|||||||
if (mShortcutSubtype == null) {
|
if (mShortcutSubtype == null) {
|
||||||
return true;
|
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;
|
final boolean allowsImplicitlySelectedSubtypes = true;
|
||||||
for (final InputMethodSubtypeCompatWrapper enabledSubtype :
|
for (final InputMethodSubtype enabledSubtype : mImm.getEnabledInputMethodSubtypeList(
|
||||||
mImm.getEnabledInputMethodSubtypeList(
|
mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
|
||||||
mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
|
|
||||||
if (enabledSubtype.equals(mShortcutSubtype)) {
|
if (enabledSubtype.equals(mShortcutSubtype)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -448,20 +430,20 @@ public class SubtypeSwitcher {
|
|||||||
|
|
||||||
public String getCurrentSubtypeExtraValue() {
|
public String getCurrentSubtypeExtraValue() {
|
||||||
// If null, return what an empty ExtraValue would return : the empty string.
|
// 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) {
|
public boolean currentSubtypeContainsExtraValueKey(String key) {
|
||||||
// If null, return what an empty ExtraValue would return : false.
|
// 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) {
|
public String getCurrentSubtypeExtraValueOf(String key) {
|
||||||
// If null, return what an empty ExtraValue would return : null.
|
// If null, return what an empty ExtraValue would return : null.
|
||||||
return null != mCurrentSubtype ? mCurrentSubtype.getExtraValueOf(key) : null;
|
return mCurrentSubtype.getExtraValueOf(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentSubtypeMode() {
|
public String getCurrentSubtypeMode() {
|
||||||
return null != mCurrentSubtype ? mCurrentSubtype.getMode() : KEYBOARD_MODE;
|
return mCurrentSubtype.getMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@ package com.android.inputmethod.latin;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -31,15 +31,13 @@ public class SubtypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache my InputMethodInfo and/or InputMethodSubtype list.
|
// TODO: Cache my InputMethodInfo and/or InputMethodSubtype list.
|
||||||
public static boolean checkIfSubtypeBelongsToThisIme(Context context,
|
public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) {
|
||||||
InputMethodSubtypeCompatWrapper ims) {
|
|
||||||
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
|
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
|
||||||
if (imm == null) return false;
|
if (imm == null) return false;
|
||||||
|
|
||||||
final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
|
final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
|
||||||
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true);
|
||||||
imm.getEnabledInputMethodSubtypeList(myImi, true);
|
for (final InputMethodSubtype subtype : subtypes) {
|
||||||
for (final InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
|
||||||
if (subtype.equals(ims)) {
|
if (subtype.equals(ims)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -74,7 +72,7 @@ public class SubtypeUtils {
|
|||||||
for (InputMethodInfo imi : imiList) {
|
for (InputMethodInfo imi : imiList) {
|
||||||
// We can return true immediately after we find two or more filtered IMEs.
|
// We can return true immediately after we find two or more filtered IMEs.
|
||||||
if (filteredImisCount > 1) return true;
|
if (filteredImisCount > 1) return true;
|
||||||
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
final List<InputMethodSubtype> subtypes =
|
||||||
imm.getEnabledInputMethodSubtypeList(imi, true);
|
imm.getEnabledInputMethodSubtypeList(imi, true);
|
||||||
// IMEs that have no subtypes should be counted.
|
// IMEs that have no subtypes should be counted.
|
||||||
if (subtypes.isEmpty()) {
|
if (subtypes.isEmpty()) {
|
||||||
@ -83,7 +81,7 @@ public class SubtypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int auxCount = 0;
|
int auxCount = 0;
|
||||||
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
for (InputMethodSubtype subtype : subtypes) {
|
||||||
if (subtype.isAuxiliary()) {
|
if (subtype.isAuxiliary()) {
|
||||||
++auxCount;
|
++auxCount;
|
||||||
}
|
}
|
||||||
@ -102,13 +100,12 @@ public class SubtypeUtils {
|
|||||||
if (filteredImisCount > 1) {
|
if (filteredImisCount > 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(null, true);
|
||||||
imm.getEnabledInputMethodSubtypeList(null, true);
|
|
||||||
int keyboardCount = 0;
|
int keyboardCount = 0;
|
||||||
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
|
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
|
||||||
// both explicitly and implicitly enabled input method subtype.
|
// both explicitly and implicitly enabled input method subtype.
|
||||||
// (The current IME should be LatinIME.)
|
// (The current IME should be LatinIME.)
|
||||||
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
for (InputMethodSubtype subtype : subtypes) {
|
||||||
if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) {
|
if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) {
|
||||||
++keyboardCount;
|
++keyboardCount;
|
||||||
}
|
}
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 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.latin;
|
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
|
||||||
|
|
||||||
public class ArbitrarySubtype extends InputMethodSubtypeCompatWrapper {
|
|
||||||
final String mLocale;
|
|
||||||
final String mExtraValue;
|
|
||||||
|
|
||||||
public ArbitrarySubtype(final String locale, final String extraValue) {
|
|
||||||
super(locale);
|
|
||||||
mLocale = locale;
|
|
||||||
mExtraValue = extraValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocale() {
|
|
||||||
return mLocale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExtraValue() {
|
|
||||||
return mExtraValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMode() {
|
|
||||||
return "keyboard";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExtraValueOf(final String key) {
|
|
||||||
if (LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key)) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsExtraValueKey(final String key) {
|
|
||||||
return LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE.equals(key);
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,6 +30,9 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -37,6 +40,8 @@ import com.android.inputmethod.keyboard.Key;
|
|||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
||||||
|
|
||||||
private static final String PREF_DEBUG_MODE = "debug_mode";
|
private static final String PREF_DEBUG_MODE = "debug_mode";
|
||||||
@ -48,6 +53,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
protected Keyboard mKeyboard;
|
protected Keyboard mKeyboard;
|
||||||
protected TextView mTextView;
|
protected TextView mTextView;
|
||||||
protected InputConnection mInputConnection;
|
protected InputConnection mInputConnection;
|
||||||
|
private final HashMap<String, InputMethodSubtype> mSubtypeMap =
|
||||||
|
new HashMap<String, InputMethodSubtype>();
|
||||||
|
|
||||||
// A helper class to ease span tests
|
// A helper class to ease span tests
|
||||||
public static class Span {
|
public static class Span {
|
||||||
@ -108,6 +115,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
final boolean previousDebugSetting = setDebugMode(true);
|
final boolean previousDebugSetting = setDebugMode(true);
|
||||||
mLatinIME.onCreate();
|
mLatinIME.onCreate();
|
||||||
setDebugMode(previousDebugSetting);
|
setDebugMode(previousDebugSetting);
|
||||||
|
initSubtypeMap();
|
||||||
final EditorInfo ei = new EditorInfo();
|
final EditorInfo ei = new EditorInfo();
|
||||||
ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
|
ei.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
|
||||||
final InputConnection ic = mTextView.onCreateInputConnection(ei);
|
final InputConnection ic = mTextView.onCreateInputConnection(ei);
|
||||||
@ -126,6 +134,23 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
changeLanguage("en_US");
|
changeLanguage("en_US");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initSubtypeMap() {
|
||||||
|
final InputMethodManager imm = (InputMethodManager)mLatinIME.getSystemService(
|
||||||
|
Context.INPUT_METHOD_SERVICE);
|
||||||
|
final String packageName = mLatinIME.getPackageName();
|
||||||
|
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
||||||
|
if (imi.getPackageName().equals(packageName)) {
|
||||||
|
for (final InputMethodSubtype ims :
|
||||||
|
imm.getEnabledInputMethodSubtypeList(imi, true)) {
|
||||||
|
final String locale = ims.getLocale();
|
||||||
|
mSubtypeMap.put(locale, ims);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("LatinIME is disabled");
|
||||||
|
}
|
||||||
|
|
||||||
// We need to run the messages added to the handler from LatinIME. The only way to do
|
// We need to run the messages added to the handler from LatinIME. The only way to do
|
||||||
// that is to call Looper#loop() on the right looper, so we're going to get the looper
|
// that is to call Looper#loop() on the right looper, so we're going to get the looper
|
||||||
// object and call #loop() here. The messages in the handler actually run on the UI
|
// object and call #loop() here. The messages in the handler actually run on the UI
|
||||||
@ -217,8 +242,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void changeLanguage(final String locale) {
|
protected void changeLanguage(final String locale) {
|
||||||
SubtypeSwitcher.getInstance().updateSubtype(
|
final InputMethodSubtype subtype = mSubtypeMap.get(locale);
|
||||||
new ArbitrarySubtype(locale, LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
|
if (subtype == null) {
|
||||||
|
fail("InputMethodSubtype for locale " + locale + " is not enabled");
|
||||||
|
}
|
||||||
|
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
||||||
waitForDictionaryToBeLoaded();
|
waitForDictionaryToBeLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user