Search in sources :

Example 36 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project Neo-Launcher by NeoApplications.

the class Utilities method getFullDrawable.

/**
 * Returns the full drawable for {@param info}.
 * @param outObj this is set to the internal data associated with {@param info},
 *               eg {@link LauncherActivityInfo} or {@link ShortcutInfo}.
 */
public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, boolean flattenDrawable, Object[] outObj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    IconPackManager.CustomIconEntry customIconEntry = (info instanceof WorkspaceItemInfo) ? ((WorkspaceItemInfo) info).customIconEntry : null;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || customIconEntry != null) {
        LauncherActivityInfo activityInfo = LauncherAppsCompat.getInstance(launcher).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return (activityInfo != null) ? appState.getIconCache().getFullResIcon(activityInfo, flattenDrawable) : null;
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        ShortcutKey key = ShortcutKey.fromItemInfo(info);
        DeepShortcutManager sm = DeepShortcutManager.getInstance(launcher);
        List<ShortcutInfo> si = sm.queryForFullDetails(key.componentName.getPackageName(), Arrays.asList(key.getId()), key.user);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return sm.getShortcutIconDrawable(si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else {
        return null;
    }
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) IconPackManager(com.saggitt.omega.iconpack.IconPackManager) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) List(java.util.List) ArrayList(java.util.ArrayList) Point(android.graphics.Point) DeepShortcutManager(com.android.launcher3.shortcuts.DeepShortcutManager) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey)

Example 37 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project Neo-Launcher by NeoApplications.

the class LauncherAppsCompatVO method getCustomShortcutActivityList.

@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(@Nullable PackageUserKey packageUser) {
    List<ShortcutConfigActivityInfo> result = new ArrayList<>();
    UserHandle myUser = Process.myUserHandle();
    final List<UserHandle> users;
    final String packageName;
    if (packageUser == null) {
        users = UserManagerCompat.getInstance(mContext).getUserProfiles();
        packageName = null;
    } else {
        users = new ArrayList<>(1);
        users.add(packageUser.mUser);
        packageName = packageUser.mPackageName;
    }
    for (UserHandle user : users) {
        boolean ignoreTargetSdk = myUser.equals(user);
        List<LauncherActivityInfo> activities = mLauncherApps.getShortcutConfigActivityList(packageName, user);
        for (LauncherActivityInfo activityInfo : activities) {
            if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) {
                result.add(new ShortcutConfigActivityInfoVO(activityInfo));
            }
        }
    }
    return result;
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ShortcutConfigActivityInfoVO(com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO)

Example 38 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project Neo-Launcher by NeoApplications.

the class AllAppsList method addPackage.

/**
 * Add the icons for the supplied apk called packageName.
 */
