Search in sources :

Example 36 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 37 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project Neo-Launcher by NeoApplications.

the class NormalizedIconLoader method getDefaultIcon.

@Override
public Drawable getDefaultIcon(int userId) {
    synchronized (mDefaultIcons) {
        BitmapInfo info = mDefaultIcons.get(userId);
        if (info == null) {
            info = getBitmapInfo(Resources.getSystem().getDrawable(android.R.drawable.sym_def_app_icon), userId, 0, false);
            mDefaultIcons.put(userId, info);
        }
        return new FastBitmapDrawable(info);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Example 38 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project Neo-Launcher by NeoApplications.

the class LoaderCursor method loadIcon.

/**
 * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
 */
protected boolean loadIcon(WorkspaceItemInfo info, LauncherIcons li) {
    if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
        String packageName = getString(iconPackageIndex);
        String resourceName = getString(iconResourceIndex);
        if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
            info.iconResource = new ShortcutIconResource();
            info.iconResource.packageName = packageName;
            info.iconResource.resourceName = resourceName;
            BitmapInfo iconInfo = li.createIconBitmap(info.iconResource);
            if (iconInfo != null) {
                info.applyFrom(iconInfo);
                return true;
            }
        }
    }
    // Failed to load from resource, try loading from DB.
    byte[] data = getBlob(iconIndex);
    try {
        info.applyFrom(li.createIconBitmap(BitmapFactory.decodeByteArray(data, 0, data.length)));
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Failed to decode byte array for info " + info, e);
        return false;
    }
}
Also used : ShortcutIconResource(android.content.Intent.ShortcutIconResource) BitmapInfo(com.android.launcher3.icons.BitmapInfo) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException)

Example 39 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo 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)

Example 40 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Trebuchet by LineageOS.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

BitmapInfo (com.android.launcher3.icons.BitmapInfo)33 LauncherIcons (com.android.launcher3.icons.LauncherIcons)21 Intent (android.content.Intent)18 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)18 Bitmap (android.graphics.Bitmap)15 ComponentName (android.content.ComponentName)14 Context (android.content.Context)14 IconCache (com.android.launcher3.icons.IconCache)13 WorkerThread (androidx.annotation.WorkerThread)11 ItemInfo (com.android.launcher3.model.data.ItemInfo)11 List (java.util.List)9 ShortcutInfo (android.content.pm.ShortcutInfo)8 PackageInfo (android.content.pm.PackageInfo)7 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 TaskDescription (android.app.ActivityManager.TaskDescription)5 ActivityInfo (android.content.pm.ActivityInfo)5 LauncherApps (android.content.pm.LauncherApps)5 UserManager (android.os.UserManager)5 R (com.android.launcher3.R)5 BaseIconFactory (com.android.launcher3.icons.BaseIconFactory)5