mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Consolidate Hero search result with SearchResultIconRow
With this, we can now show app title and support drag/drop for shortcut results. Bug: 172245107 preview: https://drive.google.com/file/d/1A4eKKTDPht-MDbfA2VFI3OuAO36fc3AS/view?usp=sharing Change-Id: Icf94a2d23b44bfe5527aea71e27178906e5deb3e
This commit is contained in:
@@ -15,16 +15,35 @@
|
||||
*/
|
||||
package com.android.launcher3.views;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||
|
||||
import android.app.RemoteAction;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.allapps.AllAppsStore;
|
||||
import com.android.launcher3.allapps.search.AllAppsSearchBarController;
|
||||
import com.android.launcher3.allapps.search.SearchEventTracker;
|
||||
import com.android.launcher3.icons.BitmapInfo;
|
||||
import com.android.launcher3.icons.LauncherIcons;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
||||
import com.android.launcher3.model.data.RemoteActionItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.systemui.plugins.shared.SearchTarget;
|
||||
@@ -39,6 +58,17 @@ public class SearchResultIcon extends BubbleTextView implements
|
||||
|
||||
|
||||
public static final String TARGET_TYPE_APP = "app";
|
||||
public static final String TARGET_TYPE_HERO_APP = "hero_app";
|
||||
public static final String TARGET_TYPE_SHORTCUT = "shortcut";
|
||||
public static final String TARGET_TYPE_REMOTE_ACTION = "remote_action";
|
||||
public static final String TARGET_TYPE_SUGGEST = "suggest";
|
||||
|
||||
public static final String REMOTE_ACTION_SHOULD_START = "should_start_for_result";
|
||||
public static final String REMOTE_ACTION_TOKEN = "action_token";
|
||||
|
||||
|
||||
private static final String[] LONG_PRESS_SUPPORTED_TYPES =
|
||||
new String[]{TARGET_TYPE_APP, TARGET_TYPE_SHORTCUT, TARGET_TYPE_HERO_APP};
|
||||
|
||||
private final Launcher mLauncher;
|
||||
|
||||
@@ -64,26 +94,96 @@ public class SearchResultIcon extends BubbleTextView implements
|
||||
setOnFocusChangeListener(mLauncher.getFocusHandler());
|
||||
setOnClickListener(this);
|
||||
setOnLongClickListener(this);
|
||||
getLayoutParams().height = mLauncher.getDeviceProfile().allAppsCellHeightPx;
|
||||
setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
mLauncher.getDeviceProfile().allAppsCellHeightPx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySearchTarget(SearchTarget searchTarget) {
|
||||
mSearchTarget = searchTarget;
|
||||
AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore();
|
||||
SearchEventTracker.getInstance(getContext()).registerWeakHandler(mSearchTarget, this);
|
||||
if (searchTarget.getItemType().equals(TARGET_TYPE_APP)) {
|
||||
AppInfo appInfo = appsStore.getApp(new ComponentKey(searchTarget.getComponentName(),
|
||||
searchTarget.getUserHandle()));
|
||||
applyFromApplicationInfo(appInfo);
|
||||
switch (searchTarget.getItemType()) {
|
||||
case TARGET_TYPE_APP:
|
||||
case TARGET_TYPE_HERO_APP:
|
||||
prepareUsingApp(searchTarget.getComponentName(), searchTarget.getUserHandle());
|
||||
break;
|
||||
case TARGET_TYPE_SHORTCUT:
|
||||
prepareUsingShortcutInfo(searchTarget.getShortcutInfos().get(0));
|
||||
break;
|
||||
case TARGET_TYPE_REMOTE_ACTION:
|
||||
case TARGET_TYPE_SUGGEST:
|
||||
prepareUsingRemoteAction(searchTarget.getRemoteAction(),
|
||||
searchTarget.getExtras().getString(REMOTE_ACTION_TOKEN),
|
||||
searchTarget.getExtras().getBoolean(REMOTE_ACTION_SHOULD_START),
|
||||
searchTarget.getItemType().equals(TARGET_TYPE_REMOTE_ACTION));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareUsingApp(ComponentName componentName, UserHandle userHandle) {
|
||||
AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore();
|
||||
AppInfo appInfo = appsStore.getApp(new ComponentKey(componentName, userHandle));
|
||||
applyFromApplicationInfo(appInfo);
|
||||
}
|
||||
|
||||
|
||||
private void prepareUsingShortcutInfo(ShortcutInfo shortcutInfo) {
|
||||
WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo(shortcutInfo, getContext());
|
||||
applyFromWorkspaceItem(workspaceItemInfo);
|
||||
LauncherAppState launcherAppState = LauncherAppState.getInstance(getContext());
|
||||
MODEL_EXECUTOR.execute(() -> {
|
||||
launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, shortcutInfo);
|
||||
reapplyItemInfoAsync(workspaceItemInfo);
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareUsingRemoteAction(RemoteAction remoteAction, String token, boolean start,
|
||||
boolean useIconToBadge) {
|
||||
RemoteActionItemInfo itemInfo = new RemoteActionItemInfo(remoteAction, token, start);
|
||||
|
||||
applyFromRemoteActionInfo(itemInfo);
|
||||
if (!loadIconFromResource()) {
|
||||
UI_HELPER_EXECUTOR.post(() -> {
|
||||
// If the Drawable from the remote action is not AdaptiveBitmap, styling will not
|
||||
// work.
|
||||
try (LauncherIcons li = LauncherIcons.obtain(getContext())) {
|
||||
Drawable d = itemInfo.getRemoteAction().getIcon().loadDrawable(getContext());
|
||||
BitmapInfo bitmap = li.createBadgedIconBitmap(d, itemInfo.user,
|
||||
Build.VERSION.SDK_INT);
|
||||
|
||||
if (useIconToBadge) {
|
||||
BitmapInfo placeholder = li.createIconBitmap(
|
||||
itemInfo.getRemoteAction().getTitle().toString().substring(0, 1),
|
||||
bitmap.color);
|
||||
itemInfo.bitmap = li.badgeBitmap(placeholder.icon, bitmap);
|
||||
} else {
|
||||
itemInfo.bitmap = bitmap;
|
||||
}
|
||||
reapplyItemInfoAsync(itemInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void reapplyItemInfoAsync(ItemInfoWithIcon itemInfoWithIcon) {
|
||||
MAIN_EXECUTOR.post(() -> reapplyItemInfo(itemInfoWithIcon));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleSelection(int eventType) {
|
||||
mLauncher.getItemOnClickListener().onClick(this);
|
||||
SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(
|
||||
new SearchTargetEvent.Builder(mSearchTarget, eventType).build());
|
||||
reportEvent(eventType);
|
||||
}
|
||||
|
||||
private void reportEvent(int eventType) {
|
||||
SearchTargetEvent.Builder b = new SearchTargetEvent.Builder(mSearchTarget, eventType);
|
||||
if (mSearchTarget.getItemType().equals(TARGET_TYPE_SHORTCUT)) {
|
||||
b.setShortcutPosition(0);
|
||||
}
|
||||
SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(b.build());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,8 +193,22 @@ public class SearchResultIcon extends BubbleTextView implements
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
SearchEventTracker.INSTANCE.get(mLauncher).notifySearchTargetEvent(
|
||||
new SearchTargetEvent.Builder(mSearchTarget, SearchTargetEvent.LONG_PRESS).build());
|
||||
if (!supportsLongPress(mSearchTarget.getItemType())) {
|
||||
return false;
|
||||
}
|
||||
reportEvent(SearchTargetEvent.LONG_PRESS);
|
||||
return ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(view);
|
||||
|
||||
}
|
||||
|
||||
private boolean supportsLongPress(String type) {
|
||||
for (String t : LONG_PRESS_SUPPORTED_TYPES) {
|
||||
if (t.equals(type)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean loadIconFromResource() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user