From 11fa71845bead86b27600ef8712365065defece2 Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Tue, 10 Apr 2018 17:54:17 -0700 Subject: Move accessibilityHeader from TextView to View I put it on TextView to try to scope it as narrowly as possible, but an ImageView could be a heading, as could a LinearLayout that holds a TextView (like a preference). Bug: 77726494 Test: atest CtsAccessibilityServiceTestCases Change-Id: I9313ce6de25b5893db450f23499b151a4f08afda --- api/current.txt | 4 ++-- core/java/android/view/View.java | 43 ++++++++++++++++++++++++++++++---- core/java/android/widget/TextView.java | 31 ------------------------ core/res/res/values/attrs.xml | 5 ++-- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/api/current.txt b/api/current.txt index 2572cd3d0dfd..bf806ac78d27 100644 --- a/api/current.txt +++ b/api/current.txt @@ -47598,6 +47598,7 @@ package android.view { method public void invalidateDrawable(android.graphics.drawable.Drawable); method public void invalidateOutline(); method public boolean isAccessibilityFocused(); + method public boolean isAccessibilityHeading(); method public boolean isActivated(); method public boolean isAttachedToWindow(); method public boolean isClickable(); @@ -47759,6 +47760,7 @@ package android.view { method public void sendAccessibilityEvent(int); method public void sendAccessibilityEventUnchecked(android.view.accessibility.AccessibilityEvent); method public void setAccessibilityDelegate(android.view.View.AccessibilityDelegate); + method public void setAccessibilityHeading(boolean); method public void setAccessibilityLiveRegion(int); method public void setAccessibilityPaneTitle(java.lang.CharSequence); method public void setAccessibilityTraversalAfter(int); @@ -53834,7 +53836,6 @@ package android.widget { method public android.graphics.Typeface getTypeface(); method public android.text.style.URLSpan[] getUrls(); method public boolean hasSelection(); - method public boolean isAccessibilityHeading(); method public boolean isAllCaps(); method public boolean isCursorVisible(); method public boolean isElegantTextHeight(); @@ -53857,7 +53858,6 @@ package android.widget { method protected void onTextChanged(java.lang.CharSequence, int, int, int); method public boolean onTextContextMenuItem(int); method public void removeTextChangedListener(android.text.TextWatcher); - method public void setAccessibilityHeading(boolean); method public void setAllCaps(boolean); method public final void setAutoLinkMask(int); method public void setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index dc58f11e83fd..cb7c12a9b2f2 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -697,6 +697,7 @@ import java.util.function.Predicate; * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. *

* + * @attr ref android.R.styleable#View_accessibilityHeading * @attr ref android.R.styleable#View_alpha * @attr ref android.R.styleable#View_background * @attr ref android.R.styleable#View_clickable @@ -2955,7 +2956,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * 1 PFLAG3_SCREEN_READER_FOCUSABLE * 1 PFLAG3_AGGREGATED_VISIBLE * 1 PFLAG3_AUTOFILLID_EXPLICITLY_SET - * 1 available + * 1 PFLAG3_ACCESSIBILITY_HEADING * |-------|-------|-------|-------| */ @@ -3252,6 +3253,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private static final int PFLAG3_AUTOFILLID_EXPLICITLY_SET = 0x40000000; + /** + * Indicates if the View is a heading for accessibility purposes + */ + private static final int PFLAG3_ACCESSIBILITY_HEADING = 0x80000000; + /* End of masks for mPrivateFlags3 */ /** @@ -5475,6 +5481,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, case R.styleable.View_outlineAmbientShadowColor: setOutlineAmbientShadowColor(a.getColor(attr, Color.BLACK)); break; + case com.android.internal.R.styleable.View_accessibilityHeading: + setAccessibilityHeading(a.getBoolean(attr, false)); } } @@ -8795,6 +8803,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, info.addAction(AccessibilityAction.ACTION_SHOW_ON_SCREEN); populateAccessibilityNodeInfoDrawingOrderInParent(info); info.setPaneTitle(mAccessibilityPaneTitle); + info.setHeading(isAccessibilityHeading()); } /** @@ -10782,11 +10791,37 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * accessibility tools. */ public void setScreenReaderFocusable(boolean screenReaderFocusable) { + updatePflags3AndNotifyA11yIfChanged(PFLAG3_SCREEN_READER_FOCUSABLE, screenReaderFocusable); + } + + /** + * Gets whether this view is a heading for accessibility purposes. + * + * @return {@code true} if the view is a heading, {@code false} otherwise. + * + * @attr ref android.R.styleable#View_accessibilityHeading + */ + public boolean isAccessibilityHeading() { + return (mPrivateFlags3 & PFLAG3_ACCESSIBILITY_HEADING) != 0; + } + + /** + * Set if view is a heading for a section of content for accessibility purposes. + * + * @param isHeading {@code true} if the view is a heading, {@code false} otherwise. + * + * @attr ref android.R.styleable#View_accessibilityHeading + */ + public void setAccessibilityHeading(boolean isHeading) { + updatePflags3AndNotifyA11yIfChanged(PFLAG3_ACCESSIBILITY_HEADING, isHeading); + } + + private void updatePflags3AndNotifyA11yIfChanged(int mask, boolean newValue) { int pflags3 = mPrivateFlags3; - if (screenReaderFocusable) { - pflags3 |= PFLAG3_SCREEN_READER_FOCUSABLE; + if (newValue) { + pflags3 |= mask; } else { - pflags3 &= ~PFLAG3_SCREEN_READER_FOCUSABLE; + pflags3 &= ~mask; } if (pflags3 != mPrivateFlags3) { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index fae6db5d694f..7b9ecca075ff 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -317,7 +317,6 @@ import java.util.function.Supplier; * @attr ref android.R.styleable#TextView_autoSizeMaxTextSize * @attr ref android.R.styleable#TextView_autoSizeStepGranularity * @attr ref android.R.styleable#TextView_autoSizePresetSizes - * @attr ref android.R.styleable#TextView_accessibilityHeading */ @RemoteView public class TextView extends View implements ViewTreeObserver.OnPreDrawListener { @@ -417,7 +416,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private int mCurTextColor; private int mCurHintTextColor; private boolean mFreezesText; - private boolean mIsAccessibilityHeading; private Editable.Factory mEditableFactory = Editable.Factory.getInstance(); private Spannable.Factory mSpannableFactory = Spannable.Factory.getInstance(); @@ -1294,8 +1292,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case com.android.internal.R.styleable.TextView_lineHeight: lineHeight = a.getDimensionPixelSize(attr, -1); break; - case com.android.internal.R.styleable.TextView_accessibilityHeading: - mIsAccessibilityHeading = a.getBoolean(attr, false); } } @@ -5212,32 +5208,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - /** - * Gets whether this view is a heading for accessibility purposes. - * - * @return {@code true} if the view is a heading, {@code false} otherwise. - * - * @attr ref android.R.styleable#TextView_accessibilityHeading - */ - public boolean isAccessibilityHeading() { - return mIsAccessibilityHeading; - } - - /** - * Set if view is a heading for a section of content for accessibility purposes. - * - * @param isHeading {@code true} if the view is a heading, {@code false} otherwise. - * - * @attr ref android.R.styleable#TextView_accessibilityHeading - */ - public void setAccessibilityHeading(boolean isHeading) { - if (isHeading != mIsAccessibilityHeading) { - mIsAccessibilityHeading = isHeading; - notifyViewAccessibilityStateChangedIfNeeded( - AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED); - } - } - /** * Convenience method to append the specified text to the TextView's * display buffer, upgrading it to {@link android.widget.TextView.BufferType#EDITABLE} @@ -10833,7 +10803,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener info.setText(getTextForAccessibility()); info.setHintText(mHint); info.setShowingHintText(isShowingHint()); - info.setHeading(mIsAccessibilityHeading); if (mBufferType == BufferType.EDITABLE) { info.setEditable(true); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index aceba0879368..538a38639129 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3092,6 +3092,9 @@ See {@link android.view.View#setAccessibilityPaneTitle(CharSequence)} --> + + + - - -- cgit v1.2.3-59-g8ed1b