Search in sources :

Example 81 with ItemInfoWithIcon

use of com.android.launcher3.ItemInfoWithIcon in project android_packages_apps_Launcher3 by ArrowOS.

the class IconCache method getTitlesAndIconsInBulk.

/**
 * Load and fill icons requested in iconRequestInfos using a single bulk sql query.
 */
public synchronized <T extends ItemInfoWithIcon> void getTitlesAndIconsInBulk(List<IconRequestInfo<T>> iconRequestInfos) {
    Map<Pair<UserHandle, Boolean>, List<IconRequestInfo<T>>> iconLoadSubsectionsMap = iconRequestInfos.stream().collect(groupingBy(iconRequest -> Pair.create(iconRequest.itemInfo.user, iconRequest.useLowResIcon)));
    Trace.beginSection("loadIconsInBulk");
    iconLoadSubsectionsMap.forEach((sectionKey, filteredList) -> {
        Map<ComponentName, List<IconRequestInfo<T>>> duplicateIconRequestsMap = filteredList.stream().collect(groupingBy(iconRequest -> iconRequest.itemInfo.getTargetComponent()));
        Trace.beginSection("loadIconSubsectionInBulk");
        try (Cursor c = createBulkQueryCursor(filteredList, /* user = */
        sectionKey.first, /* useLowResIcons = */
        sectionKey.second)) {
            int componentNameColumnIndex = c.getColumnIndexOrThrow(IconDB.COLUMN_COMPONENT);
            while (c.moveToNext()) {
                ComponentName cn = ComponentName.unflattenFromString(c.getString(componentNameColumnIndex));
                List<IconRequestInfo<T>> duplicateIconRequests = duplicateIconRequestsMap.get(cn);
                if (cn != null) {
                    CacheEntry entry = cacheLocked(cn, /* user = */
                    sectionKey.first, () -> duplicateIconRequests.get(0).launcherActivityInfo, mLauncherActivityInfoCachingLogic, c, /* usePackageIcon= */
                    false, /* useLowResIcons = */
                    sectionKey.second);
                    for (IconRequestInfo<T> iconRequest : duplicateIconRequests) {
                        applyCacheEntry(entry, iconRequest.itemInfo);
                    }
                }
            }
        } catch (SQLiteException e) {
            Log.d(TAG, "Error reading icon cache", e);
        } finally {
            Trace.endSection();
        }
    });
    Trace.endSection();
}
Also used : Trace(android.os.Trace) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Preconditions(com.android.launcher3.util.Preconditions) Drawable(android.graphics.drawable.Drawable) Process(android.os.Process) LauncherFiles(com.android.launcher3.LauncherFiles) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) SQLiteException(android.database.sqlite.SQLiteException) Map(java.util.Map) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) WidgetSection(com.android.launcher3.widget.WidgetSections.WidgetSection) Log(android.util.Log) Utilities(com.android.launcher3.Utilities) Predicate(java.util.function.Predicate) InstantAppResolver(com.android.launcher3.util.InstantAppResolver) UserCache(com.android.launcher3.pm.UserCache) LauncherApps(android.content.pm.LauncherApps) ComponentCachingLogic(com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic) Objects(java.util.Objects) PackageInstaller(android.content.pm.PackageInstaller) List(java.util.List) Stream(java.util.stream.Stream) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) WidgetSections(com.android.launcher3.widget.WidgetSections) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Context(android.content.Context) MODEL_EXECUTOR(com.android.launcher3.util.Executors.MODEL_EXECUTOR) NO_CATEGORY(com.android.launcher3.widget.WidgetSections.NO_CATEGORY) AppInfo(com.android.launcher3.model.data.AppInfo) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pair(android.util.Pair) Intent(android.content.Intent) PackageInfo(android.content.pm.PackageInfo) Supplier(java.util.function.Supplier) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) CachingLogic(com.android.launcher3.icons.cache.CachingLogic) Cursor(android.database.Cursor) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) HandlerRunnable(com.android.launcher3.icons.cache.HandlerRunnable) Collections(java.util.Collections) BaseIconCache(com.android.launcher3.icons.cache.BaseIconCache) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) IconRequestInfo(com.android.launcher3.model.data.IconRequestInfo) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) List(java.util.List) ComponentName(android.content.ComponentName) Pair(android.util.Pair)

Example 82 with ItemInfoWithIcon

use of com.android.launcher3.ItemInfoWithIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class BubbleTextView method verifyHighRes.

