Search in sources :

Example 71 with FastBitmapDrawable

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

the class Workspace method createWidgetDrawable.

private Drawable createWidgetDrawable(ItemInfo widgetInfo, View layout) {
    int[] unScaledSize = estimateItemSize(widgetInfo);
    int visibility = layout.getVisibility();
    layout.setVisibility(VISIBLE);
    int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY);
    int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY);
    layout.measure(width, height);
    layout.layout(0, 0, unScaledSize[0], unScaledSize[1]);
    Bitmap b = BitmapRenderer.createHardwareBitmap(unScaledSize[0], unScaledSize[1], layout::draw);
    layout.setVisibility(visibility);
    return new FastBitmapDrawable(b);
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 72 with FastBitmapDrawable

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

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)

Example 73 with FastBitmapDrawable

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

the class DragPreviewProvider method createDrawable.

/**
 * Returns a new drawable to show when the {@link #mView} is being dragged around.
 * Responsibility for the drawable is transferred to the caller.
 */
public Drawable createDrawable() {
    if (mView instanceof LauncherAppWidgetHostView) {
        return null;
    }
    int width = 0;
    int height = 0;
    // Assume scaleX == scaleY, which is always the case for workspace items.
    float scale = mView.getScaleX();
    if (mView instanceof DraggableView) {
        ((DraggableView) mView).getSourceVisualDragBounds(mTempRect);
        width = mTempRect.width();
        height = mTempRect.height();
    } else {
        width = mView.getWidth();
        height = mView.getHeight();
    }
    return new FastBitmapDrawable(BitmapRenderer.createHardwareBitmap(width + blurSizeOutline, height + blurSizeOutline, (c) -> drawDragView(c, scale)));
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Context(android.content.Context) Rect(android.graphics.Rect) BitmapRenderer(com.android.launcher3.icons.BitmapRenderer) UI_HELPER_EXECUTOR(com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR) ActivityContext(com.android.launcher3.views.ActivityContext) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BlurMaskFilter(android.graphics.BlurMaskFilter) FeatureFlags(com.android.launcher3.config.FeatureFlags) PorterDuff(android.graphics.PorterDuff) SafeCloseable(com.android.launcher3.util.SafeCloseable) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) ByteBuffer(java.nio.ByteBuffer) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) Bitmap(android.graphics.Bitmap) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) Paint(android.graphics.Paint)

Example 74 with FastBitmapDrawable

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

Example 75 with FastBitmapDrawable

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

the class Utilities method loadFullDrawableWithoutTheme.

private static Drawable loadFullDrawableWithoutTheme(Context context, ItemInfo info, int width, int height, Object[] outObj) {
    ActivityContext activity = ActivityContext.lookupContext(context);
    LauncherAppState appState = LauncherAppState.getInstance(context);
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
        LauncherActivityInfo activityInfo = context.getSystemService(LauncherApps.class).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return activityInfo == null ? null : LauncherAppState.getInstance(context).getIconProvider().getIcon(activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info).buildRequest(context).query(ShortcutRequest.ALL);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return ShortcutCachingLogic.getIcon(context, si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(activity, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION && info instanceof SearchActionItemInfo) {
        return new AdaptiveIconDrawable(new FastBitmapDrawable(((SearchActionItemInfo) info).bitmap), null);
    } else {
        return null;
    }
}
Also used : ActivityContext(com.android.launcher3.views.ActivityContext) FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherApps(android.content.pm.LauncherApps) List(java.util.List) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) Point(android.graphics.Point) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable)

Aggregations

FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)66 Drawable (android.graphics.drawable.Drawable)40 Point (android.graphics.Point)35 Bitmap (android.graphics.Bitmap)33 Rect (android.graphics.Rect)27 Paint (android.graphics.Paint)17 DraggableView (com.android.launcher3.dragndrop.DraggableView)16 TargetApi (android.annotation.TargetApi)14 FastBitmapDrawable (com.android.launcher3.FastBitmapDrawable)13 LauncherIcons (com.android.launcher3.icons.LauncherIcons)13 SuppressLint (android.annotation.SuppressLint)12 UiThread (androidx.annotation.UiThread)12 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)11 BubbleTextView (com.android.launcher3.BubbleTextView)11 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)11 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)11 View (android.view.View)10 RoundDrawableWrapper (com.android.launcher3.icons.RoundDrawableWrapper)10 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)10 ShortcutInfo (android.content.pm.ShortcutInfo)8