Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f26b3de authored by Phil Weaver's avatar Phil Weaver
Browse files

A11y support for titles of "panes"

Panes are a distinct portion of a window. Adding APIs to
support this concept.

Bug: 62231686
Test: Adding a new CTS test to verify that this value is
communicated properly to accessibility services.

Change-Id: I6edd08ec90e40640e71f5a3df292e8f15d5bcda4
parent 7a2c9d98
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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
@@ -46190,6 +46191,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();
@@ -46513,6 +46515,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);
@@ -47910,6 +47913,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
@@ -48020,6 +48024,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();
@@ -48097,6 +48102,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);
+44 −1
Original line number Diff line number Diff line
@@ -4044,6 +4044,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;
            }
        }
@@ -7217,6 +7228,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
@@ -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);
    }
    /**
+8 −1
Original line number Diff line number Diff line
@@ -564,6 +564,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 {}

+35 −0
Original line number Diff line number Diff line
@@ -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;
@@ -2032,6 +2033,33 @@ public class AccessibilityNodeInfo implements Parcelable {
        setBooleanProperty(BOOLEAN_PROPERTY_EDITABLE, editable);
    }

    /**
     * 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>
@@ -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();
+4 −0
Original line number Diff line number Diff line
@@ -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. -->
Loading