From 147527229b0c7100f8ce2015c7855a4088417fef Mon Sep 17 00:00:00 2001 From: Samuel Fufa Date: Fri, 19 Mar 2021 09:52:37 -0500 Subject: [PATCH] [Search] Tie quick-launch and focus highlight Highlight and quick-launch item should be determined by Search service pipeline based on quick_launch flag on SearchTarget Bug: 183083807 Bug: 183083682 Test: Manual Change-Id: I0191474653deca7e1ecd01fa92c90efcdbb9a8dc --- .../allapps/AllAppsContainerView.java | 36 ++----------------- .../allapps/AllAppsSectionDecorator.java | 6 ++-- .../search/AllAppsSearchBarController.java | 29 ++++----------- .../search/DefaultSearchAdapterProvider.java | 26 +++++++++----- .../allapps/search/SearchAdapterProvider.java | 13 +++++-- .../allapps/search/SectionDecorationInfo.java | 11 ------ 6 files changed, 41 insertions(+), 80 deletions(-) diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 78c404f061..591de043d2 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -15,7 +15,6 @@ */ package com.android.launcher3.allapps; -import static com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION; @@ -63,7 +62,6 @@ import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.keyboard.FocusedItemDecorator; import com.android.launcher3.model.data.AppInfo; -import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.MultiValueAlpha; @@ -564,37 +562,9 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo /** * Handles selection on focused view and returns success */ - public boolean selectFocusedView(View v) { - ItemInfo headerItem = getHighlightedItemFromHeader(); - if (headerItem != null) { - return mLauncher.startActivitySafely(v, headerItem.getIntent(), headerItem); - } - AdapterItem focusedItem = getActiveRecyclerView().getApps().getFocusedChild(); - if (focusedItem != null) { - View focusedView = getActiveRecyclerView().getLayoutManager() - .findViewByPosition(focusedItem.position); - if (focusedView != null && mSearchAdapterProvider.onAdapterItemSelected(focusedItem, - focusedView)) { - return true; - } - } - if (focusedItem != null && focusedItem.appInfo != null) { - ItemInfo itemInfo = focusedItem.appInfo; - return mLauncher.startActivitySafely(v, itemInfo.getIntent(), itemInfo); - } - return false; - } - - /** - * Returns the ItemInfo of a focused view inside {@link FloatingHeaderView} - */ - public ItemInfo getHighlightedItemFromHeader() { - View view = getFloatingHeaderView().getFocusedChild(); - if (view != null && view.getTag() instanceof ItemInfo) { - return ((ItemInfo) view.getTag()); - } - - return null; + public boolean launchHighlightedItem() { + if (mSearchAdapterProvider == null) return false; + return mSearchAdapterProvider.launchHighlightedItem(); } public SearchAdapterProvider getSearchAdapterProvider() { diff --git a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java index 269e3905c8..7fcd6ec16f 100644 --- a/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java +++ b/src/com/android/launcher3/allapps/AllAppsSectionDecorator.java @@ -29,6 +29,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.R; import com.android.launcher3.allapps.AllAppsGridAdapter.AppsGridLayoutManager; +import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.allapps.search.SectionDecorationInfo; import com.android.launcher3.util.Themes; @@ -48,6 +49,7 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration { @Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { List adapterItems = mAppsView.getApps().getAdapterItems(); + SearchAdapterProvider adapterProvider = mAppsView.getSearchAdapterProvider(); for (int i = 0; i < parent.getChildCount(); i++) { View view = parent.getChildAt(i); int position = parent.getChildAdapterPosition(view); @@ -56,7 +58,7 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration { SectionDecorationInfo sectionInfo = adapterItem.sectionDecorationInfo; SectionDecorationHandler decorationHandler = sectionInfo.getDecorationHandler(); if (decorationHandler != null) { - if (sectionInfo.isFocusedView()) { + if (view.equals(adapterProvider.getHighlightedItem())) { decorationHandler.onFocusDraw(c, view); } else { decorationHandler.onGroupDraw(c, view); @@ -102,7 +104,7 @@ public class AllAppsSectionDecorator extends RecyclerView.ItemDecoration { private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private final boolean mIsTopRound; private final boolean mIsBottomRound; - private float [] mCorners; + private float[] mCorners; private float mFillSpacing; public SectionDecorationHandler(Context context, boolean isFullWidth, int fillAlpha, diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index d3c9993579..79718fb6df 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -35,7 +35,6 @@ import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.search.SearchAlgorithm; import com.android.launcher3.search.SearchCallback; -import com.android.launcher3.util.PackageManagerHelper; /** * An interface to a search box that AllApps can command. @@ -105,30 +104,14 @@ public class AllAppsSearchBarController @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()) { - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO) { - mLauncher.getStatsLogManager().logger() - .log(LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME); - // selectFocusedView should return SearchTargetEvent that is passed onto onClick - if (Launcher.getLauncher(mLauncher).getAppsView().selectFocusedView(v)) { - return true; - } - } - } - // Skip if it's not the right action - if (actionId != EditorInfo.IME_ACTION_SEARCH) { - return false; + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO) { + mLauncher.getStatsLogManager().logger() + .log(LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME); + // selectFocusedView should return SearchTargetEvent that is passed onto onClick + return Launcher.getLauncher(mLauncher).getAppsView().launchHighlightedItem(); } - - // Skip if the query is empty - String query = v.getText().toString(); - if (query.isEmpty()) { - return false; - } - return mLauncher.startActivitySafely(v, - PackageManagerHelper.getMarketSearchIntent(mLauncher, query), null - ); + return false; } @Override diff --git a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java index e268f567ae..ba895ed5d4 100644 --- a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java +++ b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java @@ -15,31 +15,31 @@ */ package com.android.launcher3.allapps.search; -import android.net.Uri; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.BubbleTextView; import com.android.launcher3.allapps.AllAppsGridAdapter; +import com.android.launcher3.model.data.ItemInfo; /** * Provides views for local search results */ public class DefaultSearchAdapterProvider extends SearchAdapterProvider { + private View mHighlightedView; + public DefaultSearchAdapterProvider(BaseDraggingActivity launcher) { super(launcher); } @Override public void onBindView(AllAppsGridAdapter.ViewHolder holder, int position) { - - } - - @Override - public void onSliceStatusUpdate(Uri sliceUri) { - + if (position == 0) { + mHighlightedView = holder.itemView; + } } @Override @@ -54,7 +54,17 @@ public class DefaultSearchAdapterProvider extends SearchAdapterProvider { } @Override - public boolean onAdapterItemSelected(AllAppsGridAdapter.AdapterItem adapterItem, View view) { + public boolean launchHighlightedItem() { + if (mHighlightedView instanceof BubbleTextView + && mHighlightedView.getTag() instanceof ItemInfo) { + ItemInfo itemInfo = (ItemInfo) mHighlightedView.getTag(); + return mLauncher.startActivitySafely(mHighlightedView, itemInfo.getIntent(), itemInfo); + } return false; } + + @Override + public View getHighlightedItem() { + return mHighlightedView; + } } diff --git a/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java b/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java index 0864090ade..a650a7d947 100644 --- a/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java +++ b/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java @@ -43,7 +43,8 @@ public abstract class SearchAdapterProvider { /** * Called from LiveSearchManager to notify slice status updates. */ - public abstract void onSliceStatusUpdate(Uri sliceUri); + public void onSliceStatusUpdate(Uri sliceUri) { + } /** * Returns whether or not viewType can be handled by searchProvider @@ -74,6 +75,12 @@ public abstract class SearchAdapterProvider { * handles selection event on search adapter item. Returns false if provider can not handle * event */ - public abstract boolean onAdapterItemSelected(AllAppsGridAdapter.AdapterItem adapterItem, - View view); + public abstract boolean launchHighlightedItem(); + + /** + * Returns the current highlighted view + */ + public abstract View getHighlightedItem(); + + } diff --git a/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java b/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java index 0b64fcaece..56dd63ccc1 100644 --- a/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java +++ b/src/com/android/launcher3/allapps/search/SectionDecorationInfo.java @@ -21,22 +21,11 @@ import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHa * Info class for a search section that is primarily used for decoration. */ public class SectionDecorationInfo { - - public static final int QUICK_LAUNCH = 1 << 0; public static final int GROUPING = 1 << 1; private String mSectionId; - private boolean mFocused; private SectionDecorationHandler mDecorationHandler; - public boolean isFocusedView() { - return mFocused; - } - - public void setFocusedView(boolean focused) { - mFocused = focused; - } - public SectionDecorationInfo() { this(null); }