Search in sources :

Example 41 with BgDataModel

use of com.android.launcher3.model.BgDataModel 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)

Example 42 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PackageInstallStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
        try {
            // For instant apps we do not get package-add. Use setting events to update
            // any pinned icons.
            ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
            if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
                app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
            }
        } catch (PackageManager.NameNotFoundException e) {
        // Ignore
        }
        // Ignore install success events as they are handled by Package add events.
        return;
    }
    synchronized (apps) {
        List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
            if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
                si.setProgressLevel(mInstallInfo);
                updates.add(si);
            }
        });
        for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
            if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
                widget.installProgress = mInstallInfo.progress;
                updates.add(widget);
            }
        }
        if (!updates.isEmpty()) {
            scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ItemInfo(com.android.launcher3.model.data.ItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo) HashSet(java.util.HashSet)

Example 43 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ProtonAOSP.

the class CacheDataUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    IconCache iconCache = app.getIconCache();
    ArrayList<WorkspaceItemInfo> updatedShortcuts = new ArrayList<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            ComponentName cn = si.getTargetComponent();
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && isValidShortcut(si) && cn != null && mPackages.contains(cn.getPackageName())) {
                iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                updatedShortcuts.add(si);
            }
        });
        apps.updateIconsAndLabels(mPackages, mUser);
    }
    bindUpdatedWorkspaceItems(updatedShortcuts);
    bindApplicationsIfNeeded();
}
Also used : IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 44 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_404Launcher by P-404.

the class PredictionUpdateTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    // TODO: remove this
    Utilities.getDevicePrefs(context).edit().putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply();
    FixedContainerItems fci = mPredictorState.items;
    Set<UserHandle> usersForChangedShortcuts = new HashSet<>(fci.items.stream().filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT).map(info -> info.user).collect(Collectors.toSet()));
    fci.items.clear();
    for (AppTarget target : mTargets) {
        WorkspaceItemInfo itemInfo;
        ShortcutInfo si = target.getShortcutInfo();
        if (si != null) {
            usersForChangedShortcuts.add(si.getUserHandle());
            itemInfo = new WorkspaceItemInfo(si, context);
            app.getIconCache().getShortcutIcon(itemInfo, si);
        } else {
            String className = target.getClassName();
            if (COMPONENT_CLASS_MARKER.equals(className)) {
                // TODO: Implement this
                continue;
            }
            ComponentName cn = new ComponentName(target.getPackageName(), className);
            UserHandle user = target.getUser();
            itemInfo = apps.data.stream().filter(info -> user.equals(info.user) && cn.equals(info.componentName)).map(ai -> {
                app.getIconCache().getTitleAndIcon(ai, false);
                return ai.makeWorkspaceItem();
            }).findAny().orElseGet(() -> {
                LauncherActivityInfo lai = context.getSystemService(LauncherApps.class).resolveActivity(AppInfo.makeLaunchIntent(cn), user);
                if (lai == null) {
                    return null;
                }
                AppInfo ai = new AppInfo(context, lai, user);
                app.getIconCache().getTitleAndIcon(ai, lai, false);
                return ai.makeWorkspaceItem();
            });
            if (itemInfo == null) {
                continue;
            }
        }
        itemInfo.container = fci.containerId;
        fci.items.add(itemInfo);
    }
    bindExtraContainerItems(fci);
    usersForChangedShortcuts.forEach(u -> dataModel.updateShortcutPinnedState(app.getContext(), u));
    // Save to disk
    mPredictorState.storage.write(context, fci.items);
}
Also used : Context(android.content.Context) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) AppInfo(com.android.launcher3.model.data.AppInfo) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) LauncherAppState(com.android.launcher3.LauncherAppState) Set(java.util.Set) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) LauncherApps(android.content.pm.LauncherApps) HashSet(java.util.HashSet) List(java.util.List) COMPONENT_CLASS_MARKER(com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) LAST_PREDICTION_ENABLED_STATE(com.android.launcher3.model.QuickstepModelDelegate.LAST_PREDICTION_ENABLED_STATE) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ShortcutInfo(android.content.pm.ShortcutInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppInfo(com.android.launcher3.model.data.AppInfo) AppTarget(android.app.prediction.AppTarget) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 45 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_404Launcher by P-404.

the class PackageIncrementalDownloadUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
    PackageInstallInfo downloadInfo = new PackageInstallInfo(mPackageName, PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING, mProgress, mUser);
    synchronized (appsList) {
        List<AppInfo> updatedAppInfos = appsList.updatePromiseInstallInfo(downloadInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                appInfo.runtimeStatusFlags &= ~ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE;
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    final ArrayList<WorkspaceItemInfo> updatedWorkspaceItems = new ArrayList<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (mPackageName.equals(si.getTargetPackage())) {
                si.runtimeStatusFlags &= ~ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE;
                si.setProgressLevel(downloadInfo);
                updatedWorkspaceItems.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItems);
}
Also used : PackageInstallInfo(com.android.launcher3.pm.PackageInstallInfo) ArrayList(java.util.ArrayList) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)66 ArrayList (java.util.ArrayList)63 ItemInfo (com.android.launcher3.model.data.ItemInfo)45 Context (android.content.Context)33 HashSet (java.util.HashSet)33 LauncherAppState (com.android.launcher3.LauncherAppState)28 AppInfo (com.android.launcher3.model.data.AppInfo)27 ComponentName (android.content.ComponentName)26 ShortcutInfo (android.content.pm.ShortcutInfo)26 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)23 BgDataModel (com.android.launcher3.model.BgDataModel)22 AppTarget (android.app.prediction.AppTarget)20 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)20 List (java.util.List)20 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)18 HashMap (java.util.HashMap)18 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)17 LauncherApps (android.content.pm.LauncherApps)17 AllAppsList (com.android.launcher3.model.AllAppsList)17 Set (java.util.Set)15