Revise hasMultipleEnabledIMEsOrSubtypes()
bug: 4559308 Change-Id: If831c0827dbf030eaf1d241ebfa60d4e5029ae63
This commit is contained in:
parent
f20eb55d4f
commit
a88a5eddbc
2 changed files with 37 additions and 1 deletions
|
@ -48,6 +48,8 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper
|
||||||
CompatUtils.getMethod(CLASS_InputMethodSubtype, "containsExtraValueKey", String.class);
|
CompatUtils.getMethod(CLASS_InputMethodSubtype, "containsExtraValueKey", String.class);
|
||||||
private static final Method METHOD_getExtraValueOf =
|
private static final Method METHOD_getExtraValueOf =
|
||||||
CompatUtils.getMethod(CLASS_InputMethodSubtype, "getExtraValueOf", String.class);
|
CompatUtils.getMethod(CLASS_InputMethodSubtype, "getExtraValueOf", String.class);
|
||||||
|
private static final Method METHOD_isAuxiliary =
|
||||||
|
CompatUtils.getMethod(CLASS_InputMethodSubtype, "isAuxiliary");
|
||||||
|
|
||||||
private final int mDummyNameResId;
|
private final int mDummyNameResId;
|
||||||
private final int mDummyIconResId;
|
private final int mDummyIconResId;
|
||||||
|
@ -116,6 +118,10 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper
|
||||||
return (String)CompatUtils.invoke(mObj, null, METHOD_getExtraValueOf, key);
|
return (String)CompatUtils.invoke(mObj, null, METHOD_getExtraValueOf, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAuxiliary() {
|
||||||
|
return (Boolean)CompatUtils.invoke(mObj, false, METHOD_isAuxiliary);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDummy() {
|
public boolean isDummy() {
|
||||||
return !hasOriginalObject();
|
return !hasOriginalObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||||
|
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
||||||
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardId;
|
import com.android.inputmethod.keyboard.KeyboardId;
|
||||||
|
@ -43,8 +44,10 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
@ -109,7 +112,34 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManagerCompatWrapper imm) {
|
public static boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManagerCompatWrapper imm) {
|
||||||
return imm.getEnabledInputMethodList().size() > 1
|
final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
|
||||||
|
|
||||||
|
// Filters out IMEs that have auxiliary subtypes only (including either implicitly or
|
||||||
|
// explicitly enabled ones).
|
||||||
|
final ArrayList<InputMethodInfoCompatWrapper> filteredImis =
|
||||||
|
new ArrayList<InputMethodInfoCompatWrapper>();
|
||||||
|
|
||||||
|
outerloop:
|
||||||
|
for (InputMethodInfoCompatWrapper imi : enabledImis) {
|
||||||
|
// We can return true immediately after we find two or more filtered IMEs.
|
||||||
|
if (filteredImis.size() > 1) return true;
|
||||||
|
final List<InputMethodSubtypeCompatWrapper> subtypes =
|
||||||
|
imm.getEnabledInputMethodSubtypeList(imi, true);
|
||||||
|
// IMEs that have no subtypes should be included.
|
||||||
|
if (subtypes.isEmpty()) {
|
||||||
|
filteredImis.add(imi);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// IMEs that have one or more non-auxiliary subtypes should be included.
|
||||||
|
for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
|
||||||
|
if (!subtype.isAuxiliary()) {
|
||||||
|
filteredImis.add(imi);
|
||||||
|
continue outerloop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredImis.size() > 1
|
||||||
// imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
|
// imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
|
||||||
// input method subtype (The current IME should be LatinIME.)
|
// input method subtype (The current IME should be LatinIME.)
|
||||||
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
||||||
|
|
Loading…
Reference in a new issue