Loading core/java/android/view/inputmethod/InputMethodSubtype.java +32 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ public final class InputMethodSubtype implements Parcelable { /** {@hide} */ public static final int SUBTYPE_ID_NONE = 0; private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; private static final String UNDEFINED_LANGUAGE_TAG = "und"; private final boolean mIsAuxiliary; private final boolean mOverridesImplicitlyEnabledSubtype; private final boolean mIsAsciiCapable; Loading Loading @@ -432,6 +436,34 @@ public final class InputMethodSubtype implements Parcelable { return result; } /** * Determines whether this {@link InputMethodSubtype} can be used as the key of mapping rules * between {@link InputMethodSubtype} and hardware keyboard layout. * * <p>Note that in a future build may require different rules. Design the system so that the * system can automatically take care of any rule changes upon OTAs.</p> * * @return {@code true} if this {@link InputMethodSubtype} can be used as the key of mapping * rules between {@link InputMethodSubtype} and hardware keyboard layout. * @hide */ public boolean isSuitableForPhysicalKeyboardLayoutMapping() { if (hashCode() == SUBTYPE_ID_NONE) { return false; } if (!TextUtils.equals(getMode(), SUBTYPE_MODE_KEYBOARD)) { return false; } if (isAuxiliary()) { return false; } final String langTag = getCanonicalizedLanguageTag(); if (langTag.isEmpty() || TextUtils.equals(langTag, UNDEFINED_LANGUAGE_TAG)) { return false; } return true; } /** * @return The mode of the subtype. */ Loading core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import org.junit.runner.RunWith; import java.util.Locale; import java.util.Objects; import java.util.function.Supplier; @SmallTest @RunWith(AndroidJUnit4.class) Loading Loading @@ -157,6 +158,34 @@ public class InputMethodSubtypeTest { assertEquals(subtype.getCanonicalizedLanguageTag(), expectedLanguageTag); } @Test public void testIsSuitableForPhysicalKeyboardLayoutMapping() { final Supplier<InputMethodSubtypeBuilder> getValidBuilder = () -> new InputMethodSubtypeBuilder() .setLanguageTag("en-US") .setIsAuxiliary(false) .setSubtypeMode("keyboard") .setSubtypeId(1); assertTrue(getValidBuilder.get().build().isSuitableForPhysicalKeyboardLayoutMapping()); // mode == "voice" is not suitable. assertFalse(getValidBuilder.get().setSubtypeMode("voice").build() .isSuitableForPhysicalKeyboardLayoutMapping()); // Auxiliary subtype not suitable. assertFalse(getValidBuilder.get().setIsAuxiliary(true).build() .isSuitableForPhysicalKeyboardLayoutMapping()); // languageTag == null is not suitable. assertFalse(getValidBuilder.get().setLanguageTag(null).build() .isSuitableForPhysicalKeyboardLayoutMapping()); // languageTag == "und" is not suitable. assertFalse(getValidBuilder.get().setLanguageTag("und").build() .isSuitableForPhysicalKeyboardLayoutMapping()); } private static InputMethodSubtype cloneViaParcel(final InputMethodSubtype original) { Parcel parcel = null; try { Loading Loading
core/java/android/view/inputmethod/InputMethodSubtype.java +32 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ public final class InputMethodSubtype implements Parcelable { /** {@hide} */ public static final int SUBTYPE_ID_NONE = 0; private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; private static final String UNDEFINED_LANGUAGE_TAG = "und"; private final boolean mIsAuxiliary; private final boolean mOverridesImplicitlyEnabledSubtype; private final boolean mIsAsciiCapable; Loading Loading @@ -432,6 +436,34 @@ public final class InputMethodSubtype implements Parcelable { return result; } /** * Determines whether this {@link InputMethodSubtype} can be used as the key of mapping rules * between {@link InputMethodSubtype} and hardware keyboard layout. * * <p>Note that in a future build may require different rules. Design the system so that the * system can automatically take care of any rule changes upon OTAs.</p> * * @return {@code true} if this {@link InputMethodSubtype} can be used as the key of mapping * rules between {@link InputMethodSubtype} and hardware keyboard layout. * @hide */ public boolean isSuitableForPhysicalKeyboardLayoutMapping() { if (hashCode() == SUBTYPE_ID_NONE) { return false; } if (!TextUtils.equals(getMode(), SUBTYPE_MODE_KEYBOARD)) { return false; } if (isAuxiliary()) { return false; } final String langTag = getCanonicalizedLanguageTag(); if (langTag.isEmpty() || TextUtils.equals(langTag, UNDEFINED_LANGUAGE_TAG)) { return false; } return true; } /** * @return The mode of the subtype. */ Loading
core/tests/coretests/src/android/view/inputmethod/InputMethodSubtypeTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import org.junit.runner.RunWith; import java.util.Locale; import java.util.Objects; import java.util.function.Supplier; @SmallTest @RunWith(AndroidJUnit4.class) Loading Loading @@ -157,6 +158,34 @@ public class InputMethodSubtypeTest { assertEquals(subtype.getCanonicalizedLanguageTag(), expectedLanguageTag); } @Test public void testIsSuitableForPhysicalKeyboardLayoutMapping() { final Supplier<InputMethodSubtypeBuilder> getValidBuilder = () -> new InputMethodSubtypeBuilder() .setLanguageTag("en-US") .setIsAuxiliary(false) .setSubtypeMode("keyboard") .setSubtypeId(1); assertTrue(getValidBuilder.get().build().isSuitableForPhysicalKeyboardLayoutMapping()); // mode == "voice" is not suitable. assertFalse(getValidBuilder.get().setSubtypeMode("voice").build() .isSuitableForPhysicalKeyboardLayoutMapping()); // Auxiliary subtype not suitable. assertFalse(getValidBuilder.get().setIsAuxiliary(true).build() .isSuitableForPhysicalKeyboardLayoutMapping()); // languageTag == null is not suitable. assertFalse(getValidBuilder.get().setLanguageTag(null).build() .isSuitableForPhysicalKeyboardLayoutMapping()); // languageTag == "und" is not suitable. assertFalse(getValidBuilder.get().setLanguageTag("und").build() .isSuitableForPhysicalKeyboardLayoutMapping()); } private static InputMethodSubtype cloneViaParcel(final InputMethodSubtype original) { Parcel parcel = null; try { Loading