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

Commit e1012e98 authored by Wenyu Zhang's avatar Wenyu Zhang
Browse files

a11y: Add sort direction API

API proposal doc: go/aria-sort-android-api.

Change-Id: I3bea12308f424a0a684aca3237b974ec1d676c83
Bug: b/411187064
Flag: android.view.accessibility.a11y_sort_direction_api
parent 5a02a939
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -56327,6 +56327,7 @@ package android.view.accessibility {
    field public static final int CONTENT_CHANGE_TYPE_PANE_APPEARED = 16; // 0x10
    field public static final int CONTENT_CHANGE_TYPE_PANE_DISAPPEARED = 32; // 0x20
    field public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 8; // 0x8
    field @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public static final int CONTENT_CHANGE_TYPE_SORT_DIRECTION = 65536; // 0x10000
    field public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 64; // 0x40
    field public static final int CONTENT_CHANGE_TYPE_SUBTREE = 1; // 0x1
    field @FlaggedApi("android.view.accessibility.supplemental_description") public static final int CONTENT_CHANGE_TYPE_SUPPLEMENTAL_DESCRIPTION = 32768; // 0x8000
@@ -56778,10 +56779,15 @@ package android.view.accessibility {
    method public int getRowIndex();
    method public int getRowSpan();
    method @Nullable public String getRowTitle();
    method @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public int getSortDirection();
    method @Deprecated public boolean isHeading();
    method public boolean isSelected();
    method @Deprecated public static android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo obtain(int, int, int, int, boolean);
    method @Deprecated public static android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo obtain(int, int, int, int, boolean, boolean);
    field @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public static final int SORT_DIRECTION_ASCENDING = 1; // 0x1
    field @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public static final int SORT_DIRECTION_DESCENDING = 2; // 0x2
    field @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public static final int SORT_DIRECTION_NONE = 0; // 0x0
    field @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") public static final int SORT_DIRECTION_OTHER = 3; // 0x3
  }
  public static final class AccessibilityNodeInfo.CollectionItemInfo.Builder {
@@ -56795,6 +56801,7 @@ package android.view.accessibility {
    method @NonNull public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo.Builder setRowSpan(int);
    method @NonNull public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo.Builder setRowTitle(@Nullable String);
    method @NonNull public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo.Builder setSelected(boolean);
    method @FlaggedApi("android.view.accessibility.a11y_sort_direction_api") @NonNull public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo.Builder setSortDirection(int);
  }
  public static final class AccessibilityNodeInfo.ExtraRenderingInfo {
+16 −0
Original line number Diff line number Diff line
@@ -827,6 +827,22 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
    @FlaggedApi(Flags.FLAG_SUPPLEMENTAL_DESCRIPTION)
    public static final int CONTENT_CHANGE_TYPE_SUPPLEMENTAL_DESCRIPTION = 1 << 15;

    /**
     * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event: The source node's collection
     * item info changed its sort direction state for the data corresponding to this collection
     * item, which is returned by
     * {@link AccessibilityNodeInfo.CollectionItemInfo#getSortDirection()}. The view changing its
     * collection item info's sort direction should set a
     * {@link AccessibilityNodeInfo.CollectionItemInfo} created with
     * {@link AccessibilityNodeInfo.CollectionItemInfo.Builder#setSortDirection(int)} and then send
     * this event.
     *
     * @see AccessibilityNodeInfo.CollectionItemInfo#getSortDirection()
     * @see AccessibilityNodeInfo.CollectionItemInfo.Builder#setSortDirection(int)
     */
    @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
    public static final int CONTENT_CHANGE_TYPE_SORT_DIRECTION = 1 << 16;

    // Speech state change types.

    /** Change type for {@link #TYPE_SPEECH_STATE_CHANGE} event: another service is speaking. */
+174 −17
Original line number Diff line number Diff line
@@ -5129,6 +5129,9 @@ public class AccessibilityNodeInfo implements Parcelable {
            parcel.writeInt(mCollectionItemInfo.getColumnSpan());
            parcel.writeInt(mCollectionItemInfo.isHeading() ? 1 : 0);
            parcel.writeInt(mCollectionItemInfo.isSelected() ? 1 : 0);
            if (Flags.a11ySortDirectionApi()) {
                parcel.writeInt(mCollectionItemInfo.getSortDirection());
            }
        }

        if (isBitSet(nonDefaultFields, fieldIndex++)) {
@@ -5263,11 +5266,18 @@ public class AccessibilityNodeInfo implements Parcelable {
                        ci.mImportantForAccessibilityItemCount);
        CollectionItemInfo cii = other.mCollectionItemInfo;
        CollectionItemInfo.Builder builder = new CollectionItemInfo.Builder();
        mCollectionItemInfo = (cii == null)  ? null
                : builder.setRowTitle(cii.mRowTitle).setRowIndex(cii.mRowIndex).setRowSpan(
        if (cii == null) {
            mCollectionItemInfo = null;
        } else {
            builder.setRowTitle(cii.mRowTitle).setRowIndex(cii.mRowIndex).setRowSpan(
                    cii.mRowSpan).setColumnTitle(cii.mColumnTitle).setColumnIndex(
                    cii.mColumnIndex).setColumnSpan(cii.mColumnSpan).setHeading(
                                        cii.mHeading).setSelected(cii.mSelected).build();
                    cii.mHeading).setSelected(cii.mSelected);
            if (Flags.a11ySortDirectionApi()) {
                builder.setSortDirection(cii.mSortDirection);
            }
            mCollectionItemInfo = builder.build();
        }
        ExtraRenderingInfo ti = other.mExtraRenderingInfo;
        mExtraRenderingInfo = (ti == null) ? null
                : new ExtraRenderingInfo(ti);
@@ -5421,17 +5431,19 @@ public class AccessibilityNodeInfo implements Parcelable {
                        parcel.readInt())
                : null;

        mCollectionItemInfo = isBitSet(nonDefaultFields, fieldIndex++)
                ? new CollectionItemInfo(
                        parcel.readString(),
                        parcel.readInt(),
                        parcel.readInt(),
                        parcel.readString(),
                        parcel.readInt(),
                        parcel.readInt(),
                        parcel.readInt() == 1,
                        parcel.readInt() == 1)
                : null;
        if (isBitSet(nonDefaultFields, fieldIndex++)) {
            CollectionItemInfo.Builder builder = new CollectionItemInfo.Builder();
            builder.setRowTitle(parcel.readString()).setRowIndex(parcel.readInt()).setRowSpan(
                    parcel.readInt()).setColumnTitle(parcel.readString()).setColumnIndex(
                    parcel.readInt()).setColumnSpan(parcel.readInt()).setHeading(
                    parcel.readInt() == 1).setSelected(parcel.readInt() == 1);
            if (Flags.a11ySortDirectionApi()) {
                builder.setSortDirection(parcel.readInt());
            }
            mCollectionItemInfo = builder.build();
        } else {
            mCollectionItemInfo = null;
        }

        if (isBitSet(nonDefaultFields, fieldIndex++)) {
            mTouchDelegateInfo = TouchDelegateInfo.CREATOR.createFromParcel(parcel);
@@ -7434,6 +7446,55 @@ public class AccessibilityNodeInfo implements Parcelable {
     * </p>
     */
    public static final class CollectionItemInfo {
        /**
         * There is no sort direction.
         *
         * @see #getSortDirection()
         * @see Builder#setSortDirection(int)
         */
        @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
        public static final int SORT_DIRECTION_NONE = 0;

        /**
         * Items are sorted in ascending order (e.g., A-Z, 0-9).
         *
         * @see #getSortDirection()
         * @see Builder#setSortDirection(int)
         */
        @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
        public static final int SORT_DIRECTION_ASCENDING = 1;

        /**
         * Items are sorted in descending order (e.g., Z-A, 9-0).
         *
         * @see #getSortDirection()
         * @see Builder#setSortDirection(int)
         */
        @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
        public static final int SORT_DIRECTION_DESCENDING = 2;

        /**
         * Items are sorted, but using a method other than ascending
         * or descending (e.g., based on relevance or a custom algorithm).
         *
         * @see #getSortDirection()
         * @see Builder#setSortDirection(int)
         */
        @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
        public static final int SORT_DIRECTION_OTHER = 3;

        /** @hide */
        @Retention(RetentionPolicy.SOURCE)
        @IntDef(
                prefix = "SORT_DIRECTION_",
                value = {
                        SORT_DIRECTION_NONE,
                        SORT_DIRECTION_ASCENDING,
                        SORT_DIRECTION_DESCENDING,
                        SORT_DIRECTION_OTHER,
                })
        public @interface SortDirection {}

        /**
         * Instantiates a CollectionItemInfo that is a clone of another one.
         *
@@ -7449,7 +7510,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        public static CollectionItemInfo obtain(CollectionItemInfo other) {
            return new CollectionItemInfo(other.mRowTitle, other.mRowIndex, other.mRowSpan,
                other.mColumnTitle, other.mColumnIndex, other.mColumnSpan, other.mHeading,
                other.mSelected);
                other.mSelected, other.mSortDirection);
        }

        /**
@@ -7528,6 +7589,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        private int mRowIndex;
        private int mColumnSpan;
        private int mRowSpan;
        private @SortDirection int mSortDirection;
        private boolean mSelected;
        private String mRowTitle;
        private String mColumnTitle;
@@ -7592,6 +7654,28 @@ public class AccessibilityNodeInfo implements Parcelable {
            mColumnTitle = columnTitle;
        }

        /**
         * Creates a new instance.
         *
         * @param rowTitle The row title at which the item is located.
         * @param rowIndex The row index at which the item is located.
         * @param rowSpan The number of rows the item spans.
         * @param columnTitle The column title at which the item is located.
         * @param columnIndex The column index at which the item is located.
         * @param columnSpan The number of columns the item spans.
         * @param heading Whether the item is a heading.
         * @param selected Whether the item is selected.
         * @param sortDirection The sort direction applied to the data associated with this node.
         * @hide
         */
        public CollectionItemInfo(@Nullable String rowTitle, int rowIndex, int rowSpan,
                @Nullable String columnTitle, int columnIndex, int columnSpan, boolean heading,
                boolean selected, @SortDirection int sortDirection) {
            this(rowTitle, rowIndex, rowSpan, columnTitle, columnIndex, columnSpan, heading,
                    selected);
            mSortDirection = sortDirection;
        }

        /**
         * Gets the column index at which the item is located.
         *
@@ -7628,6 +7712,29 @@ public class AccessibilityNodeInfo implements Parcelable {
            return mRowSpan;
        }

        /**
         * Gets the sort direction applied to the data associated with this
         * node.
         * <p>
         * This item can only be set on a heading node within a table collection.
         * Given the heading node's collection item, a subsequent collection item uses this sort
         * direction if it has the same row or column index, and a greater index in the other
         * dimension. For example, an item at row 2, column 2 can reference a heading at row 2,
         * column 1 for its sort direction.
         *
         * @return The current sort direction, one of:
         *     <ul>
         *       <li>{@link #SORT_DIRECTION_NONE}
         *       <li>{@link #SORT_DIRECTION_ASCENDING}
         *       <li>{@link #SORT_DIRECTION_DESCENDING}
         *       <li>{@link #SORT_DIRECTION_OTHER}
         *     </ul>
         */
        @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
        public @SortDirection int getSortDirection() {
            return mSortDirection;
        }

        /**
         * Gets if the collection item is a heading. For example, section
         * heading, table header, etc.
@@ -7686,6 +7793,10 @@ public class AccessibilityNodeInfo implements Parcelable {
            mSelected = false;
            mRowTitle = null;
            mColumnTitle = null;

            if (Flags.a11ySortDirectionApi()) {
                mSortDirection = SORT_DIRECTION_NONE;
            }
        }

        /**
@@ -7697,6 +7808,7 @@ public class AccessibilityNodeInfo implements Parcelable {
            private int mRowIndex;
            private int mColumnSpan;
            private int mRowSpan;
            private int mSortDirection;
            private boolean mSelected;
            private String mRowTitle;
            private String mColumnTitle;
@@ -7767,6 +7879,32 @@ public class AccessibilityNodeInfo implements Parcelable {
                return this;
            }

            /**
             * Sets the sort direction for this item.
             * <p>
             * Valid only if {@link AccessibilityNodeInfo#isHeading()} returns {@code true}.
             * Indicates that collection content associated with this heading is presented in the
             * indicated sort direction. It should only be called by accessibility providers. For
             * accessibility services, see {@link #getSortDirection()} to query the current state.
             *
             * @param sortDirection the sort direction of this collection item info
             * @throws IllegalArgumentException If {@code sortDirection} is not one of:
             *     <ul>
             *       <li>{@link #SORT_DIRECTION_NONE}
             *       <li>{@link #SORT_DIRECTION_ASCENDING}
             *       <li>{@link #SORT_DIRECTION_DESCENDING}
             *       <li>{@link #SORT_DIRECTION_OTHER}
             *     </ul>
             * @return This builder
             */
            @FlaggedApi(Flags.FLAG_A11Y_SORT_DIRECTION_API)
            @NonNull
            public CollectionItemInfo.Builder setSortDirection(@SortDirection int sortDirection) {
                enforceValidSortDirection(sortDirection);
                mSortDirection = sortDirection;
                return this;
            }

            /**
             * Sets the collection item is selected.
             *
@@ -7818,9 +7956,28 @@ public class AccessibilityNodeInfo implements Parcelable {
                collectionItemInfo.mRowTitle = mRowTitle;
                collectionItemInfo.mColumnTitle = mColumnTitle;

                if (Flags.a11ySortDirectionApi()) {
                    collectionItemInfo.mSortDirection = mSortDirection;
                }

                return collectionItemInfo;
            }
        }

        private static void enforceValidSortDirection(int sortDirection) {
            if (Flags.a11ySortDirectionApi()) {
                switch (sortDirection) {
                    case SORT_DIRECTION_NONE:
                    case SORT_DIRECTION_ASCENDING:
                    case SORT_DIRECTION_DESCENDING:
                    case SORT_DIRECTION_OTHER:
                        return;
                    default:
                        throw new IllegalArgumentException(
                                "Unknown sort direction: " + sortDirection);
                }
            }
        }
    }

    /**