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

Commit 233b6921 authored by Rahul Banerjee's avatar Rahul Banerjee
Browse files

Add transparency to Notification Rows

Bug: 392189725
Flag: com.android.systemui.notification_row_transparency
Test: Manual (build, flash, pull shade down to see notifications, flip flag off, repeat)
Change-Id: I6ad9495963cda81aa05df67158c9eec0d4c17ff3
parent 8225e4a7
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.row;

import static com.android.systemui.Flags.notificationBackgroundTintOptimization;
import static com.android.systemui.Flags.notificationRowTransparency;
import static com.android.systemui.statusbar.notification.row.ExpandableView.ClipSide.BOTTOM;
import static com.android.systemui.statusbar.notification.row.ExpandableView.ClipSide.TOP;

@@ -38,6 +39,7 @@ import com.android.app.animation.Interpolators;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.jank.InteractionJankMonitor.Configuration;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.common.shared.colors.SurfaceEffectColors;
import com.android.systemui.res.R;
import com.android.systemui.shade.TouchLogger;
import com.android.systemui.statusbar.NotificationShelf;
@@ -122,8 +124,12 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }

    private void updateColors() {
        if (notificationRowTransparency()) {
            mNormalColor = SurfaceEffectColors.surfaceEffect1(getResources());
        } else {
            mNormalColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
        }
        mTintedRippleColor = mContext.getColor(
                R.color.notification_ripple_tinted_color);
        mNormalRippleColor = mContext.getColor(
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.Notification.Action.SEMANTIC_ACTION_MARK_CONVERSATION_
import static android.service.notification.NotificationListenerService.REASON_CANCEL;

import static com.android.systemui.Flags.notificationsPinnedHunInShade;
import static com.android.systemui.Flags.notificationRowTransparency;
import static com.android.systemui.flags.Flags.ENABLE_NOTIFICATIONS_SIMULATE_SLOW_MEASURE;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.PARENT_DISMISSED;
import static com.android.systemui.statusbar.notification.row.NotificationContentView.VISIBLE_TYPE_HEADSUP;
@@ -1616,6 +1617,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (view != null) {
            view.setBackgroundTintColor(color);
        }
        if (notificationRowTransparency()
                && (mBackgroundNormal != null)
                && (mEntry != null)) {
            mBackgroundNormal.setBgIsColorized(
                    mEntry.getSbn().getNotification().isColorized());
        }
    }

    public void closeRemoteInput() {
+43 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.row;

import static com.android.systemui.Flags.notificationRowTransparency;
import static com.android.systemui.util.ColorUtilKt.hexColorString;

import android.content.Context;
@@ -23,6 +24,7 @@ import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
@@ -34,8 +36,10 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.graphics.ColorUtils;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.Dumpable;
import com.android.systemui.common.shared.colors.SurfaceEffectColors;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.shared.NotificationAddXOnHoverToDismiss;
import com.android.systemui.util.DrawableDumpKt;
@@ -69,6 +73,7 @@ public class NotificationBackgroundView extends View implements Dumpable,
    private final ColorStateList mLightColoredStatefulColors;
    private final ColorStateList mDarkColoredStatefulColors;
    private final int mNormalColor;
    private boolean mBgIsColorized = false;
    private final int convexR = 9;
    private final int concaveR = 22;

@@ -82,8 +87,12 @@ public class NotificationBackgroundView extends View implements Dumpable,
                R.color.notification_state_color_light);
        mDarkColoredStatefulColors = getResources().getColorStateList(
                R.color.notification_state_color_dark);
        if (notificationRowTransparency()) {
            mNormalColor = SurfaceEffectColors.surfaceEffect1(getResources());
        } else  {
            mNormalColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
        }
        mFocusOverlayStroke = getResources().getDimension(R.dimen.notification_focus_stroke_width);
    }

@@ -132,6 +141,21 @@ public class NotificationBackgroundView extends View implements Dumpable,
        }
    }

    /**
     * A way to tell whether the background has been colorized.
     */
    public boolean isColorized() {
        return mBgIsColorized;
    }

    /**
     * A way to inform this class whether the background has been colorized.
     * We need to know this, in order to *not* override that color.
     */
    public void setBgIsColorized(boolean b) {
        mBgIsColorized = b;
    }

    private Path calculateDismissButtonCutoutPath(Rect backgroundBounds) {
        // TODO(b/365585705): Adapt to RTL after the UX design is finalized.

@@ -280,7 +304,7 @@ public class NotificationBackgroundView extends View implements Dumpable,
        setCustomBackground(d);
    }

    private Drawable getBaseBackgroundLayer() {
    public Drawable getBaseBackgroundLayer() {
        return ((LayerDrawable) mBackground).getDrawable(0);
    }

@@ -288,11 +312,27 @@ public class NotificationBackgroundView extends View implements Dumpable,
        return ((LayerDrawable) mBackground).getDrawable(1);
    }

    private void updateBaseLayerColor() {
        // BG base layer being a drawable, there isn't a method like setColor() to color it.
        // Instead, we set a color filter that essentially replaces every pixel of the drawable.
        // For non-colorized notifications, this function specifies a new color token.
        // For colorized notifications, this uses a color that matches the tint color at 90% alpha.
        getBaseBackgroundLayer().setColorFilter(
                new PorterDuffColorFilter(
                        isColorized()
                                ? ColorUtils.setAlphaComponent(mTintColor, (int) (255 * 0.9f))
                                : SurfaceEffectColors.surfaceEffect1(getResources()),
                        PorterDuff.Mode.SRC)); // SRC operator discards the drawable's color+alpha
    }

    public void setTint(int tintColor) {
        Drawable baseLayer = getBaseBackgroundLayer();
        baseLayer.mutate().setTintMode(PorterDuff.Mode.SRC_ATOP);
        baseLayer.setTint(tintColor);
        mTintColor = tintColor;
        if (notificationRowTransparency()) {
            updateBaseLayerColor();
        }
        setStatefulColors();
        invalidate();
    }