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

Commit bbd54b3e authored by helencheuk's avatar helencheuk
Browse files

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
parent c5be03f0
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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<T extends Context & ActivityContext>
            // 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);
+8 −3
Original line number Diff line number Diff line
@@ -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);
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -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;