Search in sources :

Example 46 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PopupDataProvider method getRecommendedWidgets.

/**
 * Returns a list of recommended widgets.
 */
public List<WidgetItem> getRecommendedWidgets() {
    HashMap<ComponentKey, WidgetItem> allWidgetItems = new HashMap<>();
    mAllWidgets.stream().filter(entry -> entry instanceof WidgetsListContentEntry).forEach(entry -> ((WidgetsListContentEntry) entry).mWidgets.forEach(widget -> allWidgetItems.put(new ComponentKey(widget.componentName, widget.user), widget)));
    return mRecommendedWidgets.stream().map(recommendedWidget -> allWidgetItems.get(new ComponentKey(recommendedWidget.getTargetComponent(), recommendedWidget.user))).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) HashMap(java.util.HashMap) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) WidgetItem(com.android.launcher3.model.WidgetItem) Map(java.util.Map) Log(android.util.Log) PrintWriter(java.io.PrintWriter) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) PackageUserKey(com.android.launcher3.util.PackageUserKey) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) NotificationListener(com.android.launcher3.notification.NotificationListener) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) ComponentKey(com.android.launcher3.util.ComponentKey) Collections(java.util.Collections) StatusBarNotification(android.service.notification.StatusBarNotification) DotInfo(com.android.launcher3.dot.DotInfo) HashMap(java.util.HashMap) ComponentKey(com.android.launcher3.util.ComponentKey) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 47 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PopupDataProvider method getShortcutCountForItem.

public int getShortcutCountForItem(ItemInfo info) {
    if (!ShortcutUtil.supportsDeepShortcuts(info)) {
        return 0;
    }
    ComponentName component = info.getTargetComponent();
    if (component == null) {
        return 0;
    }
    Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user));
    return count == null ? 0 : count;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Example 48 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PinnedAppsAdapter method parseComponentKey.

private ComponentKey parseComponentKey(String string) {
    try {
        String[] parts = string.split("#");
        UserHandle user;
        if (parts.length > 2) {
            user = UserCache.INSTANCE.get(mLauncher).getUserForSerialNumber(Long.parseLong(parts[2]));
        } else {
            user = Process.myUserHandle();
        }
        ComponentName cn = ComponentName.unflattenFromString(parts[0]);
        return new ComponentKey(cn, user);
    } catch (Exception e) {
        return null;
    }
}
Also used : UserHandle(android.os.UserHandle) ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Example 49 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherPreviewRenderer method inflateAndAddWidgets.

private void inflateAndAddWidgets(LauncherAppWidgetInfo info, Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
    if (widgetProviderInfoMap == null) {
        return;
    }
    AppWidgetProviderInfo providerInfo = widgetProviderInfoMap.get(new ComponentKey(info.providerName, info.user));
    if (providerInfo == null) {
        return;
    }
    inflateAndAddWidgets(info, LauncherAppWidgetProviderInfo.fromProviderInfo(getApplicationContext(), providerInfo));
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ComponentKey(com.android.launcher3.util.ComponentKey)

Example 50 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherPreviewRenderer method populate.

private void populate(BgDataModel dataModel, Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
    // Separate the items that are on the current screen, and the other remaining items.
    ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
    ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
    ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
    IntSet currentScreenIds = IntSet.wrap(mWorkspaceScreens.keySet());
    filterCurrentWorkspaceItems(currentScreenIds, dataModel.workspaceItems, currentWorkspaceItems, otherWorkspaceItems);
    filterCurrentWorkspaceItems(currentScreenIds, dataModel.appWidgets, currentAppWidgets, otherAppWidgets);
    sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
    for (ItemInfo itemInfo : currentWorkspaceItems) {
        switch(itemInfo.itemType) {
            case Favorites.ITEM_TYPE_APPLICATION:
            case Favorites.ITEM_TYPE_SHORTCUT:
            case Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                inflateAndAddIcon((WorkspaceItemInfo) itemInfo);
                break;
            case Favorites.ITEM_TYPE_FOLDER:
                inflateAndAddFolder((FolderInfo) itemInfo);
                break;
            default:
                break;
        }
    }
    for (ItemInfo itemInfo : currentAppWidgets) {
        switch(itemInfo.itemType) {
            case Favorites.ITEM_TYPE_APPWIDGET:
            case Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
                if (widgetProviderInfoMap != null) {
                    inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, widgetProviderInfoMap);
                } else {
                    inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, dataModel.widgetsModel);
                }
                break;
            default:
                break;
        }
    }
    IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems, mDp.numShownHotseatIcons);
    FixedContainerItems hotseatpredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
    List<ItemInfo> predictions = hotseatpredictions == null ? Collections.emptyList() : hotseatpredictions.items;
    int count = Math.min(ranks.size(), predictions.size());
    for (int i = 0; i < count; i++) {
        int rank = ranks.get(i);
        WorkspaceItemInfo itemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) predictions.get(i));
        itemInfo.container = CONTAINER_HOTSEAT_PREDICTION;
        itemInfo.rank = rank;
        itemInfo.cellX = mHotseat.getCellXFromOrder(rank);
        itemInfo.cellY = mHotseat.getCellYFromOrder(rank);
        itemInfo.screenId = rank;
        inflateAndAddPredictedIcon(itemInfo);
    }
    // Add first page QSB
    if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
        CellLayout firstScreen = mWorkspaceScreens.get(FIRST_SCREEN_ID);
        View qsb = mHomeElementInflater.inflate(R.layout.qsb_preview, firstScreen, false);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstScreen.getCountX(), 1);
        lp.canReorder = false;
        firstScreen.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true);
    }
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
    dispatchVisibilityAggregated(mRootView, true);
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
    // Additional measure for views which use auto text size API
    measureView(mRootView, mDp.widthPx, mDp.heightPx);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) IntSet(com.android.launcher3.util.IntSet) ArrayList(java.util.ArrayList) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) BaseLauncherAppWidgetHostView(com.android.launcher3.widget.BaseLauncherAppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) SparseIntArray(android.util.SparseIntArray) IntArray(com.android.launcher3.util.IntArray) CellLayout(com.android.launcher3.CellLayout) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)98 ComponentName (android.content.ComponentName)40 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 ArrayList (java.util.ArrayList)26 ShortcutInfo (android.content.pm.ShortcutInfo)21 UserHandle (android.os.UserHandle)20 HashMap (java.util.HashMap)19 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)17 PackageUserKey (com.android.launcher3.util.PackageUserKey)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)16 Context (android.content.Context)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 List (java.util.List)13 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)11 AppTarget (android.app.prediction.AppTarget)10 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)10 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)10 QueryResult (com.android.launcher3.shortcuts.ShortcutRequest.QueryResult)10