Search in sources :

Example 41 with LauncherActivityInfo

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

the class AlphabeticalAppsList method getFiltersAppInfos.

private List<AppInfo> getFiltersAppInfos() {
    if (mSearchResults == null) {
        return mApps;
    }
    LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(mLauncher);
    UserHandle user = Process.myUserHandle();
    IconCache iconCache = LauncherAppState.getInstance(mLauncher).getIconCache();
    boolean quietMode = UserManagerCompat.getInstance(mLauncher).isQuietModeEnabled(user);
    ArrayList<AppInfo> result = new ArrayList<>();
    for (ComponentKey key : mSearchResults) {
        AppInfo match = mAllAppsStore.getApp(key);
        if (match != null) {
            result.add(match);
        } else {
            for (LauncherActivityInfo info : launcherApps.getActivityList(key.componentName.getPackageName(), user)) {
                if (info.getComponentName().equals(key.componentName)) {
                    AppInfo appInfo = new AppInfo(info, user, quietMode);
                    iconCache.getTitleAndIcon(appInfo, false);
                    result.add(appInfo);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) AppInfo(com.android.launcher3.AppInfo)

Example 42 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 43 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 44 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 45 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)

Aggregations

LauncherActivityInfo (android.content.pm.LauncherActivityInfo)122 LauncherApps (android.content.pm.LauncherApps)62 ArrayList (java.util.ArrayList)51 UserHandle (android.os.UserHandle)44 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)27 List (java.util.List)26 AppInfo (com.android.launcher3.model.data.AppInfo)23 ShortcutInfo (android.content.pm.ShortcutInfo)22 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)21 Context (android.content.Context)19 Point (android.graphics.Point)19 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)16 SuppressLint (android.annotation.SuppressLint)14 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)13 PackageManager (android.content.pm.PackageManager)12 PackageUserKey (com.android.launcher3.util.PackageUserKey)11 UserManager (android.os.UserManager)10 CancellationException (java.util.concurrent.CancellationException)10 PackageInstaller (android.content.pm.PackageInstaller)9