/**
 * Verifies that the current icon is high-res otherwise posts a request to load the icon.
 */
public void verifyHighRes() {
    if (mIconLoadRequest != null) {
        mIconLoadRequest.cancel();
        mIconLoadRequest = null;
    }
    if (getTag() instanceof ItemInfoWithIcon) {
        ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
        if (info.usingLowResIcon()) {
            mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache().updateIconInBackground(BubbleTextView.this, info);
        }
    }
}
Also used : ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon)

Example 83 with ItemInfoWithIcon

use of com.android.launcher3.ItemInfoWithIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class BubbleTextView method makePreloadIcon.

/**
 * Creates a PreloadIconDrawable with the appropriate progress level without mutating this
 * object.
 */
@Nullable
public PreloadIconDrawable makePreloadIcon() {
    if (!(getTag() instanceof ItemInfoWithIcon)) {
        return null;
    }
    ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
    int progressLevel = info.getProgressLevel();
    final PreloadIconDrawable preloadDrawable = newPendingIcon(getContext(), info);
    preloadDrawable.setLevel(progressLevel);
    preloadDrawable.setIsDisabled(!info.isAppStartable());
    return preloadDrawable;
}
Also used : ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Nullable(androidx.annotation.Nullable)

Example 84 with ItemInfoWithIcon

use of com.android.launcher3.ItemInfoWithIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class BubbleTextView method applyProgressLevel.

/**
 * Applies the given progress level to the this icon's progress bar.
 */
@Nullable
public PreloadIconDrawable applyProgressLevel() {
    if (!(getTag() instanceof ItemInfoWithIcon)) {
        return null;
    }
    ItemInfoWithIcon info = (ItemInfoWithIcon) getTag();
    int progressLevel = info.getProgressLevel();
    if (progressLevel >= 100) {
        setContentDescription(info.contentDescription != null ? info.contentDescription : "");
    } else if (progressLevel > 0) {
        setDownloadStateContentDescription(info, progressLevel);
    } else {
        setContentDescription(getContext().getString(R.string.app_waiting_download_title, info.title));
    }
    if (mIcon != null) {
        PreloadIconDrawable preloadIconDrawable;
        if (mIcon instanceof PreloadIconDrawable) {
            preloadIconDrawable = (PreloadIconDrawable) mIcon;
            preloadIconDrawable.setLevel(progressLevel);
            preloadIconDrawable.setIsDisabled(!info.isAppStartable());
        } else {
            preloadIconDrawable = makePreloadIcon();
            setIcon(preloadIconDrawable);
        }
        return preloadIconDrawable;
    }
    return null;
}
Also used : ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Nullable(androidx.annotation.Nullable)

Example 85 with ItemInfoWithIcon

use of com.android.launcher3.ItemInfoWithIcon in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Utilities method getBadge.

/**
 * For apps icons and shortcut icons that have badges, this method creates a drawable that can
 * later on be rendered on top of the layers for the badges. For app icons, work profile badges
 * can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
 * badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
 */
@TargetApi(Build.VERSION_CODES.O)
public static Drawable getBadge(Context context, ItemInfo info, Object obj) {
    LauncherAppState appState = LauncherAppState.getInstance(context);
    int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
        if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) {
            // The item is not yet added on home screen.
            return new FixedSizeEmptyDrawable(iconSize);
        }
        ShortcutInfo si = (ShortcutInfo) obj;
        Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
        float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
        float insetFraction = (iconSize - badgeSize) / iconSize;
        return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return ((FolderAdaptiveIcon) obj).getBadge();
    } else {
        return context.getPackageManager().getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) InsetDrawable(android.graphics.drawable.InsetDrawable) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Aggregations

ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)67 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)22 Intent (android.content.Intent)17 Paint (android.graphics.Paint)17 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)16 ComponentName (android.content.ComponentName)13 ShortcutInfo (android.content.pm.ShortcutInfo)13 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)12 Drawable (android.graphics.drawable.Drawable)11 Nullable (androidx.annotation.Nullable)11 UiThread (androidx.annotation.UiThread)10 AppInfo (com.android.launcher3.model.data.AppInfo)10 Bitmap (android.graphics.Bitmap)8 TextPaint (android.text.TextPaint)8 TargetApi (android.annotation.TargetApi)7 Point (android.graphics.Point)7 InsetDrawable (android.graphics.drawable.InsetDrawable)7 DotInfo (com.android.launcher3.dot.DotInfo)7 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Context (android.content.Context)6