Search in sources :

Example 81 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class PredictionUiStateManager method parseLastState.

private PredictionState parseLastState() {
    PredictionState state = new PredictionState();
    state.isEnabled = mGettingValidPredictionResults;
    if (!state.isEnabled) {
        state.apps = Collections.EMPTY_LIST;
        return state;
    }
    state.apps = new ArrayList<>();
    List<AppTargetCompat> appTargets = mPredictionServicePredictions[mActiveClient.ordinal()];
    if (!appTargets.isEmpty()) {
        for (AppTargetCompat appTarget : appTargets) {
            ComponentKey key;
            if (appTarget.getShortcutInfo() != null) {
                key = ShortcutKey.fromInfo(appTarget.getShortcutInfo());
            } else {
                key = new ComponentKey(new ComponentName(appTarget.getPackageName(), appTarget.getClassName()), appTarget.getUser());
            }
            state.apps.add(new ComponentKeyMapper(mContext, key, mDynamicItemCache));
        }
    }
    updateDependencies(state);
    return state;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) AppTargetCompat(com.saggitt.omega.predictions.AppTargetCompat) ComponentName(android.content.ComponentName)

Example 82 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class BaseIconCache method cacheLocked.

protected <T> CacheEntry cacheLocked(@NonNull ComponentName componentName, @NonNull UserHandle user, @NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic, boolean usePackageIcon, boolean useLowResIcon, boolean addToMemCache) {
    ComponentKey cacheKey = new ComponentKey(componentName, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
        entry = new CacheEntry();
        if (addToMemCache) {
            mCache.put(cacheKey, entry);
        }
        // Check the DB first.
        T object = null;
        boolean providerFetchedOnce = false;
        if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
            object = infoProvider.get();
            providerFetchedOnce = true;
            if (object != null) {
                cachingLogic.loadIcon(mContext, object, entry);
            } else {
                if (usePackageIcon) {
                    CacheEntry packageEntry = getEntryForPackageLocked(componentName.getPackageName(), user, false);
                    if (packageEntry != null) {
                        if (DEBUG)
                            Log.d(TAG, "using package default icon for " + componentName.toShortString());
                        packageEntry.applyTo(entry);
                        entry.title = packageEntry.title;
                        entry.contentDescription = packageEntry.contentDescription;
                    }
                }
                if (entry.icon == null) {
                    if (DEBUG)
                        Log.d(TAG, "using default icon for " + componentName.toShortString());
                    getDefaultIcon(user).applyTo(entry);
                }
            }
        }
        if (TextUtils.isEmpty(entry.title)) {
            if (object == null && !providerFetchedOnce) {
                object = infoProvider.get();
                providerFetchedOnce = true;
            }
            if (object != null) {
                entry.title = cachingLogic.getLabel(object);
                entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
            }
        }
    }
    return entry;
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey)

Example 83 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class BaseIconCache method cachePackageInstallInfo.

/**
 * Adds a default package entry in the cache. This entry is not persisted and will be removed
 * when the cache is flushed.
 */
public synchronized void cachePackageInstallInfo(String packageName, UserHandle user, Bitmap icon, CharSequence title) {
    removeFromMemCacheLocked(packageName, user);
    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);
    // For icon caching, do not go through DB. Just update the in-memory entry.
    if (entry == null) {
        entry = new CacheEntry();
    }
    if (!TextUtils.isEmpty(title)) {
        entry.title = title;
    }
    if (icon != null) {
        BaseIconFactory li = getIconFactory();
        li.createIconBitmap(icon).applyTo(entry);
        li.close();
    }
    if (!TextUtils.isEmpty(title) && entry.icon != null) {
        mCache.put(cacheKey, entry);
    }
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey) BaseIconFactory(com.android.launcher3.icons.BaseIconFactory)

Example 84 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class BaseIconCache method addIconToDBAndMemCache.

