Search in sources :

Example 81 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Trebuchet by LineageOS.

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) {
        for (ItemInfo info : dataModel.itemsIdMap) {
            if (info instanceof WorkspaceItemInfo && mUser.equals(info.user)) {
                WorkspaceItemInfo si = (WorkspaceItemInfo) info;
                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 : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 82 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Trebuchet by LineageOS.

the class AddWorkspaceItemsTask method findSpaceForItem.

/**
 * Find a position on the screen for the given size or adds a new screen.
 * @return screenId and the coordinates for the item in an int array of size 3.
 */
protected int[] findSpaceForItem(LauncherAppState app, BgDataModel dataModel, IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
    LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
    // Use sBgItemsIdMap as all the items are already loaded.
    synchronized (dataModel) {
        for (ItemInfo info : dataModel.itemsIdMap) {
            if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                ArrayList<ItemInfo> items = screenItems.get(info.screenId);
                if (items == null) {
                    items = new ArrayList<>();
                    screenItems.put(info.screenId, items);
                }
                items.add(info);
            }
        }
    }
    // Find appropriate space for the item.
    int screenId = 0;
    int[] cordinates = new int[2];
    boolean found = false;
    int screenCount = workspaceScreens.size();
    // First check the preferred screen.
    int preferredScreenIndex = workspaceScreens.isEmpty() ? 0 : 1;
    if (preferredScreenIndex < screenCount) {
        screenId = workspaceScreens.get(preferredScreenIndex);
        found = findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), cordinates, spanX, spanY);
    }
    if (!found) {
        // Search on any of the screens starting from the first screen.
        for (int screen = 1; screen < screenCount; screen++) {
            screenId = workspaceScreens.get(screen);
            if (findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), cordinates, spanX, spanY)) {
                // We found a space for it
                found = true;
                break;
            }
        }
    }
    if (!found) {
        // Still no position found. Add a new screen to the end.
        screenId = LauncherSettings.Settings.call(app.getContext().getContentResolver(), LauncherSettings.Settings.METHOD_NEW_SCREEN_ID).getInt(LauncherSettings.Settings.EXTRA_VALUE);
        // Save the screen id for binding in the workspace
        workspaceScreens.add(screenId);
        addedWorkspaceScreensFinal.add(screenId);
        // If we still can't find an empty space, then God help us all!!!
        if (!findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), cordinates, spanX, spanY)) {
            throw new RuntimeException("Can't find space to add the item");
        }
    }
    return new int[] { screenId, cordinates[0], cordinates[1] };
}
Also used : LongSparseArray(android.util.LongSparseArray) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList)

Example 83 with BgDataModel

use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Trebuchet by LineageOS.

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

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

the class SearchActionItemInfo method createWorkspaceItem.

/**
 * Creates a {@link WorkspaceItemInfo} coorsponding to search action to be stored in launcher db
 */
public WorkspaceItemInfo createWorkspaceItem(LauncherModel model) {
    WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.title = title;
    info.bitmap = bitmap;
    info.intent = mIntent;
    if (hasFlags(FLAG_SHOULD_START_FOR_RESULT)) {
        info.options |= WorkspaceItemInfo.FLAG_START_FOR_RESULT;
    }
    model.enqueueModelUpdateTask(new BaseModelUpdateTask() {

        @Override
        public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
            model.updateAndBindWorkspaceItem(() -> {
                PackageItemInfo pkgInfo = new PackageItemInfo(getIntentPackageName(), user);
                app.getIconCache().getTitleAndIconForApp(pkgInfo, false);
                try (LauncherIcons li = LauncherIcons.obtain(app.getContext())) {
                    info.bitmap = li.badgeBitmap(info.bitmap.icon, pkgInfo.bitmap);
                }
                return info;
            });
        }
    });
    return info;
}
Also used : BaseModelUpdateTask(com.android.launcher3.model.BaseModelUpdateTask) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 85 with BgDataModel

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

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