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

Commit 1c9dfb96 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge "Make sure notif icon has a bg" into main

parents de391b7f db0e8922
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6222,6 +6222,7 @@ public class Notification implements Parcelable
                if (appIconRes != 0) {
                    mN.mAppIcon = Icon.createWithResource(mContext, appIconRes);
                    contentView.setImageViewIcon(R.id.icon, mN.mAppIcon);
                    contentView.setBoolean(R.id.icon, "setShouldShowAppIcon", true);
                    usingAppIcon = true;
                } else {
                    Log.w(TAG, "bindSmallIcon: could not get the app icon");
+49 −1
Original line number Diff line number Diff line
@@ -22,7 +22,12 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
@@ -36,6 +41,13 @@ import android.widget.RemoteViews;
@RemoteViews.RemoteView
public class NotificationRowIconView extends CachingIconView {
    private boolean mApplyCircularCrop = false;
    private boolean mShouldShowAppIcon = false;

    // Padding and background set on the view prior to being changed by setShouldShowAppIcon(true),
    // to be restored if shouldShowAppIcon becomes false again.
    private Rect mOriginalPadding = null;
    private Drawable mOriginalBackground = null;


    public NotificationRowIconView(Context context) {
        super(context);
@@ -59,7 +71,7 @@ public class NotificationRowIconView extends CachingIconView {
    @Override
    protected void onFinishInflate() {
        // If showing the app icon, we don't need background or padding.
        if (Flags.notificationsUseAppIcon() || Flags.notificationsUseAppIconInRow()) {
        if (Flags.notificationsUseAppIcon()) {
            setPadding(0, 0, 0, 0);
            setBackground(null);
        }
@@ -67,6 +79,42 @@ public class NotificationRowIconView extends CachingIconView {
        super.onFinishInflate();
    }

    /** Whether the icon represents the app icon (instead of the small icon). */
    @RemotableViewMethod
    public void setShouldShowAppIcon(boolean shouldShowAppIcon) {
        if (Flags.notificationsUseAppIconInRow()) {
            if (mShouldShowAppIcon == shouldShowAppIcon) {
                return; // no change
            }

            mShouldShowAppIcon = shouldShowAppIcon;
            if (mShouldShowAppIcon) {
                if (mOriginalPadding == null && mOriginalBackground == null) {
                    mOriginalPadding = new Rect(getPaddingLeft(), getPaddingTop(),
                            getPaddingRight(), getPaddingBottom());
                    mOriginalBackground = getBackground();
                }

                setPadding(0, 0, 0, 0);

                // Make the background white in case the icon itself doesn't have one.
                int white = Color.rgb(255, 255, 255);
                ColorFilter colorFilter = new PorterDuffColorFilter(white,
                        PorterDuff.Mode.SRC_ATOP);
                getBackground().mutate().setColorFilter(colorFilter);
            } else {
                // Restore original padding and background if needed
                if (mOriginalPadding != null) {
                    setPadding(mOriginalPadding.left, mOriginalPadding.top, mOriginalPadding.right,
                            mOriginalPadding.bottom);
                    mOriginalPadding = null;
                }
                setBackground(mOriginalBackground);
                mOriginalBackground = null;
            }
        }
    }

    @Nullable
    @Override
    Drawable loadSizeRestrictedIcon(@Nullable Icon icon) {