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
diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
index ae2849e..6acfcd0 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.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 @@
// 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 2476a6f..5e2832f 100644
--- a/src/com/android/launcher3/keyboard/FocusedItemDecorator.java
+++ b/src/com/android/launcher3/keyboard/FocusedItemDecorator.java
@@ -20,12 +20,12 @@
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 @@
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 fde220c..f9bd343 100644
--- a/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java
+++ b/src/com/android/launcher3/keyboard/ViewGroupFocusHelper.java
@@ -50,10 +50,18 @@
}
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;