From 06a8880edf4c00713e0f680e04f0eb88d7acf102 Mon Sep 17 00:00:00 2001 From: skxu Date: Wed, 1 Dec 2021 17:44:45 +0000 Subject: [PATCH] Add new IME attr This new attr will allow IME to specify whether they support inline suggestion with touch exploration Fixes: 207007377 Test: atest android.view.inputmethod.InputMethodInfoTest Change-Id: I1fa36d7fd57a9b25838d4dd48243c19630495648 --- core/api/current.txt | 1 + .../view/inputmethod/InputMethodInfo.java | 42 ++++++++++++++++--- core/res/res/values/attrs.xml | 8 ++++ core/res/res/values/public.xml | 1 + ...ine_suggestions_with_touch_exploration.xml | 28 +++++++++++++ .../view/inputmethod/InputMethodInfoTest.java | 14 +++++++ 6 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 core/tests/coretests/res/xml/ime_meta_inline_suggestions_with_touch_exploration.xml diff --git a/core/api/current.txt b/core/api/current.txt index 51c9ad778ab4b..01edfafa0b805 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -1453,6 +1453,7 @@ package android { field public static final int supportsAssist = 16844016; // 0x10104f0 field public static final int supportsBatteryGameMode; field public static final int supportsInlineSuggestions = 16844301; // 0x101060d + field public static final int supportsInlineSuggestionsWithTouchExploration; field public static final int supportsLaunchVoiceAssistFromKeyguard = 16844017; // 0x10104f1 field public static final int supportsLocalInteraction = 16844047; // 0x101050f field public static final int supportsMultipleDisplays = 16844182; // 0x1010596 diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index 9a706673583bd..d7c18462077d6 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -64,6 +64,7 @@ import java.util.List; * @attr ref android.R.styleable#InputMethod_isDefault * @attr ref android.R.styleable#InputMethod_supportsSwitchingToNextInputMethod * @attr ref android.R.styleable#InputMethod_supportsInlineSuggestions + * @attr ref android.R.styleable#InputMethod_supportsInlineSuggestionsWithTouchExploration * @attr ref android.R.styleable#InputMethod_suppressesSpellChecker * @attr ref android.R.styleable#InputMethod_showInInputMethodPicker * @attr ref android.R.styleable#InputMethod_configChanges @@ -124,6 +125,11 @@ public final class InputMethodInfo implements Parcelable { */ private final boolean mInlineSuggestionsEnabled; + /** + * The flag whether this IME supports inline suggestions when touch exploration is enabled. + */ + private final boolean mSupportsInlineSuggestionsWithTouchExploration; + /** * The flag whether this IME suppresses spell checker. */ @@ -189,6 +195,7 @@ public final class InputMethodInfo implements Parcelable { boolean isAuxIme = true; boolean supportsSwitchingToNextInputMethod = false; // false as default boolean inlineSuggestionsEnabled = false; // false as default + boolean supportsInlineSuggestionsWithTouchExploration = false; // false as default boolean suppressesSpellChecker = false; // false as default boolean showInInputMethodPicker = true; // true as default mForceDefault = false; @@ -234,6 +241,9 @@ public final class InputMethodInfo implements Parcelable { false); inlineSuggestionsEnabled = sa.getBoolean( com.android.internal.R.styleable.InputMethod_supportsInlineSuggestions, false); + supportsInlineSuggestionsWithTouchExploration = sa.getBoolean( + com.android.internal.R.styleable + .InputMethod_supportsInlineSuggestionsWithTouchExploration, false); suppressesSpellChecker = sa.getBoolean( com.android.internal.R.styleable.InputMethod_suppressesSpellChecker, false); showInInputMethodPicker = sa.getBoolean( @@ -314,6 +324,8 @@ public final class InputMethodInfo implements Parcelable { mIsAuxIme = isAuxIme; mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; mInlineSuggestionsEnabled = inlineSuggestionsEnabled; + mSupportsInlineSuggestionsWithTouchExploration = + supportsInlineSuggestionsWithTouchExploration; mSuppressesSpellChecker = suppressesSpellChecker; mShowInInputMethodPicker = showInInputMethodPicker; mIsVrOnly = isVrOnly; @@ -326,6 +338,7 @@ public final class InputMethodInfo implements Parcelable { mIsAuxIme = source.readInt() == 1; mSupportsSwitchingToNextInputMethod = source.readInt() == 1; mInlineSuggestionsEnabled = source.readInt() == 1; + mSupportsInlineSuggestionsWithTouchExploration = source.readInt() == 1; mSuppressesSpellChecker = source.readBoolean(); mShowInInputMethodPicker = source.readBoolean(); mIsVrOnly = source.readBoolean(); @@ -345,7 +358,8 @@ public final class InputMethodInfo implements Parcelable { settingsActivity, null /* subtypes */, 0 /* isDefaultResId */, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */, false /* isVrOnly */, - 0 /* handledConfigChanges */, false /* supportsStylusHandwriting */); + 0 /* handledConfigChanges */, false /* supportsStylusHandwriting */, + false /* inlineSuggestionsEnabled */); } /** @@ -360,7 +374,8 @@ public final class InputMethodInfo implements Parcelable { settingsActivity, null /* subtypes */, 0 /* isDefaultResId */, false /* forceDefault */, true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */, false /* isVrOnly */, handledConfigChanges, - false /* supportsStylusHandwriting */); + false /* supportsStylusHandwriting */, + false /* inlineSuggestionsEnabled */); } /** @@ -373,7 +388,8 @@ public final class InputMethodInfo implements Parcelable { this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, true /* supportsSwitchingToNextInputMethod */, false /* inlineSuggestionsEnabled */, false /* isVrOnly */, 0 /* handledconfigChanges */, - false /* supportsStylusHandwriting */); + false /* supportsStylusHandwriting */, + false /* inlineSuggestionsEnabled */); } /** @@ -385,7 +401,8 @@ public final class InputMethodInfo implements Parcelable { boolean supportsSwitchingToNextInputMethod, boolean isVrOnly) { this(ri, isAuxIme, settingsActivity, subtypes, isDefaultResId, forceDefault, supportsSwitchingToNextInputMethod, false /* inlineSuggestionsEnabled */, isVrOnly, - 0 /* handledConfigChanges */, false /* supportsStylusHandwriting */); + 0 /* handledConfigChanges */, false /* supportsStylusHandwriting */, + false /* inlineSuggestionsEnabled */); } /** @@ -395,7 +412,8 @@ public final class InputMethodInfo implements Parcelable { public InputMethodInfo(ResolveInfo ri, boolean isAuxIme, String settingsActivity, List subtypes, int isDefaultResId, boolean forceDefault, boolean supportsSwitchingToNextInputMethod, boolean inlineSuggestionsEnabled, - boolean isVrOnly, int handledConfigChanges, boolean supportsStylusHandwriting) { + boolean isVrOnly, int handledConfigChanges, boolean supportsStylusHandwriting, + boolean supportsInlineSuggestionsWithTouchExploration) { final ServiceInfo si = ri.serviceInfo; mService = ri; mId = new ComponentName(si.packageName, si.name).flattenToShortString(); @@ -406,6 +424,8 @@ public final class InputMethodInfo implements Parcelable { mForceDefault = forceDefault; mSupportsSwitchingToNextInputMethod = supportsSwitchingToNextInputMethod; mInlineSuggestionsEnabled = inlineSuggestionsEnabled; + mSupportsInlineSuggestionsWithTouchExploration = + supportsInlineSuggestionsWithTouchExploration; mSuppressesSpellChecker = false; mShowInInputMethodPicker = true; mIsVrOnly = isVrOnly; @@ -583,6 +603,8 @@ public final class InputMethodInfo implements Parcelable { + " mIsVrOnly=" + mIsVrOnly + " mSupportsSwitchingToNextInputMethod=" + mSupportsSwitchingToNextInputMethod + " mInlineSuggestionsEnabled=" + mInlineSuggestionsEnabled + + " mSupportsInlineSuggestionsWithTouchExploration=" + + mSupportsInlineSuggestionsWithTouchExploration + " mSuppressesSpellChecker=" + mSuppressesSpellChecker + " mShowInInputMethodPicker=" + mShowInInputMethodPicker + " mSupportsStylusHandwriting=" + mSupportsStylusHandwriting); @@ -653,6 +675,15 @@ public final class InputMethodInfo implements Parcelable { return mInlineSuggestionsEnabled; } + /** + * Returns {@code true} if this input method supports inline suggestions when touch exploration + * is enabled. + * @hide + */ + public boolean supportsInlineSuggestionsWithTouchExploration() { + return mSupportsInlineSuggestionsWithTouchExploration; + } + /** * Return {@code true} if this input method suppresses spell checker. */ @@ -683,6 +714,7 @@ public final class InputMethodInfo implements Parcelable { dest.writeInt(mIsAuxIme ? 1 : 0); dest.writeInt(mSupportsSwitchingToNextInputMethod ? 1 : 0); dest.writeInt(mInlineSuggestionsEnabled ? 1 : 0); + dest.writeInt(mSupportsInlineSuggestionsWithTouchExploration ? 1 : 0); dest.writeBoolean(mSuppressesSpellChecker); dest.writeBoolean(mShowInInputMethodPicker); dest.writeBoolean(mIsVrOnly); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index fca2bd15787d1..3a2401a970094 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3644,6 +3644,14 @@ + + + + + + diff --git a/core/tests/coretests/src/android/view/inputmethod/InputMethodInfoTest.java b/core/tests/coretests/src/android/view/inputmethod/InputMethodInfoTest.java index 8718b954474af..e7d7d640324d0 100644 --- a/core/tests/coretests/src/android/view/inputmethod/InputMethodInfoTest.java +++ b/core/tests/coretests/src/android/view/inputmethod/InputMethodInfoTest.java @@ -55,11 +55,13 @@ public class InputMethodInfoTest { assertThat(imi.supportsSwitchingToNextInputMethod(), is(false)); assertThat(imi.isInlineSuggestionsEnabled(), is(false)); + assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(false)); final InputMethodInfo clone = cloneViaParcel(imi); assertThat(clone.supportsSwitchingToNextInputMethod(), is(false)); assertThat(imi.isInlineSuggestionsEnabled(), is(false)); + assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(false)); } @Test @@ -84,6 +86,18 @@ public class InputMethodInfoTest { assertThat(clone.isInlineSuggestionsEnabled(), is(true)); } + @Test + public void testInlineSuggestionsEnabledWithTouchExploration() throws Exception { + final InputMethodInfo imi = + buildInputMethodForTest(R.xml.ime_meta_inline_suggestions_with_touch_exploration); + + assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(true)); + + final InputMethodInfo clone = cloneViaParcel(imi); + + assertThat(clone.supportsInlineSuggestionsWithTouchExploration(), is(true)); + } + @Test public void testIsVrOnly() throws Exception { final InputMethodInfo imi = buildInputMethodForTest(R.xml.ime_meta_vr_only);