Loading src/com/android/launcher3/views/SearchResultIcon.java +39 −36 Original line number Diff line number Diff line Loading @@ -30,8 +30,6 @@ 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; Loading @@ -49,6 +47,8 @@ import com.android.launcher3.util.ComponentKey; import com.android.systemui.plugins.shared.SearchTarget; import com.android.systemui.plugins.shared.SearchTargetEvent; import java.util.function.Consumer; /** * A {@link BubbleTextView} representing a single cell result in AllApps */ Loading @@ -61,7 +61,6 @@ public class SearchResultIcon extends BubbleTextView implements 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"; Loading @@ -73,6 +72,7 @@ public class SearchResultIcon extends BubbleTextView implements private final Launcher mLauncher; private SearchTarget mSearchTarget; private Consumer<ItemInfoWithIcon> mOnItemInfoChanged; public SearchResultIcon(Context context) { this(context, null, 0); Loading @@ -98,6 +98,15 @@ public class SearchResultIcon extends BubbleTextView implements mLauncher.getDeviceProfile().allAppsCellHeightPx)); } /** * Applies search target with a ItemInfoWithIcon consumer to be called after itemInfo is * constructed */ public void applySearchTarget(SearchTarget searchTarget, Consumer<ItemInfoWithIcon> cb) { mOnItemInfoChanged = cb; applySearchTarget(searchTarget); } @Override public void applySearchTarget(SearchTarget searchTarget) { mSearchTarget = searchTarget; Loading @@ -111,7 +120,6 @@ public class SearchResultIcon extends BubbleTextView implements 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), Loading @@ -124,25 +132,24 @@ public class SearchResultIcon extends BubbleTextView implements AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore(); AppInfo appInfo = appsStore.getApp(new ComponentKey(componentName, userHandle)); applyFromApplicationInfo(appInfo); notifyItemInfoChanged(appInfo); } private void prepareUsingShortcutInfo(ShortcutInfo shortcutInfo) { WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo(shortcutInfo, getContext()); applyFromWorkspaceItem(workspaceItemInfo); notifyItemInfoChanged(workspaceItemInfo); LauncherAppState launcherAppState = LauncherAppState.getInstance(getContext()); MODEL_EXECUTOR.execute(() -> { launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, shortcutInfo); reapplyItemInfoAsync(workspaceItemInfo); MAIN_EXECUTOR.post(() -> applyFromWorkspaceItem(workspaceItemInfo)); }); } private void prepareUsingRemoteAction(RemoteAction remoteAction, String token, boolean start, boolean useIconToBadge) { RemoteActionItemInfo itemInfo = new RemoteActionItemInfo(remoteAction, token, start); applyFromRemoteActionInfo(itemInfo); if (!loadIconFromResource()) { notifyItemInfoChanged(itemInfo); UI_HELPER_EXECUTOR.post(() -> { // If the Drawable from the remote action is not AdaptiveBitmap, styling will not // work. Loading @@ -159,17 +166,10 @@ public class SearchResultIcon extends BubbleTextView implements } else { itemInfo.bitmap = bitmap; } reapplyItemInfoAsync(itemInfo); } MAIN_EXECUTOR.post(() -> applyFromRemoteActionInfo(itemInfo)); }); } } @UiThread void reapplyItemInfoAsync(ItemInfoWithIcon itemInfoWithIcon) { MAIN_EXECUTOR.post(() -> reapplyItemInfo(itemInfoWithIcon)); } @Override public void handleSelection(int eventType) { Loading Loading @@ -208,7 +208,10 @@ public class SearchResultIcon extends BubbleTextView implements return false; } protected boolean loadIconFromResource() { return false; private void notifyItemInfoChanged(ItemInfoWithIcon itemInfoWithIcon) { if (mOnItemInfoChanged != null) { mOnItemInfoChanged.accept(itemInfoWithIcon); mOnItemInfoChanged = null; } } } src/com/android/launcher3/views/SearchResultIconRow.java +9 −4 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.systemui.plugins.shared.SearchTargetEvent; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; /** * A full width representation of {@link SearchResultIcon} with a secondary label and inline Loading @@ -53,7 +54,7 @@ import java.util.List; */ public class SearchResultIconRow extends LinearLayout implements AllAppsSearchBarController.SearchTargetHandler, View.OnClickListener, View.OnLongClickListener { View.OnLongClickListener, Consumer<ItemInfoWithIcon> { public static final int MAX_SHORTCUTS_COUNT = 2; Loading Loading @@ -95,6 +96,7 @@ public class SearchResultIconRow extends LinearLayout implements mShortcutViews[1] = findViewById(R.id.shortcut_1); mResultIcon.getLayoutParams().height = iconSize; mResultIcon.getLayoutParams().width = iconSize; mResultIcon.setTextVisibility(false); for (BubbleTextView bubbleTextView : mShortcutViews) { ViewGroup.LayoutParams lp = bubbleTextView.getLayoutParams(); lp.width = iconSize; Loading @@ -113,9 +115,7 @@ public class SearchResultIconRow extends LinearLayout implements @Override public void applySearchTarget(SearchTarget searchTarget) { mSearchTarget = searchTarget; mResultIcon.applySearchTarget(searchTarget); mResultIcon.setTextVisibility(false); mTitleView.setText(mResultIcon.getText()); mResultIcon.applySearchTarget(searchTarget, this); String itemType = searchTarget.getItemType(); boolean showDesc = itemType.equals(SearchResultIcon.TARGET_TYPE_SHORTCUT); mDescriptionView.setVisibility(showDesc ? VISIBLE : GONE); Loading @@ -138,6 +138,11 @@ public class SearchResultIconRow extends LinearLayout implements } } @Override public void accept(ItemInfoWithIcon itemInfoWithIcon) { mTitleView.setText(itemInfoWithIcon.title); } private void showInlineShortcuts(List<ShortcutInfo> infos) { if (infos == null) return; ArrayList<Pair<ShortcutInfo, ItemInfoWithIcon>> shortcuts = new ArrayList<>(); Loading src/com/android/launcher3/views/SearchResultSuggestion.java +3 −3 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import com.android.launcher3.R; */ public class SearchResultSuggestion extends SearchResultIcon { public static final String TARGET_TYPE_SUGGEST = "suggest"; private final Drawable mCustomIcon; public SearchResultSuggestion(Context context) { Loading Loading @@ -55,8 +56,7 @@ public class SearchResultSuggestion extends SearchResultIcon { } @Override protected boolean loadIconFromResource() { setIcon(mCustomIcon); return true; protected void setIcon(Drawable icon) { super.setIcon(mCustomIcon); } } Loading
src/com/android/launcher3/views/SearchResultIcon.java +39 −36 Original line number Diff line number Diff line Loading @@ -30,8 +30,6 @@ 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; Loading @@ -49,6 +47,8 @@ import com.android.launcher3.util.ComponentKey; import com.android.systemui.plugins.shared.SearchTarget; import com.android.systemui.plugins.shared.SearchTargetEvent; import java.util.function.Consumer; /** * A {@link BubbleTextView} representing a single cell result in AllApps */ Loading @@ -61,7 +61,6 @@ public class SearchResultIcon extends BubbleTextView implements 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"; Loading @@ -73,6 +72,7 @@ public class SearchResultIcon extends BubbleTextView implements private final Launcher mLauncher; private SearchTarget mSearchTarget; private Consumer<ItemInfoWithIcon> mOnItemInfoChanged; public SearchResultIcon(Context context) { this(context, null, 0); Loading @@ -98,6 +98,15 @@ public class SearchResultIcon extends BubbleTextView implements mLauncher.getDeviceProfile().allAppsCellHeightPx)); } /** * Applies search target with a ItemInfoWithIcon consumer to be called after itemInfo is * constructed */ public void applySearchTarget(SearchTarget searchTarget, Consumer<ItemInfoWithIcon> cb) { mOnItemInfoChanged = cb; applySearchTarget(searchTarget); } @Override public void applySearchTarget(SearchTarget searchTarget) { mSearchTarget = searchTarget; Loading @@ -111,7 +120,6 @@ public class SearchResultIcon extends BubbleTextView implements 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), Loading @@ -124,25 +132,24 @@ public class SearchResultIcon extends BubbleTextView implements AllAppsStore appsStore = mLauncher.getAppsView().getAppsStore(); AppInfo appInfo = appsStore.getApp(new ComponentKey(componentName, userHandle)); applyFromApplicationInfo(appInfo); notifyItemInfoChanged(appInfo); } private void prepareUsingShortcutInfo(ShortcutInfo shortcutInfo) { WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo(shortcutInfo, getContext()); applyFromWorkspaceItem(workspaceItemInfo); notifyItemInfoChanged(workspaceItemInfo); LauncherAppState launcherAppState = LauncherAppState.getInstance(getContext()); MODEL_EXECUTOR.execute(() -> { launcherAppState.getIconCache().getShortcutIcon(workspaceItemInfo, shortcutInfo); reapplyItemInfoAsync(workspaceItemInfo); MAIN_EXECUTOR.post(() -> applyFromWorkspaceItem(workspaceItemInfo)); }); } private void prepareUsingRemoteAction(RemoteAction remoteAction, String token, boolean start, boolean useIconToBadge) { RemoteActionItemInfo itemInfo = new RemoteActionItemInfo(remoteAction, token, start); applyFromRemoteActionInfo(itemInfo); if (!loadIconFromResource()) { notifyItemInfoChanged(itemInfo); UI_HELPER_EXECUTOR.post(() -> { // If the Drawable from the remote action is not AdaptiveBitmap, styling will not // work. Loading @@ -159,17 +166,10 @@ public class SearchResultIcon extends BubbleTextView implements } else { itemInfo.bitmap = bitmap; } reapplyItemInfoAsync(itemInfo); } MAIN_EXECUTOR.post(() -> applyFromRemoteActionInfo(itemInfo)); }); } } @UiThread void reapplyItemInfoAsync(ItemInfoWithIcon itemInfoWithIcon) { MAIN_EXECUTOR.post(() -> reapplyItemInfo(itemInfoWithIcon)); } @Override public void handleSelection(int eventType) { Loading Loading @@ -208,7 +208,10 @@ public class SearchResultIcon extends BubbleTextView implements return false; } protected boolean loadIconFromResource() { return false; private void notifyItemInfoChanged(ItemInfoWithIcon itemInfoWithIcon) { if (mOnItemInfoChanged != null) { mOnItemInfoChanged.accept(itemInfoWithIcon); mOnItemInfoChanged = null; } } }
src/com/android/launcher3/views/SearchResultIconRow.java +9 −4 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import com.android.systemui.plugins.shared.SearchTargetEvent; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; /** * A full width representation of {@link SearchResultIcon} with a secondary label and inline Loading @@ -53,7 +54,7 @@ import java.util.List; */ public class SearchResultIconRow extends LinearLayout implements AllAppsSearchBarController.SearchTargetHandler, View.OnClickListener, View.OnLongClickListener { View.OnLongClickListener, Consumer<ItemInfoWithIcon> { public static final int MAX_SHORTCUTS_COUNT = 2; Loading Loading @@ -95,6 +96,7 @@ public class SearchResultIconRow extends LinearLayout implements mShortcutViews[1] = findViewById(R.id.shortcut_1); mResultIcon.getLayoutParams().height = iconSize; mResultIcon.getLayoutParams().width = iconSize; mResultIcon.setTextVisibility(false); for (BubbleTextView bubbleTextView : mShortcutViews) { ViewGroup.LayoutParams lp = bubbleTextView.getLayoutParams(); lp.width = iconSize; Loading @@ -113,9 +115,7 @@ public class SearchResultIconRow extends LinearLayout implements @Override public void applySearchTarget(SearchTarget searchTarget) { mSearchTarget = searchTarget; mResultIcon.applySearchTarget(searchTarget); mResultIcon.setTextVisibility(false); mTitleView.setText(mResultIcon.getText()); mResultIcon.applySearchTarget(searchTarget, this); String itemType = searchTarget.getItemType(); boolean showDesc = itemType.equals(SearchResultIcon.TARGET_TYPE_SHORTCUT); mDescriptionView.setVisibility(showDesc ? VISIBLE : GONE); Loading @@ -138,6 +138,11 @@ public class SearchResultIconRow extends LinearLayout implements } } @Override public void accept(ItemInfoWithIcon itemInfoWithIcon) { mTitleView.setText(itemInfoWithIcon.title); } private void showInlineShortcuts(List<ShortcutInfo> infos) { if (infos == null) return; ArrayList<Pair<ShortcutInfo, ItemInfoWithIcon>> shortcuts = new ArrayList<>(); Loading
src/com/android/launcher3/views/SearchResultSuggestion.java +3 −3 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import com.android.launcher3.R; */ public class SearchResultSuggestion extends SearchResultIcon { public static final String TARGET_TYPE_SUGGEST = "suggest"; private final Drawable mCustomIcon; public SearchResultSuggestion(Context context) { Loading Loading @@ -55,8 +56,7 @@ public class SearchResultSuggestion extends SearchResultIcon { } @Override protected boolean loadIconFromResource() { setIcon(mCustomIcon); return true; protected void setIcon(Drawable icon) { super.setIcon(mCustomIcon); } }