diff options
| author | Jacky Kao <jackykao@google.com> | 2020-01-16 16:08:16 +0800 |
|---|---|---|
| committer | Jacky Kao <jackykao@google.com> | 2020-01-21 08:28:02 +0800 |
| commit | b0873998c55d0ac141381c0a703d936ef1a43150 (patch) | |
| tree | b1f72bcfc05eefa994110ed5516ec79e0d60836d /core/java/android/widget/TextView.java | |
| parent | 35be8b1d52d09d74dc1461f07003d0cca6a7707f (diff) | |
Providing new accessibilityNode action
Providing a new A11yNode action for ime actions:
ACTION_IME_ENTER
1. TextView will expose this action and store the ime action id
if it is editable and has focus.
2. This A11y action which would have default text “Enter” if the
developer didn’t set a custom ime action label, otherwise the label
would be what the developer provided.
3. This A11y action which would have default id,
IME_ACTION_UNSPECIFIED if the developer didn't set a custom ime
action id, otherwise the id would be what the developer provided.
4. TextView will perform this action by calling its onEditorAction
with stored ime action when populating this node.
Bug: 139380257
Test: a11y CTS tests & unit tests
Change-Id: Ifba432f8fda732f8335c40fe27f5e74499621d47
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 32d3fef88e81..6d5de9d4718d 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -422,6 +422,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ static final int PROCESS_TEXT_REQUEST_CODE = 100; + // Accessibility action to send IME custom action for CTS testing. + public static final int ACCESSIBILITY_ACTION_IME_ENTER = R.id.accessibilityActionImeEnter; + /** * Return code of {@link #doKeyDown}. */ @@ -11740,6 +11743,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener info.setContentInvalid(true); info.setError(mEditor.mError); } + // TextView will expose this action if it is editable and has focus. + if (isTextEditable() && isFocused()) { + CharSequence imeActionLabel = mContext.getResources().getString( + com.android.internal.R.string.keyboardview_keycode_enter); + if (getImeActionId() != 0 && getImeActionLabel() != null) { + imeActionLabel = getImeActionLabel(); + final int imeActionId = getImeActionId(); + // put ime action id into the extra data with ACTION_ARGUMENT_IME_ACTION_ID_INT. + final Bundle argument = info.getExtras(); + argument.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_IME_ACTION_ID_INT, + imeActionId); + } + AccessibilityNodeInfo.AccessibilityAction action = + new AccessibilityNodeInfo.AccessibilityAction( + ACCESSIBILITY_ACTION_IME_ENTER, imeActionLabel); + info.addAction(action); + } } if (!TextUtils.isEmpty(mText)) { @@ -12051,6 +12071,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } } return true; + case ACCESSIBILITY_ACTION_IME_ENTER: { + if (isFocused() && isTextEditable()) { + final int imeActionId = (arguments != null) ? arguments.getInt( + AccessibilityNodeInfo.ACTION_ARGUMENT_IME_ACTION_ID_INT, + EditorInfo.IME_ACTION_UNSPECIFIED) + : EditorInfo.IME_ACTION_UNSPECIFIED; + if (imeActionId == getImeActionId()) { + onEditorAction(imeActionId); + } + } + } return true; default: { return super.performAccessibilityActionInternal(action, arguments); } |
