Merge "[Search] Tie quick-launch and focus highlight" into sc-dev

This commit is contained in:
Samuel Fufa
2021-03-21 20:33:25 +00:00
committed by Android (Google) Code Review
6 changed files with 41 additions and 80 deletions
@@ -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() {
@@ -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<AllAppsGridAdapter.AdapterItem> 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,
@@ -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
@@ -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;
}
}
@@ -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();
}
@@ -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);
}