Set a11y focus for selected Settings item

When a Settings preference item is selected via a settings panel or
settings search, the system takes user to its corresponding subsettings
activity. There, in the past, the selected preference was highlighted
but the a11y focus was set on the back button. This code sets the a11y
focus on the selected preference.

Bug: b/285512439
Test: atest HighlightablePreferenceGroupAdapterTest
Change-Id: I7edc697e2e3870b1822279c115230add14e82df0
This commit is contained in:
Behnam Heydarshahi
2023-09-15 19:18:43 +00:00
parent 71235aa403
commit 7549d613e6
2 changed files with 17 additions and 0 deletions

View File

@@ -122,6 +122,9 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
&& TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
// This position should be highlighted. If it's highlighted before - skip animation.
addHighlightBackground(holder, !mFadeInAnimated);
if (v != null) {
v.requestAccessibilityFocus();
}
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
// View with highlight is reused for a view that should not have highlight
removeHighlightBackground(holder, false /* animate */);