/**
 * Adds an entry into the DB and the in-memory cache.
 * @param replaceExisting if true, it will recreate the bitmap even if it already exists in
 *                        the memory. This is useful then the previous bitmap was created using
 *                        old data.
 * package private
 */
protected synchronized <T> void addIconToDBAndMemCache(T object, CachingLogic<T> cachingLogic, PackageInfo info, long userSerial, boolean replaceExisting) {
    UserHandle user = cachingLogic.getUser(object);
    ComponentName componentName = cachingLogic.getComponent(object);
    final ComponentKey key = new ComponentKey(componentName, user);
    CacheEntry entry = null;
    if (!replaceExisting) {
        entry = mCache.get(key);
        // We can't reuse the entry if the high-res icon is not present.
        if (entry == null || entry.icon == null || entry.isLowRes()) {
            entry = null;
        }
    }
    if (entry == null) {
        entry = new CacheEntry();
        cachingLogic.loadIcon(mContext, object, entry);
    }
    // an empty entry.
    if (entry.icon == null)
        return;
    entry.title = cachingLogic.getLabel(object);
    entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
    if (cachingLogic.addToMemCache())
        mCache.put(key, entry);
    ContentValues values = newContentValues(entry, entry.title.toString(), componentName.getPackageName(), cachingLogic.getKeywords(object, mLocaleList));
    addIconToDB(values, componentName, info, userSerial);
}
Also used : ContentValues(android.content.ContentValues) UserHandle(android.os.UserHandle) ComponentKey(com.android.launcher3.util.ComponentKey) ComponentName(android.content.ComponentName)

Example 85 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class BaseIconCache method getEntryForPackageLocked.

/**
 * Gets an entry for the package, which can be used as a fallback entry for various components.
 * This method is not thread safe, it must be called from a synchronized method.
 */
protected CacheEntry getEntryForPackageLocked(String packageName, UserHandle user, boolean useLowResIcon) {
    assertWorkerThread();
    ComponentKey cacheKey = getPackageKey(packageName, user);
    CacheEntry entry = mCache.get(cacheKey);
    if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
        entry = new CacheEntry();
        boolean entryUpdated = true;
        // Check the DB first.
        if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
            try {
                int flags = Process.myUserHandle().equals(user) ? 0 : PackageManager.GET_UNINSTALLED_PACKAGES;
                PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
                ApplicationInfo appInfo = info.applicationInfo;
                if (appInfo == null) {
                    throw new NameNotFoundException("ApplicationInfo is null");
                }
                BaseIconFactory li = getIconFactory();
                // Load the full res icon for the application, but if useLowResIcon is set, then
                // only keep the low resolution icon instead of the larger full-sized icon
                BitmapInfo iconInfo = li.createBadgedIconBitmap(appInfo.loadIcon(mPackageManager), user, appInfo.targetSdkVersion, isInstantApp(appInfo));
                li.close();
                entry.title = appInfo.loadLabel(mPackageManager);
                entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
                entry.icon = useLowResIcon ? LOW_RES_ICON : iconInfo.icon;
                entry.color = iconInfo.color;
                // Add the icon in the DB here, since these do not get written during
                // package updates.
                ContentValues values = newContentValues(iconInfo, entry.title.toString(), packageName, null);
                addIconToDB(values, cacheKey.componentName, info, getSerialNumberForUser(user));
            } catch (NameNotFoundException e) {
                if (DEBUG)
                    Log.d(TAG, "Application not installed " + packageName);
                entryUpdated = false;
            }
        }
        // Only add a filled-out entry to the cache
        if (entryUpdated) {
            mCache.put(cacheKey, entry);
        }
    }
    return entry;
}
Also used : ContentValues(android.content.ContentValues) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ComponentKey(com.android.launcher3.util.ComponentKey) ApplicationInfo(android.content.pm.ApplicationInfo) BaseIconFactory(com.android.launcher3.icons.BaseIconFactory) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

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