Search in sources :

Example 31 with ComponentKey

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);
        }
    }
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey)

Example 32 with 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();
        }
    }
}
Also used : LongSparseArray(android.util.LongSparseArray) SQLException(android.database.SQLException) ComponentKey(com.android.launcher3.util.ComponentKey) Cursor(android.database.Cursor) Paint(android.graphics.Paint) UserHandle(android.os.UserHandle) HashSet(java.util.HashSet)

Example 33 with ComponentKey

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;
}
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 34 with ComponentKey

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);
    }
}
Also used : UserHandle(android.os.UserHandle) ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName) SpannableString(android.text.SpannableString) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 35 with ComponentKey

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;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) ArrayList(java.util.ArrayList) AppInfo(com.android.launcher3.AppInfo)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)98 ComponentName (android.content.ComponentName)40 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 ArrayList (java.util.ArrayList)26 ShortcutInfo (android.content.pm.ShortcutInfo)21 UserHandle (android.os.UserHandle)20 HashMap (java.util.HashMap)19 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)17 PackageUserKey (com.android.launcher3.util.PackageUserKey)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)16 Context (android.content.Context)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 List (java.util.List)13 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)11 AppTarget (android.app.prediction.AppTarget)10 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)10 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)10 QueryResult (com.android.launcher3.shortcuts.ShortcutRequest.QueryResult)10