Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 865dc9b3 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

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
parent 8b748381
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.launcher3.settings;
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.SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY;
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
@@ -29,6 +31,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;


import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentActivity;
@@ -248,6 +251,8 @@ public class SettingsActivity extends FragmentActivity
                if (highlighter != null) {
                if (highlighter != null) {
                    getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
                    getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
                    mPreferenceHighlighted = true;
                    mPreferenceHighlighted = true;
                } else {
                    requestAccessibilityFocus(getListView());
                }
                }
            }
            }
        }
        }
@@ -268,6 +273,15 @@ public class SettingsActivity extends FragmentActivity
            return position >= 0 ? new PreferenceHighlighter(list, position) : null;
            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
        @Override
        public void onDestroy() {
        public void onDestroy() {
            if (mNotificationDotsObserver != null) {
            if (mNotificationDotsObserver != null) {