From f9efc544936d4d47bbaa91a6fad2f126bd0e20e0 Mon Sep 17 00:00:00 2001 From: Liam Lee Pong Lam Date: Mon, 9 Sep 2024 22:02:39 +0000 Subject: [PATCH] Improve the visibility of allapps item on talkback focus result: https://photos.app.goo.gl/TqTDboxa2WFfZUoz8 Flag: com.android.launcher3.accessibility_scroll_on_allapps Bug: 265392261 Test: Manual Change-Id: If1cce3d0bd501361837dafb24cbe2fde7bac0ac0 --- aconfig/launcher.aconfig | 10 ++++ .../QuickstepAccessibilityDelegate.java | 56 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index 0da2df1965..37691247b8 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -388,3 +388,13 @@ flag { description: "Refactor grid migration such that the code is simpler to understand and update" bug: "358399271" } + +flag { + name: "accessibility_scroll_on_allapps" + namespace: "launcher" + description: "Scroll to item position if accessibility focused" + bug: "265392261" + metadata { + purpose: PURPOSE_BUGFIX + } +} diff --git a/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java b/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java index 962fd91c2e..1161720e3b 100644 --- a/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java +++ b/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java @@ -15,10 +15,19 @@ */ package com.android.launcher3; +import static androidx.recyclerview.widget.RecyclerView.NO_POSITION; + import android.view.KeyEvent; import android.view.View; +import android.view.accessibility.AccessibilityEvent; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.LinearSmoothScroller; +import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; +import com.android.launcher3.allapps.AllAppsRecyclerView; +import com.android.launcher3.allapps.SearchRecyclerView; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.uioverrides.PredictedAppIcon; import com.android.launcher3.uioverrides.QuickstepLauncher; @@ -26,13 +35,60 @@ import com.android.launcher3.uioverrides.QuickstepLauncher; import java.util.List; public class QuickstepAccessibilityDelegate extends LauncherAccessibilityDelegate { + private QuickstepLauncher mLauncher; public QuickstepAccessibilityDelegate(QuickstepLauncher launcher) { super(launcher); + mLauncher = launcher; mActions.put(PIN_PREDICTION, new LauncherAction( PIN_PREDICTION, R.string.pin_prediction, KeyEvent.KEYCODE_P)); } + @Override + public void onPopulateAccessibilityEvent(View view, AccessibilityEvent event) { + super.onPopulateAccessibilityEvent(view, event); + // Scroll to the position if focused view in main allapps list and not completely visible. + scrollToPositionIfNeeded(view); + } + + private void scrollToPositionIfNeeded(View view) { + if (!Flags.accessibilityScrollOnAllapps()) { + return; + } + AllAppsRecyclerView contentView = mLauncher.getAppsView().getActiveRecyclerView(); + if (contentView instanceof SearchRecyclerView) { + return; + } + LinearLayoutManager layoutManager = (LinearLayoutManager) contentView.getLayoutManager(); + if (layoutManager == null) { + return; + } + RecyclerView.ViewHolder vh = contentView.findContainingViewHolder(view); + if (vh == null) { + return; + } + int itemPosition = vh.getBindingAdapterPosition(); + if (itemPosition == NO_POSITION) { + return; + } + int firstCompletelyVisible = layoutManager.findFirstCompletelyVisibleItemPosition(); + int lastCompletelyVisible = layoutManager.findLastCompletelyVisibleItemPosition(); + boolean itemCompletelyVisible = firstCompletelyVisible <= itemPosition + && lastCompletelyVisible >= itemPosition; + if (itemCompletelyVisible) { + return; + } + RecyclerView.SmoothScroller smoothScroller = + new LinearSmoothScroller(mLauncher.asContext()) { + @Override + protected int getVerticalSnapPreference() { + return LinearSmoothScroller.SNAP_TO_ANY; + } + }; + smoothScroller.setTargetPosition(itemPosition); + layoutManager.startSmoothScroll(smoothScroller); + } + @Override protected void getSupportedActions(View host, ItemInfo item, List out) { if (host instanceof PredictedAppIcon && !((PredictedAppIcon) host).isPinned()) {