Add setContainerTitle API

Test: atest android.view.accessibility.cts.AccessibilityNodeInfoTest
Bug: 191984454
Change-Id: I82874c095aab641257a9735654294a06abac3e45
This commit is contained in:
Zeyin Wu
2022-10-13 23:57:24 +00:00
parent a934d86910
commit bf86a1b0ba
3 changed files with 53 additions and 2 deletions

View File

@@ -52239,6 +52239,7 @@ package android.view.accessibility {
method public CharSequence getClassName();
method public android.view.accessibility.AccessibilityNodeInfo.CollectionInfo getCollectionInfo();
method public android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo getCollectionItemInfo();
method @Nullable public CharSequence getContainerTitle();
method public CharSequence getContentDescription();
method public int getDrawingOrder();
method public CharSequence getError();
@@ -52315,6 +52316,7 @@ package android.view.accessibility {
method public void setClickable(boolean);
method public void setCollectionInfo(android.view.accessibility.AccessibilityNodeInfo.CollectionInfo);
method public void setCollectionItemInfo(android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo);
method public void setContainerTitle(@Nullable CharSequence);
method public void setContentDescription(CharSequence);
method public void setContentInvalid(boolean);
method public void setContextClickable(boolean);

View File

@@ -897,6 +897,7 @@ public class AccessibilityNodeInfo implements Parcelable {
private CharSequence mTooltipText;
private String mViewIdResourceName;
private String mUniqueId;
private CharSequence mContainerTitle;
private ArrayList<String> mExtraDataKeys;
@UnsupportedAppUsage
@@ -3630,6 +3631,47 @@ public class AccessibilityNodeInfo implements Parcelable {
return mUniqueId;
}
/**
* Sets the container title for app-developer-defined container which can be any type of
* ViewGroup or layout.
* Container title will be used to group together related controls, similar to HTML fieldset.
* Or container title may identify a large piece of the UI that is visibly grouped together,
* such as a toolbar or a card, etc.
* <p>
* Container title helps to assist in navigation across containers and other groups.
* For example, a screen reader may use this to determine where to put accessibility focus.
* </p>
* <p>
* Container title is different from pane title{@link #setPaneTitle} which indicates that the
* node represents a window or activity.
* </p>
*
* <p>
* Example: An app can set container titles on several non-modal menus, containing TextViews
* or ImageButtons that have content descriptions, text, etc. Screen readers can quickly
* switch accessibility focus among menus instead of child views. Other accessibility-services
* can easily find the menu.
* </p>
*
* @param containerTitle The container title that is associated with a ViewGroup/Layout on the
* screen.
*/
public void setContainerTitle(@Nullable CharSequence containerTitle) {
enforceNotSealed();
mContainerTitle = (containerTitle == null) ? null
: containerTitle.subSequence(0, containerTitle.length());
}
/**
* Returns the container title.
*
* @see #setContainerTitle for details.
*/
@Nullable
public CharSequence getContainerTitle() {
return mContainerTitle;
}
/**
* Sets the token and node id of the leashed parent.
*
@@ -3963,6 +4005,10 @@ public class AccessibilityNodeInfo implements Parcelable {
nonDefaultFields |= bitAt(fieldIndex);
}
fieldIndex++;
if (!Objects.equals(mContainerTitle, DEFAULT.mContainerTitle)) {
nonDefaultFields |= bitAt(fieldIndex);
}
fieldIndex++;
if (!Objects.equals(mViewIdResourceName, DEFAULT.mViewIdResourceName)) {
nonDefaultFields |= bitAt(fieldIndex);
}
@@ -4108,10 +4154,10 @@ public class AccessibilityNodeInfo implements Parcelable {
}
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mPaneTitle);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mTooltipText);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mContainerTitle);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeString(mViewIdResourceName);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeString(mUniqueId);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeInt(mTextSelectionStart);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeInt(mTextSelectionEnd);
if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeInt(mInputType);
@@ -4204,6 +4250,7 @@ public class AccessibilityNodeInfo implements Parcelable {
mContentDescription = other.mContentDescription;
mPaneTitle = other.mPaneTitle;
mTooltipText = other.mTooltipText;
mContainerTitle = other.mContainerTitle;
mViewIdResourceName = other.mViewIdResourceName;
if (mActions != null) mActions.clear();
@@ -4347,6 +4394,7 @@ public class AccessibilityNodeInfo implements Parcelable {
}
if (isBitSet(nonDefaultFields, fieldIndex++)) mPaneTitle = parcel.readCharSequence();
if (isBitSet(nonDefaultFields, fieldIndex++)) mTooltipText = parcel.readCharSequence();
if (isBitSet(nonDefaultFields, fieldIndex++)) mContainerTitle = parcel.readCharSequence();
if (isBitSet(nonDefaultFields, fieldIndex++)) mViewIdResourceName = parcel.readString();
if (isBitSet(nonDefaultFields, fieldIndex++)) mUniqueId = parcel.readString();
@@ -4675,6 +4723,7 @@ public class AccessibilityNodeInfo implements Parcelable {
builder.append("; stateDescription: ").append(mStateDescription);
builder.append("; contentDescription: ").append(mContentDescription);
builder.append("; tooltipText: ").append(mTooltipText);
builder.append("; containerTitle: ").append(mContainerTitle);
builder.append("; viewIdResName: ").append(mViewIdResourceName);
builder.append("; uniqueId: ").append(mUniqueId);

View File

@@ -46,7 +46,7 @@ public class AccessibilityNodeInfoTest {
// The number of fields tested in the corresponding CTS AccessibilityNodeInfoTest:
// See fullyPopulateAccessibilityNodeInfo, assertEqualsAccessibilityNodeInfo,
// and assertAccessibilityNodeInfoCleared in that class.
private static final int NUM_MARSHALLED_PROPERTIES = 40;
private static final int NUM_MARSHALLED_PROPERTIES = 41;
/**
* The number of properties that are purposely not marshalled