A fix for handling dummy voice subtypes
Change-Id: I75d4d1625e0925d01ae84c9577e15087d83e4191
This commit is contained in:
parent
458807e8a3
commit
bc3dba451a
3 changed files with 16 additions and 7 deletions
|
@ -67,7 +67,6 @@ public class InputMethodManagerCompatWrapper {
|
||||||
|
|
||||||
// For the compatibility, IMM will create dummy subtypes if subtypes are not found.
|
// 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.
|
// 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 boolean HAS_VOICE_FUNCTION = true;
|
||||||
private static final String VOICE_MODE = "voice";
|
private static final String VOICE_MODE = "voice";
|
||||||
private static final String KEYBOARD_MODE = "keyboard";
|
private static final String KEYBOARD_MODE = "keyboard";
|
||||||
|
@ -119,11 +118,13 @@ public class InputMethodManagerCompatWrapper {
|
||||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList,
|
||||||
(imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
|
(imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes);
|
||||||
if (retval == null || !(retval instanceof List) || ((List<?>)retval).isEmpty()) {
|
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
|
// Returns an empty list
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
// Creates dummy subtypes
|
// Creates dummy subtypes
|
||||||
|
@SuppressWarnings("unused")
|
||||||
List<InputMethodSubtypeCompatWrapper> subtypeList =
|
List<InputMethodSubtypeCompatWrapper> subtypeList =
|
||||||
new ArrayList<InputMethodSubtypeCompatWrapper>();
|
new ArrayList<InputMethodSubtypeCompatWrapper>();
|
||||||
InputMethodSubtypeCompatWrapper keyboardSubtype = getLastResortSubtype(KEYBOARD_MODE);
|
InputMethodSubtypeCompatWrapper keyboardSubtype = getLastResortSubtype(KEYBOARD_MODE);
|
||||||
|
@ -159,11 +160,13 @@ public class InputMethodManagerCompatWrapper {
|
||||||
getShortcutInputMethodsAndSubtypes() {
|
getShortcutInputMethodsAndSubtypes() {
|
||||||
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
|
Object retval = CompatUtils.invoke(mImm, null, METHOD_getShortcutInputMethodsAndSubtypes);
|
||||||
if (retval == null || !(retval instanceof Map) || ((Map<?, ?>)retval).isEmpty()) {
|
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
|
// Returns an empty map
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
// Creates dummy subtypes
|
// Creates dummy subtypes
|
||||||
|
@SuppressWarnings("unused")
|
||||||
InputMethodInfoCompatWrapper imi = getLatinImeInputMethodInfo();
|
InputMethodInfoCompatWrapper imi = getLatinImeInputMethodInfo();
|
||||||
InputMethodSubtypeCompatWrapper voiceSubtype = getLastResortSubtype(VOICE_MODE);
|
InputMethodSubtypeCompatWrapper voiceSubtype = getLastResortSubtype(VOICE_MODE);
|
||||||
if (imi != null && voiceSubtype != null) {
|
if (imi != null && voiceSubtype != null) {
|
||||||
|
@ -196,9 +199,11 @@ public class InputMethodManagerCompatWrapper {
|
||||||
|
|
||||||
public void setInputMethodAndSubtype(
|
public void setInputMethodAndSubtype(
|
||||||
IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
|
IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
|
||||||
|
if (subtype != null && subtype.hasOriginalObject()) {
|
||||||
CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
|
CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
|
||||||
token, id, subtype.getOriginalObject());
|
token, id, subtype.getOriginalObject());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean switchToLastInputMethod(IBinder token) {
|
public boolean switchToLastInputMethod(IBinder token) {
|
||||||
if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) {
|
if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
|
||||||
// For the API level 11 or later, LatinIME should override onCurrentInputMethodSubtypeChanged().
|
// 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
|
// For the API level 10 or previous, we handle the "subtype changed" events by ourselves
|
||||||
// without having support from framework -- onCurrentInputMethodSubtypeChanged().
|
// 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;
|
private InputMethodManagerCompatWrapper mImm;
|
||||||
|
|
||||||
|
|
|
@ -382,13 +382,17 @@ public class SubtypeSwitcher {
|
||||||
return false;
|
return false;
|
||||||
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 InputMethodSubtypeCompatWrapper enabledSubtype :
|
||||||
mImm.getEnabledInputMethodSubtypeList(
|
mImm.getEnabledInputMethodSubtypeList(
|
||||||
mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
|
mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
|
||||||
if (enabledSubtype.equals(mShortcutSubtype))
|
if (enabledSubtype.equals(mShortcutSubtype)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue