Search in sources :

Example 6 with LauncherAppsCompat

use of com.android.launcher3.compat.LauncherAppsCompat in project Neo-Launcher by NeoApplications.

the class TaskUtils method getTitle.

/**
 * TODO: remove this once we switch to getting the icon and label from IconCache.
 */
public static CharSequence getTitle(Context context, Task task) {
    LauncherAppsCompat launcherAppsCompat = LauncherAppsCompat.getInstance(context);
    PackageManager packageManager = context.getPackageManager();
    UserHandle user = UserHandle.of(task.key.userId);
    ApplicationInfo applicationInfo = launcherAppsCompat.getApplicationInfo(task.getTopComponent().getPackageName(), 0, user);
    if (applicationInfo == null) {
        Log.e(TAG, "Failed to get title for task " + task);
        return "";
    }
    return packageManager.getUserBadgedLabel(applicationInfo.loadLabel(packageManager), user);
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) PackageManager(android.content.pm.PackageManager) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 7 with LauncherAppsCompat

use of com.android.launcher3.compat.LauncherAppsCompat in project Neo-Launcher by NeoApplications.

the class AllAppsList method updatePackage.

/**
 * Add and remove icons for this package which has been updated.
 */
public void updatePackage(Context context, String packageName, UserHandle user) {
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    final List<LauncherActivityInfo> matches = launcherApps.getActivityList(packageName, user);
    if (matches.size() > 0) {
        // to the removed list.
        for (int i = data.size() - 1; i >= 0; i--) {
            final AppInfo applicationInfo = data.get(i);
            if (user.equals(applicationInfo.user) && packageName.equals(applicationInfo.componentName.getPackageName())) {
                if (!findActivity(matches, applicationInfo.componentName)) {
                    Log.w(TAG, "Changing shortcut target due to app component name change.");
                    removeApp(i);
                }
            }
        }
        // Also updates existing activities with new labels/icons
        for (final LauncherActivityInfo info : matches) {
            AppInfo applicationInfo = findAppInfo(info.getComponentName(), user);
            if (applicationInfo == null) {
                add(new AppInfo(context, info, user), info);
            } else {
                mIconCache.getTitleAndIcon(applicationInfo, info, true);
                applicationInfo.sectionName = mIndex.computeSectionName(applicationInfo.title);
                mDataChanged = true;
            }
        }
    } else {
        // Remove all data for this package.
        for (int i = data.size() - 1; i >= 0; i--) {
            final AppInfo applicationInfo = data.get(i);
            if (user.equals(applicationInfo.user) && packageName.equals(applicationInfo.componentName.getPackageName())) {
                mIconCache.remove(applicationInfo.componentName, user);
                removeApp(i);
            }
        }
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) AppInfo(com.android.launcher3.AppInfo) PromiseAppInfo(com.android.launcher3.PromiseAppInfo)

Example 8 with LauncherAppsCompat

use of com.android.launcher3.compat.LauncherAppsCompat in project Neo-Launcher by NeoApplications.

the class SdCardAvailableReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    final PackageManagerHelper pmHelper = new PackageManagerHelper(context);
    for (Entry<UserHandle, ArrayList<String>> entry : mPackages.entrySet()) {
        UserHandle user = entry.getKey();
        final ArrayList<String> packagesRemoved = new ArrayList<>();
        final ArrayList<String> packagesUnavailable = new ArrayList<>();
        for (String pkg : new HashSet<>(entry.getValue())) {
            if (!launcherApps.isPackageEnabledForProfile(pkg, user)) {
                if (pmHelper.isAppOnSdcard(pkg, user)) {
                    packagesUnavailable.add(pkg);
                } else {
                    packagesRemoved.add(pkg);
                }
            }
        }
        if (!packagesRemoved.isEmpty()) {
            mModel.onPackagesRemoved(user, packagesRemoved.toArray(new String[packagesRemoved.size()]));
        }
        if (!packagesUnavailable.isEmpty()) {
            mModel.onPackagesUnavailable(packagesUnavailable.toArray(new String[packagesUnavailable.size()]), user, false);
        }
    }
    // Unregister the broadcast receiver, just in case
    mContext.unregisterReceiver(this);
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) HashSet(java.util.HashSet)

Example 9 with LauncherAppsCompat

use of com.android.launcher3.compat.LauncherAppsCompat in project Neo-Launcher by NeoApplications.

the class InstallShortcutReceiver method flushQueueInBackground.

@WorkerThread
private static void flushQueueInBackground(Context context) {
    LauncherModel model = LauncherAppState.getInstance(context).getModel();
    if (model.getCallback() == null) {
        // Launcher not loaded
        return;
    }
    ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
    SharedPreferences prefs = Utilities.getPrefs(context);
    Set<String> strings = prefs.getStringSet(APPS_PENDING_INSTALL, null);
    if (DBG)
        Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
    if (strings == null) {
        return;
    }
    LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    for (String encoded : strings) {
        PendingInstallShortcutInfo info = decode(encoded, context);
        if (info == null) {
            continue;
        }
        String pkg = getIntentPackage(info.launchIntent);
        if (!TextUtils.isEmpty(pkg) && !launcherApps.isPackageEnabledForProfile(pkg, info.user) && !info.isActivity) {
            if (DBG) {
                Log.d(TAG, "Ignoring shortcut for absent package: " + info.launchIntent);
            }
            continue;
        }
        // Generate a shortcut info to add into the model
        installQueue.add(info.getItemInfo());
    }
    prefs.edit().remove(APPS_PENDING_INSTALL).apply();
    if (!installQueue.isEmpty()) {
        model.addAndBindAddedWorkspaceItems(installQueue);
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Pair(android.util.Pair) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

LauncherAppsCompat (com.android.launcher3.compat.LauncherAppsCompat)9 ArrayList (java.util.ArrayList)5 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)4 AppInfo (com.android.launcher3.AppInfo)4 UserHandle (android.os.UserHandle)3 ItemInfo (com.android.launcher3.ItemInfo)2 LauncherAppWidgetInfo (com.android.launcher3.LauncherAppWidgetInfo)2 PromiseAppInfo (com.android.launcher3.PromiseAppInfo)2 WorkspaceItemInfo (com.android.launcher3.WorkspaceItemInfo)2 IconCache (com.android.launcher3.icons.IconCache)2 HashSet (java.util.HashSet)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 SessionInfo (android.content.pm.PackageInstaller.SessionInfo)1 PackageManager (android.content.pm.PackageManager)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 Pair (android.util.Pair)1 WorkerThread (androidx.annotation.WorkerThread)1