summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jacky Kao <jackykao@google.com> 2021-11-15 10:43:07 +0800
committer Jacky Kao <jackykao@google.com> 2021-11-16 11:06:10 +0800
commit4b3593c0f71e613a0687a93fd671919af0e724e6 (patch)
tree5a0e9c6264ca9a02f0664c3edc8009605b429a83
parenta14619e6af236ac5a0a77955909e7252d515caa2 (diff)
Support row and column title for the accessibility node
The accessibility service, Talkback, wants to support more information about the table on Chrome, but there’s no sources for it. We need to add more data in the Accessibility node to make Talkback can do what it wants. This patch is adding the row and column title in the inner class, CollectionItemInfo, of the AccessibilityNodeInfo class. Bug: 181789503 Test: a11y CTS & unit tests Change-Id: Id5d267836acf92b10a33a11677bd8f3ed040bfb9
-rw-r--r--core/api/current.txt4
-rw-r--r--core/java/android/view/accessibility/AccessibilityNodeInfo.java91
2 files changed, 89 insertions, 6 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index 1ba2dfa75e76..89796ea8b6a9 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -51322,14 +51322,18 @@ package android.view.accessibility {
public static final class AccessibilityNodeInfo.CollectionItemInfo {
ctor public AccessibilityNodeInfo.CollectionItemInfo(int, int, int, int, boolean);
ctor public AccessibilityNodeInfo.CollectionItemInfo(int, int, int, int, boolean, boolean);
+ ctor public AccessibilityNodeInfo.CollectionItemInfo(@Nullable String, int, int, @Nullable String, int, int, boolean, boolean);
method public int getColumnIndex();
method public int getColumnSpan();
+ method @Nullable public String getColumnTitle();
method public int getRowIndex();
method public int getRowSpan();
+ method @Nullable public String getRowTitle();
method @Deprecated public boolean isHeading();
method public boolean isSelected();
method public static android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo obtain(int, int, int, int, boolean);
method public static android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo obtain(int, int, int, int, boolean, boolean);
+ method @NonNull public static android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo obtain(@Nullable String, int, int, @Nullable String, int, int, boolean, boolean);
}
public static final class AccessibilityNodeInfo.ExtraRenderingInfo {
diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
index 4730eaa8eee9..7680aa6c61fd 100644
--- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java
+++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
@@ -3957,8 +3957,10 @@ public class AccessibilityNodeInfo implements Parcelable {
}
if (isBitSet(nonDefaultFields, fieldIndex++)) {
+ parcel.writeString(mCollectionItemInfo.getRowTitle());
parcel.writeInt(mCollectionItemInfo.getRowIndex());
parcel.writeInt(mCollectionItemInfo.getRowSpan());
+ parcel.writeString(mCollectionItemInfo.getColumnTitle());
parcel.writeInt(mCollectionItemInfo.getColumnIndex());
parcel.writeInt(mCollectionItemInfo.getColumnSpan());
parcel.writeInt(mCollectionItemInfo.isHeading() ? 1 : 0);
@@ -4100,8 +4102,9 @@ public class AccessibilityNodeInfo implements Parcelable {
ci.mHierarchical, ci.mSelectionMode);
CollectionItemInfo cii = other.mCollectionItemInfo;
mCollectionItemInfo = (cii == null) ? null
- : new CollectionItemInfo(cii.mRowIndex, cii.mRowSpan, cii.mColumnIndex,
- cii.mColumnSpan, cii.mHeading, cii.mSelected);
+ : new CollectionItemInfo(cii.mRowTitle, cii.mRowIndex, cii.mRowSpan,
+ cii.mColumnTitle, cii.mColumnIndex, cii.mColumnSpan,
+ cii.mHeading, cii.mSelected);
ExtraRenderingInfo ti = other.mExtraRenderingInfo;
mExtraRenderingInfo = (ti == null) ? null
: new ExtraRenderingInfo(ti);
@@ -4221,8 +4224,10 @@ public class AccessibilityNodeInfo implements Parcelable {
if (mCollectionItemInfo != null) mCollectionItemInfo.recycle();
mCollectionItemInfo = isBitSet(nonDefaultFields, fieldIndex++)
? CollectionItemInfo.obtain(
+ parcel.readString(),
parcel.readInt(),
parcel.readInt(),
+ parcel.readString(),
parcel.readInt(),
parcel.readInt(),
parcel.readInt() == 1,
@@ -5570,8 +5575,9 @@ public class AccessibilityNodeInfo implements Parcelable {
* @hide
*/
public static CollectionItemInfo obtain(CollectionItemInfo other) {
- return CollectionItemInfo.obtain(other.mRowIndex, other.mRowSpan, other.mColumnIndex,
- other.mColumnSpan, other.mHeading, other.mSelected);
+ return CollectionItemInfo.obtain(other.mRowTitle, other.mRowIndex, other.mRowSpan,
+ other.mColumnTitle, other.mColumnIndex, other.mColumnSpan, other.mHeading,
+ other.mSelected);
}
/**
@@ -5612,10 +5618,36 @@ public class AccessibilityNodeInfo implements Parcelable {
*/
public static CollectionItemInfo obtain(int rowIndex, int rowSpan,
int columnIndex, int columnSpan, boolean heading, boolean selected) {
+ return obtain(null, rowIndex, rowSpan, null, columnIndex,
+ columnSpan, heading, selected);
+ }
+
+ /**
+ * Obtains a pooled instance.
+ *
+ * <p>In most situations object pooling is not beneficial. Creates a new instance using the
+ * constructor {@link
+ * AccessibilityNodeInfo.CollectionItemInfo#CollectionItemInfo(int,
+ * int, int, int, boolean, boolean)} instead.
+ *
+ * @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. (Prefer
+ * {@link AccessibilityNodeInfo#setHeading(boolean)})
+ * @param selected Whether the item is selected.
+ */
+ @NonNull
+ public static CollectionItemInfo obtain(@Nullable String rowTitle, int rowIndex,
+ int rowSpan, @Nullable String columnTitle, int columnIndex, int columnSpan,
+ boolean heading, boolean selected) {
final CollectionItemInfo info = sPool.acquire();
if (info == null) {
- return new CollectionItemInfo(
- rowIndex, rowSpan, columnIndex, columnSpan, heading, selected);
+ return new CollectionItemInfo(rowTitle, rowIndex, rowSpan, columnTitle,
+ columnIndex, columnSpan, heading, selected);
}
info.mRowIndex = rowIndex;
@@ -5624,6 +5656,8 @@ public class AccessibilityNodeInfo implements Parcelable {
info.mColumnSpan = columnSpan;
info.mHeading = heading;
info.mSelected = selected;
+ info.mRowTitle = rowTitle;
+ info.mColumnTitle = columnTitle;
return info;
}
@@ -5633,6 +5667,8 @@ public class AccessibilityNodeInfo implements Parcelable {
private int mColumnSpan;
private int mRowSpan;
private boolean mSelected;
+ private String mRowTitle;
+ private String mColumnTitle;
/**
* Creates a new instance.
@@ -5660,12 +5696,33 @@ public class AccessibilityNodeInfo implements Parcelable {
*/
public CollectionItemInfo(int rowIndex, int rowSpan, int columnIndex, int columnSpan,
boolean heading, boolean selected) {
+ this(null, rowIndex, rowSpan, null, columnIndex, columnSpan,
+ heading, selected);
+ }
+
+ /**
+ * 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.
+ */
+ public CollectionItemInfo(@Nullable String rowTitle, int rowIndex, int rowSpan,
+ @Nullable String columnTitle, int columnIndex, int columnSpan, boolean heading,
+ boolean selected) {
mRowIndex = rowIndex;
mRowSpan = rowSpan;
mColumnIndex = columnIndex;
mColumnSpan = columnSpan;
mHeading = heading;
mSelected = selected;
+ mRowTitle = rowTitle;
+ mColumnTitle = columnTitle;
}
/**
@@ -5725,6 +5782,26 @@ public class AccessibilityNodeInfo implements Parcelable {
}
/**
+ * Gets the row title at which the item is located.
+ *
+ * @return The row title.
+ */
+ @Nullable
+ public String getRowTitle() {
+ return mRowTitle;
+ }
+
+ /**
+ * Gets the column title at which the item is located.
+ *
+ * @return The column title.
+ */
+ @Nullable
+ public String getColumnTitle() {
+ return mColumnTitle;
+ }
+
+ /**
* Recycles this instance.
*
* <p>In most situations object pooling is not beneficial, and recycling is not necessary.
@@ -5741,6 +5818,8 @@ public class AccessibilityNodeInfo implements Parcelable {
mRowSpan = 0;
mHeading = false;
mSelected = false;
+ mRowTitle = null;
+ mColumnTitle = null;
}
}