Search in sources :

Example 11 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by AOSPA.

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 12 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by AOSPA.

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[] coordinates = new int[2];
    boolean found = false;
    int screenCount = workspaceScreens.size();
    // First check the preferred screen.
    IntSet screensToExclude = new IntSet();
    if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
        screensToExclude.add(FIRST_SCREEN_ID);
    }
    for (int screen = 0; screen < screenCount; screen++) {
        screenId = workspaceScreens.get(screen);
        if (!screensToExclude.contains(screenId) && findNextAvailableIconSpaceInScreen(app, screenItems.get(screenId), coordinates, 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), coordinates, spanX, spanY)) {
            throw new RuntimeException("Can't find space to add the item");
        }
    }
    return new int[] { screenId, coordinates[0], coordinates[1] };
}
Also used : LongSparseArray(android.util.LongSparseArray) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) IntSet(com.android.launcher3.util.IntSet) ArrayList(java.util.ArrayList)

Example 13 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by AOSPA.

the class AddWorkspaceItemsTask method findNextAvailableIconSpaceInScreen.

private boolean findNextAvailableIconSpaceInScreen(LauncherAppState app, ArrayList<ItemInfo> occupiedPos, int[] xy, int spanX, int spanY) {
    InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
    GridOccupancy occupied = new GridOccupancy(profile.numColumns, profile.numRows);
    if (occupiedPos != null) {
        for (ItemInfo r : occupiedPos) {
            occupied.markCells(r, true);
        }
    }
    return occupied.findVacantCell(xy, spanX, spanY);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) GridOccupancy(com.android.launcher3.util.GridOccupancy)

Example 14 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Launcher3 by AOSPA.

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 15 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_Trebuchet by LineageOS.

the class Utilities method getBadge.

/**
 * For apps icons and shortcut icons that have badges, this method creates a drawable that can
 * later on be rendered on top of the layers for the badges. For app icons, work profile badges
 * can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
 * badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
 */
@TargetApi(Build.VERSION_CODES.O)
public static Drawable getBadge(Launcher launcher, ItemInfo info, Object obj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
        if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) {
            // The item is not yet added on home screen.
            return new FixedSizeEmptyDrawable(iconSize);
        }
        ShortcutInfo si = (ShortcutInfo) obj;
        Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
        float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
        float insetFraction = (iconSize - badgeSize) / iconSize;
        return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return ((FolderAdaptiveIcon) obj).getBadge();
    } else {
        return launcher.getPackageManager().getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
    }
}
Also used : Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) InsetDrawable(android.graphics.drawable.InsetDrawable) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Aggregations

ArrayList (java.util.ArrayList)62 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)56 Context (android.content.Context)39 LauncherAppState (com.android.launcher3.LauncherAppState)38 HashSet (java.util.HashSet)37 ShortcutInfo (android.content.pm.ShortcutInfo)33 List (java.util.List)33 ComponentName (android.content.ComponentName)32 ItemInfo (com.android.launcher3.model.data.ItemInfo)30 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)24 Point (android.graphics.Point)24 LauncherApps (android.content.pm.LauncherApps)23 IconCache (com.android.launcher3.icons.IconCache)23 LauncherIcons (com.android.launcher3.icons.LauncherIcons)23 AppInfo (com.android.launcher3.model.data.AppInfo)22 PackageManager (android.content.pm.PackageManager)20 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)20 HashMap (java.util.HashMap)20 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)19 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)19