Search in sources :

Example 66 with BgDataModel

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

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 67 with BgDataModel

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

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, R.style.AppTheme);
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, LauncherSettings.Favorites.SCREEN + " = 0 or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 68 with BgDataModel

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

the class AddWorkspaceItemsTask method shortcutExists.

/**
 * Returns true if the shortcuts already exists on the workspace. This must be called after
 * the workspace has been loaded. We identify a shortcut by its intent.
 */
protected boolean shortcutExists(BgDataModel dataModel, Intent intent, UserHandle user) {
    final String compPkgName, intentWithPkg, intentWithoutPkg;
    if (intent == null) {
        // Skip items with null intents
        return true;
    }
    if (intent.getComponent() != null) {
        // If component is not null, an intent with null package will produce
        // the same result and should also be a match.
        compPkgName = intent.getComponent().getPackageName();
        if (intent.getPackage() != null) {
            intentWithPkg = intent.toUri(0);
            intentWithoutPkg = new Intent(intent).setPackage(null).toUri(0);
        } else {
            intentWithPkg = new Intent(intent).setPackage(compPkgName).toUri(0);
            intentWithoutPkg = intent.toUri(0);
        }
    } else {
        compPkgName = null;
        intentWithPkg = intent.toUri(0);
        intentWithoutPkg = intent.toUri(0);
    }
    boolean isLauncherAppTarget = PackageManagerHelper.isLauncherAppTarget(intent);
    synchronized (dataModel) {
        for (ItemInfo item : dataModel.itemsIdMap) {
            if (item instanceof WorkspaceItemInfo) {
                WorkspaceItemInfo info = (WorkspaceItemInfo) item;
                if (item.getIntent() != null && info.user.equals(user)) {
                    Intent copyIntent = new Intent(item.getIntent());
                    copyIntent.setSourceBounds(intent.getSourceBounds());
                    String s = copyIntent.toUri(0);
                    if (intentWithPkg.equals(s) || intentWithoutPkg.equals(s)) {
                        return true;
                    }
                    // checking for existing promise icon with same package name
                    if (isLauncherAppTarget && info.isPromise() && info.hasStatusFlag(WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON) && info.getTargetComponent() != null && compPkgName != null && compPkgName.equals(info.getTargetComponent().getPackageName())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 69 with BgDataModel

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

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 70 with BgDataModel

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

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