use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.
the class RecentsView method removeTask.
private void removeTask(Task task, int index, PendingAnimation.OnEndListener onEndListener, boolean shouldLog) {
if (task != null) {
ActivityManagerWrapper.getInstance().removeTask(task.key.id);
if (shouldLog) {
ComponentKey componentKey = TaskUtils.getLaunchComponentKeyForTask(task.key);
mActivity.getUserEventDispatcher().logTaskLaunchOrDismiss(onEndListener.logAction, Direction.UP, index, componentKey);
mActivity.getStatsLogManager().logTaskDismiss(this, componentKey);
}
}
}
use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.
the class WidgetPreviewLoader method removeObsoletePreviews.
/**
* Updates the persistent DB:
* 1. Any preview generated for an old package version is removed
* 2. Any preview for an absent package is removed
* This ensures that we remove entries for packages which changed while the launcher was dead.
*
* @param packageUser if provided, specifies that list only contains previews for the
* given package/user, otherwise the list contains all previews
*/
public void removeObsoletePreviews(ArrayList<? extends ComponentKey> list, @Nullable PackageUserKey packageUser) {
Preconditions.assertWorkerThread();
LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
for (ComponentKey key : list) {
final long userId = mUserManager.getSerialNumberForUser(key.user);
HashSet<String> packages = validPackages.get(userId);
if (packages == null) {
packages = new HashSet<>();
validPackages.put(userId, packages);
}
packages.add(key.componentName.getPackageName());
}
LongSparseArray<HashSet<String>> packagesToDelete = new LongSparseArray<>();
long passedUserId = packageUser == null ? 0 : mUserManager.getSerialNumberForUser(packageUser.mUser);
Cursor c = null;
try {
c = mDb.query(new String[] { CacheDb.COLUMN_USER, CacheDb.COLUMN_PACKAGE, CacheDb.COLUMN_LAST_UPDATED, CacheDb.COLUMN_VERSION }, null, null);
while (c.moveToNext()) {
long userId = c.getLong(0);
String pkg = c.getString(1);
long lastUpdated = c.getLong(2);
long version = c.getLong(3);
if (packageUser != null && (!pkg.equals(packageUser.mPackageName) || userId != passedUserId)) {
// This preview is associated with a different package/user, no need to remove.
continue;
}
HashSet<String> packages = validPackages.get(userId);
if (packages != null && packages.contains(pkg)) {
long[] versions = getPackageVersion(pkg);
if (versions[0] == version && versions[1] == lastUpdated) {
// Every thing checks out
continue;
}
}
// We need to delete this package.
packages = packagesToDelete.get(userId);
if (packages == null) {
packages = new HashSet<>();
packagesToDelete.put(userId, packages);
}
packages.add(pkg);
}
for (int i = 0; i < packagesToDelete.size(); i++) {
long userId = packagesToDelete.keyAt(i);
UserHandle user = mUserManager.getUserForSerialNumber(userId);
for (String pkg : packagesToDelete.valueAt(i)) {
removePackage(pkg, user, userId);
}
}
} catch (SQLException e) {
Log.e(TAG, "Error updating widget previews", e);
} finally {
if (c != null) {
c.close();
}
}
}
use of com.android.launcher3.util.ComponentKey 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;
}
use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.
the class Utilities method makeComponentKey.
/**
* Creates a new component key from an encoded component key string in the form of
* [flattenedComponentString#userId]. If the userId is not present, then it defaults
* to the current user.
*/
public static ComponentKey makeComponentKey(Context context, String componentKeyStr) {
ComponentName componentName;
UserHandle user;
int userDelimiterIndex = componentKeyStr.indexOf("#");
if (userDelimiterIndex != -1) {
String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
long componentUser = Long.parseLong(componentKeyStr.substring(userDelimiterIndex + 12, componentKeyStr.length() - 1));
componentName = ComponentName.unflattenFromString(componentStr);
user = Utilities.notNullOrDefault(UserManagerCompat.getInstance(context).getUserForSerialNumber(componentUser), Process.myUserHandle());
} else {
// No user provided, default to the current user
componentName = ComponentName.unflattenFromString(componentKeyStr);
user = Process.myUserHandle();
}
try {
return new ComponentKey(componentName, user);
} catch (NullPointerException e) {
throw new NullPointerException("Trying to create invalid component key: " + componentKeyStr);
}
}
use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.
the class DefaultAppSearchAlgorithm method getTitleMatchResult.
private ArrayList<ComponentKey> getTitleMatchResult(String query) {
// Do an intersection of the words in the query and each title, and filter out all the
// apps that don't match all of the words in the query.
final String queryTextLower = query.toLowerCase();
final ArrayList<ComponentKey> result = new ArrayList<>();
StringMatcher matcher = StringMatcher.getInstance();
for (AppInfo info : getApps(mContext, mApps, mBaseFilter)) {
if (matches(info, queryTextLower, matcher)) {
result.add(info.toComponentKey());
}
}
return result;
}
Aggregations