diff options
| author | yingleiw <yingleiw@google.com> | 2021-11-09 15:47:03 -0800 |
|---|---|---|
| committer | yingleiw <yingleiw@google.com> | 2021-12-02 12:04:52 -0800 |
| commit | fbfd734049a5efd404bb4b1728d5205bd34a2c13 (patch) | |
| tree | ab465b0a6164c4dfdcb69c4253c5e64feaf52eaa /core/java/android/widget/TextView.java | |
| parent | 32cb668a406660839ef6357e26fe655bf5fd3d9d (diff) | |
Add AccessibilityAction ACTION_SHOW_SUGGESTIONS
And implement it for editable text to show the popup
window for typo correction.
Bug: b/143378480
Test: tested with modified talkback.
Change-Id: I8bb1ec87f6bb2177fb4b8fb9a88bfbe10b374173
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 496fa67498eb..014340197393 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -12105,6 +12105,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (canCut()) { info.addAction(AccessibilityNodeInfo.ACTION_CUT); } + if (canReplace()) { + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SHOW_SUGGESTIONS); + } if (canShare()) { info.addAction(new AccessibilityNodeInfo.AccessibilityAction( ACCESSIBILITY_ACTION_SHARE, @@ -12419,6 +12422,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } return false; default: { + // New ids have static blocks to assign values, so they can't be used in a case + // block. + if (action == R.id.accessibilityActionShowSuggestions) { + return isFocused() && canReplace() && onTextContextMenuItem(ID_REPLACE); + } return super.performAccessibilityActionInternal(action, arguments); } } @@ -13005,6 +13013,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; } + boolean canReplace() { + if (hasPasswordTransformationMethod()) { + return false; + } + + return (mText.length() > 0) && (mText instanceof Editable) && (mEditor != null) + && isSuggestionsEnabled() && mEditor.shouldOfferToShowSuggestions(); + } + boolean canShare() { if (!getContext().canStartActivityForResult() || !isDeviceProvisioned()) { return false; |
