perform accessbility focus when the recyclerview doesn't gain focus
after fragment replacement in SettingsActivity
Bug: 145475911
Test: Settings -> App & Notifications -> Default Apps -> Enable Talkback
-> Gear Button next to Home app -> About -> Verify Talkback reads the
first item in the page
Change-Id: I100e646ad2aba0081b48b86ec408ce8e76a80713
Merged-In: I100e646ad2aba0081b48b86ec408ce8e76a80713
(cherry picked from commit 865dc9b3b17084c73cf07868b115cc7710b7dfc1)
diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java
index 18b6094..8d2db78 100644
--- a/src/com/android/launcher3/settings/SettingsActivity.java
+++ b/src/com/android/launcher3/settings/SettingsActivity.java
@@ -16,6 +16,8 @@
package com.android.launcher3.settings;
+import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
+
import static com.android.launcher3.SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY;
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
@@ -32,14 +34,7 @@
import android.provider.Settings;
import android.text.TextUtils;
-import com.android.launcher3.LauncherFiles;
-import com.android.launcher3.R;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.config.FeatureFlags;
-import com.android.launcher3.graphics.GridOptionsProvider;
-import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
-import com.android.launcher3.util.SecureSettingsObserver;
-
+import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceFragment.OnPreferenceStartFragmentCallback;
@@ -48,6 +43,14 @@
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
+import com.android.launcher3.LauncherFiles;
+import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
+import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.graphics.GridOptionsProvider;
+import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
+import com.android.launcher3.util.SecureSettingsObserver;
+
/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
*/
@@ -248,6 +251,8 @@
if (highlighter != null) {
getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
mPreferenceHighlighted = true;
+ } else {
+ requestAccessibilityFocus(getListView());
}
}
}
@@ -268,6 +273,15 @@
return position >= 0 ? new PreferenceHighlighter(list, position) : null;
}
+ private void requestAccessibilityFocus(@NonNull final RecyclerView rv) {
+ rv.post(() -> {
+ if (!rv.hasFocus() && rv.getChildCount() > 0) {
+ rv.getChildAt(0)
+ .performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null);
+ }
+ });
+ }
+
@Override
public void onDestroy() {
if (mNotificationDotsObserver != null) {