From 5a5c74f350f98c9083572b7006f85973a86cf62c Mon Sep 17 00:00:00 2001 From: sallyyuen Date: Fri, 3 Apr 2020 14:11:21 -0700 Subject: [PATCH] Check for text when adding CollectionInfo and CollectionItemInfo Generally, the button's text is displayed next to the check box, but Sound Settings uses its own views to display the text, distinct from RadioGroup and RadioButton. This results in TalkBack announcing out of list state too early, since the text content is not considered part of the collection. Add a check to exclude buttons with no text when counting the children to be in the collection. Developers should be either setting the button text or implementing their own views to appear alongside the buttons. Bug: 149064784 Test: Added CTS test. Manual testing of Settings -> Sound -> Do no disturb -> Advanced -> Set Duration for Quick Settings Change-Id: Ie9abe4cccc4ab53e79a583b9a2ce45535dcf1cc0 --- core/java/android/widget/RadioGroup.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java index 71ccb595278b5..849488d42bcfa 100644 --- a/core/java/android/widget/RadioGroup.java +++ b/core/java/android/widget/RadioGroup.java @@ -22,6 +22,7 @@ import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.TypedArray; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.View; @@ -484,21 +485,21 @@ public class RadioGroup extends LinearLayout { super.onInitializeAccessibilityNodeInfo(info); if (this.getOrientation() == HORIZONTAL) { info.setCollectionInfo(AccessibilityNodeInfo.CollectionInfo.obtain(1, - getVisibleChildCount(), false, + getVisibleChildWithTextCount(), false, AccessibilityNodeInfo.CollectionInfo.SELECTION_MODE_SINGLE)); } else { info.setCollectionInfo( - AccessibilityNodeInfo.CollectionInfo.obtain(getVisibleChildCount(), + AccessibilityNodeInfo.CollectionInfo.obtain(getVisibleChildWithTextCount(), 1, false, AccessibilityNodeInfo.CollectionInfo.SELECTION_MODE_SINGLE)); } } - private int getVisibleChildCount() { + private int getVisibleChildWithTextCount() { int count = 0; for (int i = 0; i < getChildCount(); i++) { if (this.getChildAt(i) instanceof RadioButton) { - if (((RadioButton) this.getChildAt(i)).getVisibility() == VISIBLE) { + if (isVisibleWithText((RadioButton) this.getChildAt(i))) { count++; } } @@ -513,15 +514,19 @@ public class RadioGroup extends LinearLayout { int index = 0; for (int i = 0; i < getChildCount(); i++) { if (this.getChildAt(i) instanceof RadioButton) { - RadioButton radioButton = (RadioButton) this.getChildAt(i); - if (radioButton == child) { + RadioButton button = (RadioButton) this.getChildAt(i); + if (button == child) { return index; } - if (radioButton.getVisibility() == VISIBLE) { + if (isVisibleWithText(button)) { index++; } } } return -1; } + + private boolean isVisibleWithText(RadioButton button) { + return button.getVisibility() == VISIBLE && !TextUtils.isEmpty(button.getText()); + } } \ No newline at end of file