From bbd54b3e32b40410503708ae0b4a336b2d316981 Mon Sep 17 00:00:00 2001 From: helencheuk Date: Wed, 24 Jan 2024 11:42:46 +0000 Subject: [PATCH] Draw focus outline in search app result Before: https://screenshot.googleplex.com/9qoPoBNZkDY94gy https://screenshot.googleplex.com/7XVFxwj8d6UqLUs https://screenshot.googleplex.com/4KtQcma26eSdBnb After: https://screenshot.googleplex.com/BxfNAJGqXhyGBbJ https://screenshot.googleplex.com/8EMKUQW4ubXHdDd https://screenshot.googleplex.com/32KBfdj4preL8H6 Bug: 319454774 Test: Manual, open all apps, type some word and press enter to search. Navigate to the search result below and outline should appear Test: will add screenshot test in b/318360469 Flag: ACONFIG com.android.launcher3.enable_focus_outline Development Change-Id: I8caef8dd9e590d43e05baa78cebee73d21b84acf --- .../allapps/ActivityAllAppsContainerView.java | 7 ++++++- .../launcher3/keyboard/FocusedItemDecorator.java | 11 ++++++++--- .../launcher3/keyboard/ViewGroupFocusHelper.java | 10 +++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index ae2849e49d..6acfcd0f11 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -80,6 +80,7 @@ import com.android.launcher3.allapps.search.AllAppsSearchUiDelegate; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.keyboard.FocusedItemDecorator; +import com.android.launcher3.keyboard.ViewGroupFocusHelper; import com.android.launcher3.model.StringCache; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.pm.UserCache; @@ -1535,7 +1536,11 @@ public class ActivityAllAppsContainerView // No animations will occur when changes occur to the items in this RecyclerView. mRecyclerView.setItemAnimator(null); onInitializeRecyclerView(mRecyclerView); - FocusedItemDecorator focusedItemDecorator = new FocusedItemDecorator(mRecyclerView); + // Use ViewGroupFocusHelper for SearchRecyclerView to draw focus outline for the + // buttons in the view (e.g. query builder button and setting button) + FocusedItemDecorator focusedItemDecorator = isSearch() ? new FocusedItemDecorator( + new ViewGroupFocusHelper(mRecyclerView)) : new FocusedItemDecorator( + mRecyclerView); mRecyclerView.addItemDecoration(focusedItemDecorator); mOnFocusChangeListener = focusedItemDecorator.getFocusListener(); mAdapter.setIconFocusListener(mOnFocusChangeListener); diff --git a/src/com/android/launcher3/keyboard/FocusedItemDecorator.java b/src/com/android/launcher3/keyboard/FocusedItemDecorator.java index 2476a6fd3e..5e2832ffc6 100644 --- a/src/com/android/launcher3/keyboard/FocusedItemDecorator.java +++ b/src/com/android/launcher3/keyboard/FocusedItemDecorator.java @@ -20,12 +20,12 @@ import android.graphics.Canvas; import android.view.View; import android.view.View.OnFocusChangeListener; -import com.android.launcher3.keyboard.FocusIndicatorHelper.SimpleFocusIndicatorHelper; - import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.ItemDecoration; import androidx.recyclerview.widget.RecyclerView.State; +import com.android.launcher3.keyboard.FocusIndicatorHelper.SimpleFocusIndicatorHelper; + /** * {@link ItemDecoration} for drawing and animating focused view background. */ @@ -37,12 +37,17 @@ public class FocusedItemDecorator extends ItemDecoration { mHelper = new SimpleFocusIndicatorHelper(container); } + public FocusedItemDecorator(FocusIndicatorHelper focusIndicatorHelper) { + mHelper = focusIndicatorHelper; + } + public OnFocusChangeListener getFocusListener() { return mHelper; } @Override - public void onDraw(Canvas c, RecyclerView parent, State state) { + public void onDrawOver(Canvas c, RecyclerView parent, State state) { + // Use onDrawOver so focus outline is always visible mHelper.draw(c); } } diff --git a/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java b/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java index fde220cbf6..f9bd3437a5 100644 --- a/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java +++ b/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java @@ -50,10 +50,18 @@ public class ViewGroupFocusHelper extends FocusIndicatorHelper { } private void computeLocationRelativeToContainer(View child, Rect outRect) { - View parent = (View) child.getParent(); + if (child == null) { + return; + } + outRect.left += child.getX(); outRect.top += child.getY(); + if (child.getParent() == null || !(child.getParent() instanceof View)) { + return; + } + + View parent = (View) child.getParent(); if (parent != mContainer) { if (parent instanceof PagedView) { PagedView page = (PagedView) parent;