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

Commit db0e8922 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Make sure notif icon has a bg

If we're showing the small icon like before, use the same coloring (the
"inverted" style where the icon itself is the color of the notification,
and the background is either provided by the developer or just based on
the theme). If we're showing the app icon, don't add additional padding
and make sure we have a white background.

Ideally, we'd want to use what launcher does to scale the icons properly
and add the background, but this is an initial prototype.

Bug: 335211019
Test: tested some apps manually
Flag: android.app.notifications_use_app_icon_in_row DEVELOPMENT
Change-Id: Ic681cb343b9416931eccbe92d7a2568540b49d9f
parent 082fe7bb
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) {