public void addPackage(Context context, String packageName, UserHandle user) {
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    final List<LauncherActivityInfo> matches = launcherApps.getActivityList(packageName, user);
    for (LauncherActivityInfo info : matches) {
        add(new AppInfo(context, info, user), info);
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) AppInfo(com.android.launcher3.AppInfo) PromiseAppInfo(com.android.launcher3.PromiseAppInfo)

Example 39 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project Neo-Launcher by NeoApplications.

the class AddWorkspaceItemsTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    if (mItemList.isEmpty()) {
        return;
    }
    final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
    final IntArray addedWorkspaceScreensFinal = new IntArray();
    synchronized (dataModel) {
        IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
        List<ItemInfo> filteredItems = new ArrayList<>();
        for (Pair<ItemInfo, Object> entry : mItemList) {
            ItemInfo item = entry.first;
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                // Short-circuit this logic if the icon exists somewhere on the workspace
                if (shortcutExists(dataModel, item.getIntent(), item.user)) {
                    continue;
                }
                // b/139663018 Short-circuit this logic if the icon is a system app
                if (PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
                    continue;
                }
            }
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
                if (item instanceof AppInfo) {
                    item = ((AppInfo) item).makeWorkspaceItem();
                }
            }
            if (item != null) {
                filteredItems.add(item);
            }
        }
        PackageInstallerCompat packageInstaller = PackageInstallerCompat.getInstance(app.getContext());
        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(app.getContext());
        for (ItemInfo item : filteredItems) {
            // Find appropriate space for the item.
            int[] coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
            int screenId = coords[0];
            ItemInfo itemInfo;
            if (item instanceof WorkspaceItemInfo || item instanceof FolderInfo || item instanceof LauncherAppWidgetInfo) {
                itemInfo = item;
            } else if (item instanceof AppInfo) {
                itemInfo = ((AppInfo) item).makeWorkspaceItem();
            } else {
                throw new RuntimeException("Unexpected info type");
            }
            if (item instanceof WorkspaceItemInfo && ((WorkspaceItemInfo) item).isPromise()) {
                WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) item;
                String packageName = item.getTargetComponent() != null ? item.getTargetComponent().getPackageName() : null;
                if (packageName == null) {
                    continue;
                }
                SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user, packageName);
                List<LauncherActivityInfo> activities = launcherApps.getActivityList(packageName, item.user);
                boolean hasActivity = activities != null && !activities.isEmpty();
                if (sessionInfo == null) {
                    if (!hasActivity) {
                        // Session was cancelled, do not add.
                        continue;
                    }
                } else {
                    workspaceInfo.setInstallProgress((int) sessionInfo.getProgress());
                }
                if (hasActivity) {
                    // App was installed while launcher was in the background,
                    // or app was already installed for another user.
                    itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user).makeWorkspaceItem();
                    if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
                        // Icon already exists on the workspace and should not be auto-added.
                        continue;
                    }
                    WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
                    wii.title = "";
                    wii.applyFrom(app.getIconCache().getDefaultIcon(item.user));
                    app.getIconCache().getTitleAndIcon(wii, ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
                }
            }
            // Add the shortcut to the db
            getModelWriter().addItemToDatabase(itemInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coords[1], coords[2]);
            // Save the WorkspaceItemInfo for binding in the workspace
            addedItemsFinal.add(itemInfo);
        }
    }
    if (!addedItemsFinal.isEmpty()) {
        scheduleCallbackTask(new CallbackTask() {

            @Override
            public void execute(Callbacks callbacks) {
                final ArrayList<ItemInfo> addAnimated = new ArrayList<>();
                final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
                if (!addedItemsFinal.isEmpty()) {
                    ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
                    int lastScreenId = info.screenId;
                    for (ItemInfo i : addedItemsFinal) {
                        if (i.screenId == lastScreenId) {
                            addAnimated.add(i);
                        } else {
                            addNotAnimated.add(i);
                        }
                    }
                }
                callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated);
            }
        });
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) IntArray(com.android.launcher3.util.IntArray) Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) PackageInstallerCompat(com.android.launcher3.compat.PackageInstallerCompat) CallbackTask(com.android.launcher3.LauncherModel.CallbackTask) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) FolderInfo(com.android.launcher3.FolderInfo) AppInfo(com.android.launcher3.AppInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 40 with LauncherActivityInfo

use of android.content.pm.LauncherActivityInfo in project Neo-Launcher by NeoApplications.

the class LoaderTask method loadAllApps.

private List<LauncherActivityInfo> loadAllApps() {
    final List<UserHandle> profiles = mUserManager.getUserProfiles();
    List<LauncherActivityInfo> allActivityList = new ArrayList<>();
    // Clear the list of apps
    mBgAllAppsList.clear();
    for (UserHandle user : profiles) {
        // Query for the set of apps
        final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
        // TODO: Fix this. Only fail for the current user.
        if (apps == null || apps.isEmpty()) {
            return allActivityList;
        }
        boolean quietMode = mUserManager.isQuietModeEnabled(user);
        // Create the ApplicationInfos
        for (int i = 0; i < apps.size(); i++) {
            LauncherActivityInfo app = apps.get(i);
            // This builds the icon bitmaps.
            mBgAllAppsList.add(new AppInfo(app, user, quietMode), app);
        }
        allActivityList.addAll(apps);
    }
    if (FeatureFlags.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) {
        // get all active sessions and add them to the all apps list
        for (PackageInstaller.SessionInfo info : mPackageInstaller.getAllVerifiedSessions()) {
            mBgAllAppsList.addPromiseApp(mApp.getContext(), PackageInstallerCompat.PackageInstallInfo.fromInstallingState(info));
        }
    }
    mBgAllAppsList.getAndResetChangeFlag();
    return allActivityList;
}
Also used : SessionInfo(android.content.pm.PackageInstaller.SessionInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ArrayList(java.util.ArrayList) PackageInstaller(android.content.pm.PackageInstaller) AppInfo(com.android.launcher3.AppInfo)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)134 LauncherApps (android.content.pm.LauncherApps)70 ArrayList (java.util.ArrayList)57 UserHandle (android.os.UserHandle)50 Intent (android.content.Intent)36 ComponentName (android.content.ComponentName)31 List (java.util.List)30 AppInfo (com.android.launcher3.model.data.AppInfo)28 ShortcutInfo (android.content.pm.ShortcutInfo)27 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 Context (android.content.Context)23 Point (android.graphics.Point)22 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)19 SuppressLint (android.annotation.SuppressLint)16 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)16 PackageUserKey (com.android.launcher3.util.PackageUserKey)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)13 IconRequestInfo (com.android.launcher3.model.data.IconRequestInfo)12 CancellationException (java.util.concurrent.CancellationException)12 PackageInstaller (android.content.pm.PackageInstaller)11