Loading src/com/android/launcher3/BubbleTextView.java +12 −5 Original line number Diff line number Diff line Loading @@ -280,7 +280,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, applyDotState(info, false /* animate */); } public void applyFromPackageItemInfo(PackageItemInfo info) { /** * Apply label and tag using a generic {@link ItemInfoWithIcon} */ public void applyFromItemInfoWithIcon(ItemInfoWithIcon info) { applyIconAndLabel(info); // We don't need to check the info since it's not a WorkspaceItemInfo super.setTag(info); Loading Loading @@ -407,12 +410,14 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Draws the notification dot in the top right corner of the icon bounds. * * @param canvas The canvas to draw to. */ protected void drawDotIfNecessary(Canvas canvas) { if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) { getIconBounds(mDotParams.iconBounds); Utilities.scaleRectAboutCenter(mDotParams.iconBounds, IconShape.getNormalizationScale()); Utilities.scaleRectAboutCenter(mDotParams.iconBounds, IconShape.getNormalizationScale()); final int scrollX = getScrollX(); final int scrollY = getScrollY(); canvas.translate(scrollX, scrollY); Loading Loading @@ -507,6 +512,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Creates an animator to fade the text in or out. * * @param fadeIn Whether the text should fade in or fade out. */ public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) { Loading Loading @@ -663,7 +669,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, applyFromWorkspaceItem((WorkspaceItemInfo) info); mActivity.invalidateParent(info); } else if (info instanceof PackageItemInfo) { applyFromPackageItemInfo((PackageItemInfo) info); applyFromItemInfoWithIcon((PackageItemInfo) info); } mDisableRelayout = false; Loading Loading @@ -761,7 +767,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, public SafeCloseable prepareDrawDragView() { resetIconScale(); setForceHideDot(true); return () -> { }; return () -> { }; } private void resetIconScale() { Loading src/com/android/launcher3/allapps/search/AppsSearchPipeline.java +1 −63 Original line number Diff line number Diff line Loading @@ -15,26 +15,15 @@ */ package com.android.launcher3.allapps.search; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS; import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_SEARCH_HERO_APP; import android.content.Context; import android.content.pm.ShortcutInfo; import androidx.annotation.WorkerThread; import com.android.launcher3.LauncherAppState; import com.android.launcher3.allapps.AllAppsGridAdapter; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHandler; import com.android.launcher3.icons.IconCache; import com.android.launcher3.model.AllAppsList; import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.PopupPopulator; import com.android.launcher3.shortcuts.ShortcutRequest; import java.util.ArrayList; import java.util.List; Loading @@ -46,64 +35,28 @@ import java.util.function.Consumer; public class AppsSearchPipeline implements SearchPipeline { private static final int MAX_RESULTS_COUNT = 5; private static final int MAX_HERO_SECTION_COUNT = 2; private static final int MAX_SHORTCUTS_COUNT = 2; private final SearchSectionInfo mSearchSectionInfo; private final LauncherAppState mLauncherAppState; private final boolean mHeroSectionSupported; public AppsSearchPipeline(Context context, LauncherAppState launcherAppState) { this(context, launcherAppState, true); } public AppsSearchPipeline(Context context, LauncherAppState launcherAppState, boolean supportsHeroView) { mLauncherAppState = launcherAppState; mSearchSectionInfo = new SearchSectionInfo(); mSearchSectionInfo.setDecorationHandler( new SectionDecorationHandler(context, true)); mHeroSectionSupported = supportsHeroView; } @Override @WorkerThread public void performSearch(String query, Consumer<ArrayList<AdapterItem>> callback) { mLauncherAppState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() { @Override public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { List<AppInfo> matchingResults = getTitleMatchResult(apps.data, query); if (mHeroSectionSupported && matchingResults.size() <= MAX_HERO_SECTION_COUNT) { callback.accept(getHeroAdapterItems(app.getContext(), matchingResults)); } else { callback.accept(getAdapterItems(matchingResults)); } } }); } /** * Returns MAX_SHORTCUTS_COUNT shortcuts from local cache * TODO: Shortcuts should be ranked based on relevancy */ private ArrayList<WorkspaceItemInfo> getShortcutInfos(Context context, AppInfo appInfo) { List<ShortcutInfo> shortcuts = new ShortcutRequest(context, appInfo.user) .withContainer(appInfo.getTargetComponent()) .query(ShortcutRequest.PUBLISHED); shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, null); IconCache cache = LauncherAppState.getInstance(context).getIconCache(); ArrayList<WorkspaceItemInfo> shortcutItems = new ArrayList<>(); for (int i = 0; i < shortcuts.size() && i < MAX_SHORTCUTS_COUNT; i++) { final ShortcutInfo shortcut = shortcuts.get(i); final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, context); cache.getUnbadgedShortcutIcon(si, shortcut); si.rank = i; si.container = CONTAINER_SHORTCUTS; shortcutItems.add(si); } return shortcutItems; } /** * Filters {@link AppInfo}s matching specified query */ Loading @@ -122,21 +75,6 @@ public class AppsSearchPipeline implements SearchPipeline { return result; } private ArrayList<AdapterItem> getHeroAdapterItems(Context context, List<AppInfo> apps) { ArrayList<AdapterItem> adapterItems = new ArrayList<>(); for (int i = 0; i < apps.size(); i++) { //hero app AppInfo appInfo = apps.get(i); ArrayList<WorkspaceItemInfo> shortcuts = getShortcutInfos(context, appInfo); AdapterItem adapterItem = new AllAppsGridAdapter.AdapterItemWithPayload(shortcuts, VIEW_TYPE_SEARCH_HERO_APP); adapterItem.appInfo = appInfo; adapterItem.searchSectionInfo = mSearchSectionInfo; adapterItems.add(adapterItem); } return adapterItems; } private ArrayList<AdapterItem> getAdapterItems(List<AppInfo> matchingApps) { ArrayList<AdapterItem> items = new ArrayList<>(); for (int i = 0; i < matchingApps.size() && i < MAX_RESULTS_COUNT; i++) { Loading src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { public DefaultAppSearchAlgorithm(Context context, LauncherAppState launcherAppState) { mResultHandler = new Handler(); mAppsSearchPipeline = new AppsSearchPipeline(context, launcherAppState, false); mAppsSearchPipeline = new AppsSearchPipeline(context, launcherAppState); } @Override Loading src/com/android/launcher3/model/AllAppsList.java +1 −1 Original line number Diff line number Diff line Loading @@ -305,7 +305,7 @@ public class AllAppsList { * * @return the corresponding AppInfo or null */ private @Nullable AppInfo findAppInfo(@NonNull ComponentName componentName, public @Nullable AppInfo findAppInfo(@NonNull ComponentName componentName, @NonNull UserHandle user) { for (AppInfo info: data) { if (componentName.equals(info.componentName) && user.equals(info.user)) { Loading src/com/android/launcher3/views/HeroSearchResultView.java +6 −4 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.touch.ItemLongClickListener; Loading @@ -47,8 +48,9 @@ import java.util.List; * A view representing a high confidence app search result that includes shortcuts */ public class HeroSearchResultView extends LinearLayout implements DragSource, AllAppsSearchBarController.PayloadResultHandler<List<WorkspaceItemInfo>> { AllAppsSearchBarController.PayloadResultHandler<List<ItemInfoWithIcon>> { public static final int MAX_SHORTCUTS_COUNT = 2; BubbleTextView mBubbleTextView; View mIconView; BubbleTextView[] mDeepShortcutTextViews = new BubbleTextView[2]; Loading Loading @@ -97,15 +99,15 @@ public class HeroSearchResultView extends LinearLayout implements DragSource, * Apply {@link ItemInfo} for appIcon and shortcut Icons */ @Override public void applyAdapterInfo(AdapterItemWithPayload<List<WorkspaceItemInfo>> adapterItem) { public void applyAdapterInfo(AdapterItemWithPayload<List<ItemInfoWithIcon>> adapterItem) { mBubbleTextView.applyFromApplicationInfo(adapterItem.appInfo); mIconView.setBackground(mBubbleTextView.getIcon()); mIconView.setTag(adapterItem.appInfo); List<WorkspaceItemInfo> shorcutInfos = adapterItem.getPayload(); List<ItemInfoWithIcon> shorcutInfos = adapterItem.getPayload(); for (int i = 0; i < mDeepShortcutTextViews.length; i++) { mDeepShortcutTextViews[i].setVisibility(shorcutInfos.size() > i ? VISIBLE : GONE); if (i < shorcutInfos.size()) { mDeepShortcutTextViews[i].applyFromWorkspaceItem(shorcutInfos.get(i)); mDeepShortcutTextViews[i].applyFromItemInfoWithIcon(shorcutInfos.get(i)); } } } Loading Loading
src/com/android/launcher3/BubbleTextView.java +12 −5 Original line number Diff line number Diff line Loading @@ -280,7 +280,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, applyDotState(info, false /* animate */); } public void applyFromPackageItemInfo(PackageItemInfo info) { /** * Apply label and tag using a generic {@link ItemInfoWithIcon} */ public void applyFromItemInfoWithIcon(ItemInfoWithIcon info) { applyIconAndLabel(info); // We don't need to check the info since it's not a WorkspaceItemInfo super.setTag(info); Loading Loading @@ -407,12 +410,14 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Draws the notification dot in the top right corner of the icon bounds. * * @param canvas The canvas to draw to. */ protected void drawDotIfNecessary(Canvas canvas) { if (!mForceHideDot && (hasDot() || mDotParams.scale > 0)) { getIconBounds(mDotParams.iconBounds); Utilities.scaleRectAboutCenter(mDotParams.iconBounds, IconShape.getNormalizationScale()); Utilities.scaleRectAboutCenter(mDotParams.iconBounds, IconShape.getNormalizationScale()); final int scrollX = getScrollX(); final int scrollY = getScrollY(); canvas.translate(scrollX, scrollY); Loading Loading @@ -507,6 +512,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Creates an animator to fade the text in or out. * * @param fadeIn Whether the text should fade in or fade out. */ public ObjectAnimator createTextAlphaAnimator(boolean fadeIn) { Loading Loading @@ -663,7 +669,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, applyFromWorkspaceItem((WorkspaceItemInfo) info); mActivity.invalidateParent(info); } else if (info instanceof PackageItemInfo) { applyFromPackageItemInfo((PackageItemInfo) info); applyFromItemInfoWithIcon((PackageItemInfo) info); } mDisableRelayout = false; Loading Loading @@ -761,7 +767,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, public SafeCloseable prepareDrawDragView() { resetIconScale(); setForceHideDot(true); return () -> { }; return () -> { }; } private void resetIconScale() { Loading
src/com/android/launcher3/allapps/search/AppsSearchPipeline.java +1 −63 Original line number Diff line number Diff line Loading @@ -15,26 +15,15 @@ */ package com.android.launcher3.allapps.search; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS; import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_SEARCH_HERO_APP; import android.content.Context; import android.content.pm.ShortcutInfo; import androidx.annotation.WorkerThread; import com.android.launcher3.LauncherAppState; import com.android.launcher3.allapps.AllAppsGridAdapter; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.allapps.AllAppsSectionDecorator.SectionDecorationHandler; import com.android.launcher3.icons.IconCache; import com.android.launcher3.model.AllAppsList; import com.android.launcher3.model.BaseModelUpdateTask; import com.android.launcher3.model.BgDataModel; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.PopupPopulator; import com.android.launcher3.shortcuts.ShortcutRequest; import java.util.ArrayList; import java.util.List; Loading @@ -46,64 +35,28 @@ import java.util.function.Consumer; public class AppsSearchPipeline implements SearchPipeline { private static final int MAX_RESULTS_COUNT = 5; private static final int MAX_HERO_SECTION_COUNT = 2; private static final int MAX_SHORTCUTS_COUNT = 2; private final SearchSectionInfo mSearchSectionInfo; private final LauncherAppState mLauncherAppState; private final boolean mHeroSectionSupported; public AppsSearchPipeline(Context context, LauncherAppState launcherAppState) { this(context, launcherAppState, true); } public AppsSearchPipeline(Context context, LauncherAppState launcherAppState, boolean supportsHeroView) { mLauncherAppState = launcherAppState; mSearchSectionInfo = new SearchSectionInfo(); mSearchSectionInfo.setDecorationHandler( new SectionDecorationHandler(context, true)); mHeroSectionSupported = supportsHeroView; } @Override @WorkerThread public void performSearch(String query, Consumer<ArrayList<AdapterItem>> callback) { mLauncherAppState.getModel().enqueueModelUpdateTask(new BaseModelUpdateTask() { @Override public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { List<AppInfo> matchingResults = getTitleMatchResult(apps.data, query); if (mHeroSectionSupported && matchingResults.size() <= MAX_HERO_SECTION_COUNT) { callback.accept(getHeroAdapterItems(app.getContext(), matchingResults)); } else { callback.accept(getAdapterItems(matchingResults)); } } }); } /** * Returns MAX_SHORTCUTS_COUNT shortcuts from local cache * TODO: Shortcuts should be ranked based on relevancy */ private ArrayList<WorkspaceItemInfo> getShortcutInfos(Context context, AppInfo appInfo) { List<ShortcutInfo> shortcuts = new ShortcutRequest(context, appInfo.user) .withContainer(appInfo.getTargetComponent()) .query(ShortcutRequest.PUBLISHED); shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, null); IconCache cache = LauncherAppState.getInstance(context).getIconCache(); ArrayList<WorkspaceItemInfo> shortcutItems = new ArrayList<>(); for (int i = 0; i < shortcuts.size() && i < MAX_SHORTCUTS_COUNT; i++) { final ShortcutInfo shortcut = shortcuts.get(i); final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, context); cache.getUnbadgedShortcutIcon(si, shortcut); si.rank = i; si.container = CONTAINER_SHORTCUTS; shortcutItems.add(si); } return shortcutItems; } /** * Filters {@link AppInfo}s matching specified query */ Loading @@ -122,21 +75,6 @@ public class AppsSearchPipeline implements SearchPipeline { return result; } private ArrayList<AdapterItem> getHeroAdapterItems(Context context, List<AppInfo> apps) { ArrayList<AdapterItem> adapterItems = new ArrayList<>(); for (int i = 0; i < apps.size(); i++) { //hero app AppInfo appInfo = apps.get(i); ArrayList<WorkspaceItemInfo> shortcuts = getShortcutInfos(context, appInfo); AdapterItem adapterItem = new AllAppsGridAdapter.AdapterItemWithPayload(shortcuts, VIEW_TYPE_SEARCH_HERO_APP); adapterItem.appInfo = appInfo; adapterItem.searchSectionInfo = mSearchSectionInfo; adapterItems.add(adapterItem); } return adapterItems; } private ArrayList<AdapterItem> getAdapterItems(List<AppInfo> matchingApps) { ArrayList<AdapterItem> items = new ArrayList<>(); for (int i = 0; i < matchingApps.size() && i < MAX_RESULTS_COUNT; i++) { Loading
src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { public DefaultAppSearchAlgorithm(Context context, LauncherAppState launcherAppState) { mResultHandler = new Handler(); mAppsSearchPipeline = new AppsSearchPipeline(context, launcherAppState, false); mAppsSearchPipeline = new AppsSearchPipeline(context, launcherAppState); } @Override Loading
src/com/android/launcher3/model/AllAppsList.java +1 −1 Original line number Diff line number Diff line Loading @@ -305,7 +305,7 @@ public class AllAppsList { * * @return the corresponding AppInfo or null */ private @Nullable AppInfo findAppInfo(@NonNull ComponentName componentName, public @Nullable AppInfo findAppInfo(@NonNull ComponentName componentName, @NonNull UserHandle user) { for (AppInfo info: data) { if (componentName.equals(info.componentName) && user.equals(info.user)) { Loading
src/com/android/launcher3/views/HeroSearchResultView.java +6 −4 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.touch.ItemLongClickListener; Loading @@ -47,8 +48,9 @@ import java.util.List; * A view representing a high confidence app search result that includes shortcuts */ public class HeroSearchResultView extends LinearLayout implements DragSource, AllAppsSearchBarController.PayloadResultHandler<List<WorkspaceItemInfo>> { AllAppsSearchBarController.PayloadResultHandler<List<ItemInfoWithIcon>> { public static final int MAX_SHORTCUTS_COUNT = 2; BubbleTextView mBubbleTextView; View mIconView; BubbleTextView[] mDeepShortcutTextViews = new BubbleTextView[2]; Loading Loading @@ -97,15 +99,15 @@ public class HeroSearchResultView extends LinearLayout implements DragSource, * Apply {@link ItemInfo} for appIcon and shortcut Icons */ @Override public void applyAdapterInfo(AdapterItemWithPayload<List<WorkspaceItemInfo>> adapterItem) { public void applyAdapterInfo(AdapterItemWithPayload<List<ItemInfoWithIcon>> adapterItem) { mBubbleTextView.applyFromApplicationInfo(adapterItem.appInfo); mIconView.setBackground(mBubbleTextView.getIcon()); mIconView.setTag(adapterItem.appInfo); List<WorkspaceItemInfo> shorcutInfos = adapterItem.getPayload(); List<ItemInfoWithIcon> shorcutInfos = adapterItem.getPayload(); for (int i = 0; i < mDeepShortcutTextViews.length; i++) { mDeepShortcutTextViews[i].setVisibility(shorcutInfos.size() > i ? VISIBLE : GONE); if (i < shorcutInfos.size()) { mDeepShortcutTextViews[i].applyFromWorkspaceItem(shorcutInfos.get(i)); mDeepShortcutTextViews[i].applyFromItemInfoWithIcon(shorcutInfos.get(i)); } } } Loading