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);
}
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);
}
}
}
}
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);
}
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);
}
}
Aggregations