diff options
| -rw-r--r-- | api/current.txt | 6 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 45 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityEvent.java | 9 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityNodeInfo.java | 35 | ||||
| -rw-r--r-- | core/res/res/values/attrs.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 1 |
6 files changed, 98 insertions, 2 deletions
diff --git a/api/current.txt b/api/current.txt index 8db2c2930b16..a75bbfa0a800 100644 --- a/api/current.txt +++ b/api/current.txt @@ -212,6 +212,7 @@ package android { field public static final int accessibilityFeedbackType = 16843650; // 0x1010382 field public static final int accessibilityFlags = 16843652; // 0x1010384 field public static final int accessibilityLiveRegion = 16843758; // 0x10103ee + field public static final int accessibilityPaneTitle = 16844156; // 0x101057c field public static final int accessibilityTraversalAfter = 16843986; // 0x10104d2 field public static final int accessibilityTraversalBefore = 16843985; // 0x10104d1 field public static final int accountPreferences = 16843423; // 0x101029f @@ -46291,6 +46292,7 @@ package android.view { method public java.lang.CharSequence getAccessibilityClassName(); method public int getAccessibilityLiveRegion(); method public android.view.accessibility.AccessibilityNodeProvider getAccessibilityNodeProvider(); + method public java.lang.CharSequence getAccessibilityPaneTitle(); method public int getAccessibilityTraversalAfter(); method public int getAccessibilityTraversalBefore(); method public float getAlpha(); @@ -46614,6 +46616,7 @@ package android.view { method public void sendAccessibilityEventUnchecked(android.view.accessibility.AccessibilityEvent); method public void setAccessibilityDelegate(android.view.View.AccessibilityDelegate); method public void setAccessibilityLiveRegion(int); + method public void setAccessibilityPaneTitle(java.lang.CharSequence); method public void setAccessibilityTraversalAfter(int); method public void setAccessibilityTraversalBefore(int); method public void setActivated(boolean); @@ -48011,6 +48014,7 @@ package android.view.accessibility { method public void setPackageName(java.lang.CharSequence); method public void writeToParcel(android.os.Parcel, int); field public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 4; // 0x4 + field public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 8; // 0x8 field public static final int CONTENT_CHANGE_TYPE_SUBTREE = 1; // 0x1 field public static final int CONTENT_CHANGE_TYPE_TEXT = 2; // 0x2 field public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0; // 0x0 @@ -48121,6 +48125,7 @@ package android.view.accessibility { method public int getMaxTextLength(); method public int getMovementGranularities(); method public java.lang.CharSequence getPackageName(); + method public java.lang.CharSequence getPaneTitle(); method public android.view.accessibility.AccessibilityNodeInfo getParent(); method public android.view.accessibility.AccessibilityNodeInfo.RangeInfo getRangeInfo(); method public java.lang.CharSequence getText(); @@ -48198,6 +48203,7 @@ package android.view.accessibility { method public void setMovementGranularities(int); method public void setMultiLine(boolean); method public void setPackageName(java.lang.CharSequence); + method public void setPaneTitle(java.lang.CharSequence); method public void setParent(android.view.View); method public void setParent(android.view.View, int); method public void setPassword(boolean); diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f62189e4b4a1..71ee7efd71d3 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4045,6 +4045,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, private CharSequence mContentDescription; /** + * If this view represents a distinct part of the window, it can have a title that labels the + * area. + */ + private CharSequence mAccessibilityPaneTitle; + + /** * Specifies the id of a view for which this view serves as a label for * accessibility purposes. */ @@ -5409,6 +5415,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, setScreenReaderFocusable(a.getBoolean(attr, false)); } break; + case R.styleable.View_accessibilityPaneTitle: + if (a.peekValue(attr) != null) { + setAccessibilityPaneTitle(a.getString(attr)); + } + break; } } @@ -7218,6 +7229,35 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * If this view is a visually distinct portion of a window, for example the content view of + * a fragment that is replaced, it is considered a pane for accessibility purposes. In order + * for accessibility services to understand the views role, and to announce its title as + * appropriate, such views should have pane titles. + * + * @param accessibilityPaneTitle The pane's title. + * + * {@see AccessibilityNodeInfo#setPaneTitle(CharSequence)} + */ + public void setAccessibilityPaneTitle(CharSequence accessibilityPaneTitle) { + if (!TextUtils.equals(accessibilityPaneTitle, mAccessibilityPaneTitle)) { + mAccessibilityPaneTitle = accessibilityPaneTitle; + notifyViewAccessibilityStateChangedIfNeeded( + AccessibilityEvent.CONTENT_CHANGE_TYPE_PANE_TITLE); + } + } + + /** + * Get the title of the pane for purposes of accessibility. + * + * @return The current pane title. + * + * {@see #setAccessibilityPaneTitle}. + */ + public CharSequence getAccessibilityPaneTitle() { + return mAccessibilityPaneTitle; + } + + /** * Sends an accessibility event of the given type. If accessibility is * not enabled this method has no effect. The default implementation calls * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first @@ -8514,6 +8554,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, info.addAction(AccessibilityAction.ACTION_SHOW_ON_SCREEN); populateAccessibilityNodeInfoDrawingOrderInParent(info); + info.setPaneTitle(mAccessibilityPaneTitle); } /** @@ -11405,6 +11446,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * {@link #getAccessibilityLiveRegion()} is not * {@link #ACCESSIBILITY_LIVE_REGION_NONE}. * </ul> + * <li>Has an accessibility pane title, see {@link #setAccessibilityPaneTitle}</li> * </ol> * * @return Whether the view is exposed for accessibility. @@ -11431,7 +11473,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return mode == IMPORTANT_FOR_ACCESSIBILITY_YES || isActionableForAccessibility() || hasListenersForAccessibility() || getAccessibilityNodeProvider() != null - || getAccessibilityLiveRegion() != ACCESSIBILITY_LIVE_REGION_NONE; + || getAccessibilityLiveRegion() != ACCESSIBILITY_LIVE_REGION_NONE + || (mAccessibilityPaneTitle != null); } /** diff --git a/core/java/android/view/accessibility/AccessibilityEvent.java b/core/java/android/view/accessibility/AccessibilityEvent.java index 56efcdf862c2..aa61926dcedc 100644 --- a/core/java/android/view/accessibility/AccessibilityEvent.java +++ b/core/java/android/view/accessibility/AccessibilityEvent.java @@ -565,6 +565,12 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par public static final int CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004; /** + * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: + * The node's pane title changed. + */ + public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 0x00000008; + + /** * Change type for {@link #TYPE_WINDOWS_CHANGED} event: * The window was added. */ @@ -654,7 +660,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par CONTENT_CHANGE_TYPE_UNDEFINED, CONTENT_CHANGE_TYPE_SUBTREE, CONTENT_CHANGE_TYPE_TEXT, - CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION + CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION, + CONTENT_CHANGE_TYPE_PANE_TITLE }) public @interface ContentChangeTypes {} diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java index 28ef6978ac93..311dd4b8b294 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java @@ -723,6 +723,7 @@ public class AccessibilityNodeInfo implements Parcelable { private CharSequence mText; private CharSequence mHintText; private CharSequence mError; + private CharSequence mPaneTitle; private CharSequence mContentDescription; private String mViewIdResourceName; private ArrayList<String> mExtraDataKeys; @@ -2033,6 +2034,33 @@ public class AccessibilityNodeInfo implements Parcelable { } /** + * If this node represents a visually distinct region of the screen that may update separately + * from the rest of the window, it is considered a pane. Set the pane title to indicate that + * the node is a pane, and to provide a title for it. + * <p> + * <strong>Note:</strong> Cannot be called from an + * {@link android.accessibilityservice.AccessibilityService}. + * This class is made immutable before being delivered to an AccessibilityService. + * </p> + * @param paneTitle The title of the pane represented by this node. + */ + public void setPaneTitle(@Nullable CharSequence paneTitle) { + enforceNotSealed(); + mPaneTitle = (paneTitle == null) + ? null : paneTitle.subSequence(0, paneTitle.length()); + } + + /** + * Get the title of the pane represented by this node. + * + * @return The title of the pane represented by this node, or {@code null} if this node does + * not represent a pane. + */ + public @Nullable CharSequence getPaneTitle() { + return mPaneTitle; + } + + /** * Get the drawing order of the view corresponding it this node. * <p> * Drawing order is determined only within the node's parent, so this index is only relative @@ -3151,6 +3179,10 @@ public class AccessibilityNodeInfo implements Parcelable { nonDefaultFields |= bitAt(fieldIndex); } fieldIndex++; + if (!Objects.equals(mPaneTitle, DEFAULT.mPaneTitle)) { + nonDefaultFields |= bitAt(fieldIndex); + } + fieldIndex++; if (!Objects.equals(mViewIdResourceName, DEFAULT.mViewIdResourceName)) { nonDefaultFields |= bitAt(fieldIndex); } @@ -3270,6 +3302,7 @@ public class AccessibilityNodeInfo implements Parcelable { if (isBitSet(nonDefaultFields, fieldIndex++)) { parcel.writeCharSequence(mContentDescription); } + if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mPaneTitle); if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeString(mViewIdResourceName); if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeInt(mTextSelectionStart); @@ -3341,6 +3374,7 @@ public class AccessibilityNodeInfo implements Parcelable { mHintText = other.mHintText; mError = other.mError; mContentDescription = other.mContentDescription; + mPaneTitle = other.mPaneTitle; mViewIdResourceName = other.mViewIdResourceName; if (mActions != null) mActions.clear(); @@ -3461,6 +3495,7 @@ public class AccessibilityNodeInfo implements Parcelable { if (isBitSet(nonDefaultFields, fieldIndex++)) { mContentDescription = parcel.readCharSequence(); } + if (isBitSet(nonDefaultFields, fieldIndex++)) mPaneTitle = parcel.readString(); if (isBitSet(nonDefaultFields, fieldIndex++)) mViewIdResourceName = parcel.readString(); if (isBitSet(nonDefaultFields, fieldIndex++)) mTextSelectionStart = parcel.readInt(); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index ee7c7952ab78..79c8e04caefa 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3030,6 +3030,10 @@ value, {@code false}, leaves the screen reader to consider other signals, such as focusability or the presence of text, to decide what it focus.--> <attr name="screenReaderFocusable" format="boolean" /> + + <!-- The title this view should present to accessibility as a pane title. + See {@link android.view.View#setAccessibilityPaneTitle(CharSequence)} --> + <attr name="accessibilityPaneTitle" format="string" /> </declare-styleable> <!-- Attributes that can be assigned to a tag for a particular View. --> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 6ec88dc8346b..58ae76cdf160 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2861,6 +2861,7 @@ <public name="widgetFeatures" /> <public name="appComponentFactory" /> <public name="fallbackLineSpacing" /> + <public name="accessibilityPaneTitle" /> </public-group> <public-group type="style" first-id="0x010302e0"> |