A fix for handling dummy voice subtypes

Change-Id: I75d4d1625e0925d01ae84c9577e15087d83e4191
main
satok 2011-04-18 16:06:31 +09:00
parent 458807e8a3
commit bc3dba451a
3 changed files with 16 additions and 7 deletions

View File

@ -67,7 +67,6 @@ public class InputMethodManagerCompatWrapper {
// For the compatibility, IMM will create dummy subtypes if subtypes are not found.
// This is required to be false if the current behavior is broken. For now, it's ok to be true.
private static final boolean ALLOW_DUMMY_SUBTYPE = true;
private static final boolean HAS_VOICE_FUNCTION = true;
private static final String VOICE_MODE = "voice";
private static final String KEYBOARD_MODE = "keyboard";
@ -119,11 +118,13 @@ public class InputMethodManagerCompatWrapper {
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
(imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
if (retval == null || !(retval instanceof List) || ((List<?>)retval).isEmpty()) {
if (!ALLOW_DUMMY_SUBTYPE) {
if (InputMethodServiceCompatWrapper.
CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
// Returns an empty list
return Collections.emptyList();
}
// Creates dummy subtypes
@SuppressWarnings("unused")
List<InputMethodSubtypeCompatWrapper> subtypeList =
new ArrayList<InputMethodSubtypeCompatWrapper>();
InputMethodSubtypeCompatWrapper keyboardSubtype = getLastResortSubtype(KEYBOARD_MODE);
@ -159,11 +160,13 @@ public class InputMethodManagerCompatWrapper {
getShortcutInputMethodsAndSubtypes() {
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
if (retval == null || !(retval instanceof Map) || ((Map<?, ?>)retval).isEmpty()) {
if (!ALLOW_DUMMY_SUBTYPE) {
if (InputMethodServiceCompatWrapper.
CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
// Returns an empty map
return Collections.emptyMap();
}
// Creates dummy subtypes
@SuppressWarnings("unused")
InputMethodInfoCompatWrapper imi = getLatinImeInputMethodInfo();
InputMethodSubtypeCompatWrapper voiceSubtype = getLastResortSubtype(VOICE_MODE);
if (imi != null && voiceSubtype != null) {
@ -196,8 +199,10 @@ public class InputMethodManagerCompatWrapper {
public void setInputMethodAndSubtype(
IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
token, id, subtype.getOriginalObject());
if (subtype != null && subtype.hasOriginalObject()) {
CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
token, id, subtype.getOriginalObject());
}
}
public boolean switchToLastInputMethod(IBinder token) {

View File

@ -28,7 +28,7 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
// For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged().
// For the API level 10 or previous, we handle the "subtype changed" events by ourselves
// without having support from framework -- onCurrentInputMethodSubtypeChanged().
private static final boolean CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED = true;
public static final boolean CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED = true;
private InputMethodManagerCompatWrapper mImm;

View File

@ -382,12 +382,16 @@ public class SubtypeSwitcher {
return false;
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)) {
if (enabledSubtype.equals(mShortcutSubtype))
if (enabledSubtype.equals(mShortcutSubtype)) {
return true;
}
}
return false;
}