diff options
| author | Yohei Yukawa <yukawa@google.com> | 2021-10-27 13:11:48 -0700 |
|---|---|---|
| committer | Yohei Yukawa <yukawa@google.com> | 2021-10-27 13:11:48 -0700 |
| commit | 4bd98255edbe5b39cd8b0c7f3d6e58843473f6df (patch) | |
| tree | 52f53785b8807f206e7867f081225e6ef37324ee /core/java/android/widget/TextView.java | |
| parent | df08d4937e6553ade3efc70cb30772adc418227a (diff) | |
Require onCheckIsTextEditor() for IME_FLAG_NAVIGATE_{NEXT,PREVIOUS}
TextView#onCreateInputConnection() has automatically set the following
EditorInfo flags depending on the presence of focusable elements next
to it.
* EditorInfo#IME_FLAG_NAVIGATE_NEXT
* EditorInfo#IME_FLAG_NAVIGATE_PREVIOUS
With those flags, IMEs may offer some additional UI for users to
trigger InputConnection#performEditorAction() with the following
command to achieve tabbing navigation to switch to other focusable
elements.
* EditorInfo#IME_ACTION_NEXT
* EditorInfo#IME_ACTION_PREVIOUS
The problem of the current TextView implementation is that it does not
check whether the next element is also a text input field or not. As
a result, users might be navigated to a UI element that does not
natively support InputConnection APIs, which results in connecting the
IME to a fallback InputConnection. We have actually received multiple
bug reports that the IME was still shown but not tapping its keys did
nothing.
Based on such feedback, this CL aims to narrow down the condition to
automatically set those navigation flags in TextView. With this CL,
those flags will no longer be set if the next View in question returns
true from View#onCheckIsTextEditor().
See also the corresponding CTS CL [1] to find examples of how it
behaves now.
[1]: I1b75b85f6c1fa4ff90ffa7d584f033b9510d2a36
Fix: 31099943
Test: atest CtsInputMethodTestCases:EditTextImeSupportTest
Change-Id: Id004a77453952f36a2c572697db31c87518f842f
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 3eaf852b3ac3..8fba58364c94 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8751,6 +8751,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return mEditor != null && mEditor.mInputType != EditorInfo.TYPE_NULL; } + private boolean hasEditorInFocusSearchDirection(@FocusRealDirection int direction) { + final View nextView = focusSearch(direction); + return nextView != null && nextView.onCheckIsTextEditor(); + } + @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { if (onCheckIsTextEditor() && isEnabled()) { @@ -8767,10 +8772,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener outAttrs.imeOptions = EditorInfo.IME_NULL; outAttrs.hintLocales = null; } - if (focusSearch(FOCUS_DOWN) != null) { + if (hasEditorInFocusSearchDirection(FOCUS_DOWN)) { outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_NEXT; } - if (focusSearch(FOCUS_UP) != null) { + if (hasEditorInFocusSearchDirection(FOCUS_UP)) { outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS; } if ((outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION) |
