mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-17 09:38:19 +00:00
Setup SearchResultIcon for single cell results
SearchResultIcon will be able to render apps, shortcuts and remote actions. It can also handle its own focused state drawing. Screenshot: https://screenshot.googleplex.com/C3KgjJtLQTBPgaf Bug: 170752716 Test: Manual Change-Id: I460a9c128ea3f5814784e342c5d5fa5b7e310882
This commit is contained in:
@@ -43,15 +43,12 @@ import com.android.launcher3.BaseDraggingActivity;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.search.AllAppsSearchBarController.SearchTargetHandler;
|
||||
import com.android.launcher3.allapps.search.SearchEventTracker;
|
||||
import com.android.launcher3.allapps.search.SearchSectionInfo;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.views.HeroSearchResultView;
|
||||
import com.android.launcher3.views.SearchSliceWrapper;
|
||||
import com.android.systemui.plugins.shared.SearchTarget;
|
||||
import com.android.systemui.plugins.shared.SearchTargetEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -94,9 +91,11 @@ public class AllAppsGridAdapter extends
|
||||
|
||||
public static final int VIEW_TYPE_SEARCH_SUGGEST = 1 << 13;
|
||||
|
||||
public static final int VIEW_TYPE_SEARCH_ICON = 1 << 14;
|
||||
|
||||
// Common view type masks
|
||||
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
||||
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
|
||||
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON | VIEW_TYPE_SEARCH_ICON;
|
||||
|
||||
/**
|
||||
* ViewHolder for each icon.
|
||||
@@ -186,6 +185,7 @@ public class AllAppsGridAdapter extends
|
||||
|| viewType == VIEW_TYPE_SEARCH_PEOPLE
|
||||
|| viewType == VIEW_TYPE_SEARCH_THUMBNAIL
|
||||
|| viewType == VIEW_TYPE_SEARCH_ICON_ROW
|
||||
|| viewType == VIEW_TYPE_SEARCH_ICON
|
||||
|| viewType == VIEW_TYPE_SEARCH_SUGGEST;
|
||||
}
|
||||
}
|
||||
@@ -399,11 +399,8 @@ public class AllAppsGridAdapter extends
|
||||
R.layout.all_apps_icon, parent, false);
|
||||
icon.setLongPressTimeoutFactor(1f);
|
||||
icon.setOnFocusChangeListener(mIconFocusListener);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
}
|
||||
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
// Ensure the all apps icon height matches the workspace icons in portrait mode.
|
||||
icon.getLayoutParams().height = mLauncher.getDeviceProfile().allAppsCellHeightPx;
|
||||
return new ViewHolder(icon);
|
||||
@@ -419,6 +416,9 @@ public class AllAppsGridAdapter extends
|
||||
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.all_apps_divider, parent, false));
|
||||
case VIEW_TYPE_SEARCH_ICON:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.search_result_icon, parent, false));
|
||||
case VIEW_TYPE_SEARCH_CORPUS_TITLE:
|
||||
return new ViewHolder(
|
||||
mLayoutInflater.inflate(R.layout.search_section_title, parent, false));
|
||||
@@ -453,6 +453,10 @@ public class AllAppsGridAdapter extends
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
if (FeatureFlags.ENABLE_DEVICE_SEARCH.get()
|
||||
&& holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
|
||||
((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
|
||||
}
|
||||
switch (holder.getItemViewType()) {
|
||||
case VIEW_TYPE_ICON:
|
||||
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
|
||||
@@ -460,43 +464,6 @@ public class AllAppsGridAdapter extends
|
||||
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
||||
icon.reset();
|
||||
icon.applyFromApplicationInfo(info);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
break;
|
||||
}
|
||||
//TODO: replace with custom TopHitBubbleTextView with support for both shortcut
|
||||
// and apps
|
||||
if (adapterItem instanceof SearchAdapterItem) {
|
||||
SearchAdapterItem item = (SearchAdapterItem) adapterItem;
|
||||
SearchTargetHandler searchTargetHandler = new SearchTargetHandler() {
|
||||
@Override
|
||||
public void applySearchTarget(SearchTarget searchTarget) {
|
||||
// Does nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelection(int type) {
|
||||
SearchTargetEvent e = new SearchTargetEvent(SearchTarget.ItemType.APP,
|
||||
type, item.position, item.getSearchSessionId());
|
||||
e.bundle = HeroSearchResultView.getAppBundle(info);
|
||||
SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(e);
|
||||
}
|
||||
};
|
||||
SearchEventTracker.INSTANCE.get(mLauncher).registerWeakHandler(
|
||||
((SearchAdapterItem) adapterItem).getSearchTarget(),
|
||||
searchTargetHandler);
|
||||
|
||||
icon.setOnClickListener(view -> {
|
||||
searchTargetHandler.handleSelection(SearchTargetEvent.SELECT);
|
||||
mOnIconClickListener.onClick(view);
|
||||
});
|
||||
icon.setOnLongClickListener(view -> {
|
||||
searchTargetHandler.handleSelection(SearchTargetEvent.LONG_PRESS);
|
||||
return mOnIconLongClickListener.onLongClick(view);
|
||||
});
|
||||
} else {
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
}
|
||||
break;
|
||||
case VIEW_TYPE_EMPTY_SEARCH:
|
||||
TextView emptyViewText = (TextView) holder.itemView;
|
||||
@@ -525,6 +492,7 @@ public class AllAppsGridAdapter extends
|
||||
case VIEW_TYPE_SEARCH_ROW_WITH_BUTTON:
|
||||
case VIEW_TYPE_SEARCH_HERO_APP:
|
||||
case VIEW_TYPE_SEARCH_ROW:
|
||||
case VIEW_TYPE_SEARCH_ICON:
|
||||
case VIEW_TYPE_SEARCH_ICON_ROW:
|
||||
case VIEW_TYPE_SEARCH_PEOPLE:
|
||||
case VIEW_TYPE_SEARCH_THUMBNAIL:
|
||||
@@ -544,11 +512,10 @@ public class AllAppsGridAdapter extends
|
||||
public void onViewRecycled(@NonNull ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) return;
|
||||
if (holder.itemView instanceof BubbleTextView) {
|
||||
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
||||
icon.setOnClickListener(null);
|
||||
icon.setOnLongClickListener(null);
|
||||
} else if (holder.itemView instanceof SliceView) {
|
||||
if (holder.itemView instanceof AllAppsSectionDecorator.SelfDecoratingView) {
|
||||
((AllAppsSectionDecorator.SelfDecoratingView) holder.itemView).removeDecoration();
|
||||
}
|
||||
if (holder.itemView instanceof SliceView) {
|
||||
SliceView sliceView = (SliceView) holder.itemView;
|
||||
if (sliceView.getTag() instanceof SearchSliceWrapper) {
|
||||
((SearchSliceWrapper) sliceView.getTag()).destroy();
|
||||
|
||||
Reference in New Issue
Block a user