From b0873998c55d0ac141381c0a703d936ef1a43150 Mon Sep 17 00:00:00 2001 From: Jacky Kao Date: Thu, 16 Jan 2020 16:08:16 +0800 Subject: Providing new accessibilityNode action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- core/java/android/widget/TextView.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'core/java/android/widget/TextView.java') 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); } -- cgit v1.2.3