diff options
| -rw-r--r-- | api/current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 43 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 31 | ||||
| -rw-r--r-- | 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 98711cf8a2d1..7dfa350c23f1 100644 --- a/api/current.txt +++ b/api/current.txt @@ -47613,6 +47613,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(); @@ -47774,6 +47775,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); @@ -53849,7 +53851,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(); @@ -53872,7 +53873,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 b367dc7b9c50..71b60844b17d 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}. * </p> * + * @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); } } @@ -5213,32 +5209,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} * if it was not already 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 fe34d98ec163..21c10ce89c1a 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3089,6 +3089,9 @@ See {@link android.view.View#setAccessibilityPaneTitle(CharSequence)} --> <attr name="accessibilityPaneTitle" format="string" /> + <!-- Whether or not this view is a heading for accessibility purposes. --> + <attr name="accessibilityHeading" format="boolean"/> + <!-- Sets the color of the spot shadow that is drawn when the view has a positive Z or elevation value. <p> @@ -4956,8 +4959,6 @@ <!-- Justification by stretching word spacing. --> <enum name="inter_word" value = "1" /> </attr> - <!-- Whether or not this view is a heading for accessibility purposes. --> - <attr name="accessibilityHeading" format="boolean"/> </declare-styleable> <declare-styleable name="TextViewAppearance"> <!-- Base text color, typeface, size, and style. --> |