Search in sources :

Example 36 with BgDataModel

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

the class HotseatPredictionModel method convertDataModelToAppTargetBundle.

/**
 * Creates and returns bundle using workspace items
 */
public static Bundle convertDataModelToAppTargetBundle(Context context, BgDataModel dataModel) {
    Bundle bundle = new Bundle();
    ArrayList<AppTargetEvent> events = new ArrayList<>();
    ArrayList<ItemInfo> workspaceItems = dataModel.getAllWorkspaceItems();
    for (ItemInfo item : workspaceItems) {
        AppTarget target = getAppTargetFromItemInfo(context, item);
        if (target != null && !isTrackedForHotseatPrediction(item))
            continue;
        events.add(wrapAppTargetWithItemLocation(target, AppTargetEvent.ACTION_PIN, item));
    }
    ArrayList<AppTarget> currentTargets = new ArrayList<>();
    FixedContainerItems hotseatItems = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
    if (hotseatItems != null) {
        for (ItemInfo itemInfo : hotseatItems.items) {
            AppTarget target = getAppTargetFromItemInfo(context, itemInfo);
            if (target != null)
                currentTargets.add(target);
        }
    }
    bundle.putParcelableArrayList(BUNDLE_KEY_PIN_EVENTS, events);
    bundle.putParcelableArrayList(BUNDLE_KEY_CURRENT_ITEMS, currentTargets);
    return bundle;
}
Also used : AppTarget(android.app.prediction.AppTarget) PredictionHelper.getAppTargetFromItemInfo(com.android.launcher3.model.PredictionHelper.getAppTargetFromItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTargetEvent(android.app.prediction.AppTargetEvent)

Example 37 with BgDataModel

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

the class QuickstepModelDelegate method getBundleForWidgetsOnWorkspace.

private Bundle getBundleForWidgetsOnWorkspace(Context context, BgDataModel dataModel) {
    Bundle bundle = new Bundle();
    ArrayList<AppTargetEvent> widgetEvents = dataModel.getAllWorkspaceItems().stream().filter(PredictionHelper::isTrackedForWidgetPrediction).map(item -> {
        AppTarget target = getAppTargetFromItemInfo(context, item);
        if (target == null)
            return null;
        return wrapAppTargetWithItemLocation(target, AppTargetEvent.ACTION_PIN, item);
    }).filter(Objects::nonNull).collect(toCollection(ArrayList::new));
    bundle.putParcelableArrayList(BUNDLE_KEY_ADDED_APP_WIDGETS, widgetEvents);
    return bundle;
}
Also used : AppTarget(android.app.prediction.AppTarget) Bundle(android.os.Bundle) HotseatPredictionModel.convertDataModelToAppTargetBundle(com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle) AppTargetEvent(android.app.prediction.AppTargetEvent)

Example 38 with BgDataModel

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

the class ShortcutsChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    final Context context = app.getContext();
    // Find WorkspaceItemInfo's that have changed on the workspace.
    ArrayList<WorkspaceItemInfo> matchingWorkspaceItems = new ArrayList<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if ((si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) && mPackageName.equals(si.getIntent().getPackage())) {
                matchingWorkspaceItems.add(si);
            }
        });
    }
    if (!matchingWorkspaceItems.isEmpty()) {
        if (mShortcuts.isEmpty()) {
            // Verify that the app is indeed installed.
            if (!new PackageManagerHelper(app.getContext()).isAppInstalled(mPackageName, mUser)) {
                // App is not installed, ignoring package events
                return;
            }
        }
        // Update the workspace to reflect the changes to updated shortcuts residing on it.
        List<String> allLauncherKnownIds = matchingWorkspaceItems.stream().map(WorkspaceItemInfo::getDeepShortcutId).distinct().collect(Collectors.toList());
        List<ShortcutInfo> shortcuts = new ShortcutRequest(context, mUser).forPackage(mPackageName, allLauncherKnownIds).query(ShortcutRequest.ALL);
        Set<String> nonPinnedIds = new HashSet<>(allLauncherKnownIds);
        ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
        for (ShortcutInfo fullDetails : shortcuts) {
            if (!fullDetails.isPinned()) {
                continue;
            }
            String sid = fullDetails.getId();
            nonPinnedIds.remove(sid);
            matchingWorkspaceItems.stream().filter(itemInfo -> sid.equals(itemInfo.getDeepShortcutId())).forEach(workspaceItemInfo -> {
                workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context);
                app.getIconCache().getShortcutIcon(workspaceItemInfo, fullDetails);
                updatedWorkspaceItemInfos.add(workspaceItemInfo);
            });
        }
        bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
        if (!nonPinnedIds.isEmpty()) {
            deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(nonPinnedIds.stream().map(id -> new ShortcutKey(mPackageName, mUser, id)).collect(Collectors.toSet())));
        }
    }
    if (mUpdateIdMap) {
        // Update the deep shortcut map if the list of ids has changed for an activity.
        dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts);
        bindDeepShortcuts(dataModel);
    }
}
Also used : Context(android.content.Context) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) LauncherAppState(com.android.launcher3.LauncherAppState) Set(java.util.Set) LauncherSettings(com.android.launcher3.LauncherSettings) Collectors(java.util.stream.Collectors) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 39 with BgDataModel

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

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (mIsUserUnlocked) {
        QueryResult shortcuts = new ShortcutRequest(context, mUser).query(ShortcutRequest.PINNED);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            mIsUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                if (mIsUserUnlocked) {
                    ShortcutKey key = ShortcutKey.fromItemInfo(si);
                    ShortcutInfo shortcut = pinnedShortcuts.get(key);
                    // (probably due to clear data), delete the workspace item as well
                    if (shortcut == null) {
                        removedKeys.add(key);
                        return;
                    }
                    si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                    si.updateFromDeepShortcutInfo(shortcut, context);
                    app.getIconCache().getShortcutIcon(si, shortcut);
                } else {
                    si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
                }
                updatedWorkspaceItemInfos.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (mIsUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) QueryResult(com.android.launcher3.shortcuts.ShortcutRequest.QueryResult) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 40 with BgDataModel

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

the class AddWorkspaceItemsTaskTest method writeWorkspaceWithHoles.

private int writeWorkspaceWithHoles(BgDataModel bgDataModel, int startId, int screenId, Rect... holes) {
    GridOccupancy occupancy = new GridOccupancy(mIdp.numColumns, mIdp.numRows);
    occupancy.markCells(0, 0, mIdp.numColumns, mIdp.numRows, true);
    for (Rect r : holes) {
        occupancy.markCells(r, false);
    }
    mExistingScreens.add(screenId);
    mScreenOccupancy.append(screenId, occupancy);
    for (int x = 0; x < mIdp.numColumns; x++) {
        for (int y = 0; y < mIdp.numRows; y++) {
            if (!occupancy.cells[x][y]) {
                continue;
            }
            WorkspaceItemInfo info = new WorkspaceItemInfo();
            info.intent = new Intent().setComponent(mComponent1);
            info.id = startId++;
            info.screenId = screenId;
            info.cellX = x;
            info.cellY = y;
            info.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
            bgDataModel.addItem(mTargetContext, info, false);
            ContentWriter writer = new ContentWriter(mTargetContext);
            info.writeToValues(writer);
            writer.put(Favorites._ID, info.id);
            mTargetContext.getContentResolver().insert(Favorites.CONTENT_URI, writer.getValues(mTargetContext));
        }
    }
    return startId;
}
Also used : Rect(android.graphics.Rect) ContentWriter(com.android.launcher3.util.ContentWriter) Intent(android.content.Intent) GridOccupancy(com.android.launcher3.util.GridOccupancy) 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