Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cd914b3 authored by Shamali Patwa's avatar Shamali Patwa Committed by Android (Google) Code Review
Browse files

Merge "Add helper method to get drawable info about the badge. This is to be...

Merge "Add helper method to get drawable info about the badge. This is to be able to map the data to the widget picker's data types." into main
parents 527b0d11 839fe820
Loading
Loading
Loading
Loading
+38 −13
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.drawable.Drawable;

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -211,7 +213,6 @@ public class BitmapInfo {
        return getBadgeDrawable(context, isThemed, false, badgeShape);
    }


    /**
     * Creates a Drawable for an icon badge for this BitmapInfo
     * @param context Context
@@ -232,18 +233,12 @@ public class BitmapInfo {
        }
        if (skipUserBadge) {
            return null;
        } else if ((flags & FLAG_INSTANT) != 0) {
            return new UserBadgeDrawable(context, R.drawable.ic_instant_app_badge,
                    R.color.badge_tint_instant, isThemed, badgeShape);
        } else if ((flags & FLAG_WORK) != 0) {
            return new UserBadgeDrawable(context, R.drawable.ic_work_app_badge,
                    R.color.badge_tint_work, isThemed, badgeShape);
        } else if ((flags & FLAG_CLONE) != 0) {
            return new UserBadgeDrawable(context, R.drawable.ic_clone_app_badge,
                    R.color.badge_tint_clone, isThemed, badgeShape);
        } else if ((flags & FLAG_PRIVATE) != 0) {
            return new UserBadgeDrawable(context, R.drawable.ic_private_profile_app_badge,
                    R.color.badge_tint_private, isThemed, badgeShape);
        } else {
            BadgeDrawableInfo drawableInfo = getBadgeDrawableInfo();
            if (drawableInfo != null) {
                return new UserBadgeDrawable(context, drawableInfo.drawableRes,
                        drawableInfo.colorRes, isThemed, badgeShape);
            }
        }
        return null;
    }
@@ -256,6 +251,26 @@ public class BitmapInfo {
        return new BitmapInfo(bitmap, color);
    }

    /**
     * Returns information about the badge to apply based on current flags.
     */
    @Nullable
    public BadgeDrawableInfo getBadgeDrawableInfo() {
        if ((flags & FLAG_INSTANT) != 0) {
            return new BadgeDrawableInfo(R.drawable.ic_instant_app_badge,
                    R.color.badge_tint_instant);
        } else if ((flags & FLAG_WORK) != 0) {
            return new BadgeDrawableInfo(R.drawable.ic_work_app_badge, R.color.badge_tint_work);
        } else if ((flags & FLAG_CLONE) != 0) {
            return new BadgeDrawableInfo(R.drawable.ic_clone_app_badge, R.color.badge_tint_clone);
        } else if ((flags & FLAG_PRIVATE) != 0) {
            return new BadgeDrawableInfo(R.drawable.ic_private_profile_app_badge,
                    R.color.badge_tint_private);
        } else {
            return null;
        }
    }

    /**
     * Interface to be implemented by drawables to provide a custom BitmapInfo
     */
@@ -272,4 +287,14 @@ public class BitmapInfo {
         */
        void drawForPersistence(Canvas canvas);
    }

    /**
     * Drawables backing a specific badge shown on app icons.
     * @param drawableRes Drawable resource for the badge.
     * @param colorRes Color resource to tint the badge.
     */
    public record BadgeDrawableInfo(
            @DrawableRes int drawableRes,
            @ColorRes int colorRes
    ) {}
}