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

Commit f7fcf9dc authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix notification row transparency." into main

parents 39194d33 23c7418d
Loading
Loading
Loading
Loading
+12 −17
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.view.animation.Interpolator;
import com.android.app.animation.Interpolators;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.jank.InteractionJankMonitor.Configuration;
import com.android.systemui.Flags;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.common.shared.colors.SurfaceEffectColors;
import com.android.systemui.res.R;
@@ -101,7 +102,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private ValueAnimator mBackgroundColorAnimator;
    private float mAppearAnimationFraction = -1.0f;
    private float mAppearAnimationTranslation;
    private int mNormalColor;
    protected int mNormalColor;
    protected int mOpaqueColor;
    private boolean mIsBelowSpeedBump;
    private long mLastActionUpTime;

@@ -130,17 +132,13 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView

    protected void updateColors() {
        if (notificationRowTransparency()) {
            if (mIsBlurSupported) {
            mNormalColor = SurfaceEffectColors.surfaceEffect1(getContext());
            } else {
                mNormalColor = mContext.getColor(
            mOpaqueColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainer);
            }
        } else {
            mNormalColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
        }
        setBackgroundToNormalColor();
        mTintedRippleColor = mContext.getColor(
                R.color.notification_ripple_tinted_color);
        mNormalRippleColor = mContext.getColor(
@@ -151,12 +149,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mOverrideAmount = 0.0f;
    }

    private void setBackgroundToNormalColor() {
        if (mBackgroundNormal != null) {
            mBackgroundNormal.setNormalColor(mNormalColor);
        }
    }

    /**
     * Reload background colors from resources and invalidate views.
     */
@@ -186,7 +178,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        mBackgroundNormal = findViewById(R.id.backgroundNormal);
        mFakeShadow = findViewById(R.id.fake_shadow);
        mShadowHidden = mFakeShadow.getVisibility() != VISIBLE;
        setBackgroundToNormalColor();
        initBackground();
        updateBackgroundTint();
        updateOutlineAlpha();
@@ -352,7 +343,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }

    protected boolean usesTransparentBackground() {
        return mIsBlurSupported && notificationRowTransparency();
        return false;
    }

    @Override
@@ -708,10 +699,14 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        }
        if (withTint && mBgTint != NO_COLOR) {
            return mBgTint;
        } else {
            if (Flags.notificationRowTransparency()) {
                return usesTransparentBackground() ? mNormalColor : mOpaqueColor;
            } else {
                return mNormalColor;
            }
        }
    }

    private int getRippleColor() {
        if (mBgTint != 0) {
+31 −12
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ import androidx.dynamicanimation.animation.SpringAnimation;

import com.android.app.animation.Interpolators;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -979,7 +980,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        } else if (isAboveShelf() != wasAboveShelf) {
            mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf);
        }
        updateColors();
        updateBackgroundTint();
    }

    /**
@@ -1678,20 +1679,34 @@ public class ExpandableNotificationRow extends ActivatableNotificationView

    @Override
    protected void setBackgroundTintColor(int color) {
        super.setBackgroundTintColor(color);
        NotificationContentView view = getShowingLayout();
        if (view != null) {
            view.setBackgroundTintColor(color);
        }
        if (notificationRowTransparency() && mBackgroundNormal != null) {
        if (notificationRowTransparency()) {
            boolean isColorized = false;
            if (NotificationBundleUi.isEnabled() && mEntryAdapter != null) {
                mBackgroundNormal.setBgIsColorized(mEntryAdapter.isColorized());
                isColorized = mEntryAdapter.isColorized();
            } else {
                if (mEntry != null) {
                    mBackgroundNormal.setBgIsColorized(
                            mEntry.getSbn().getNotification().isColorized());
                    isColorized = mEntry.getSbn().getNotification().isColorized();
                }
            }
            boolean isTransparent = usesTransparentBackground();
            if (isColorized) {
                // For colorized notifications, use a color that matches the tint color at 90% alpha
                // when the row is transparent.
                color = ColorUtils.setAlphaComponent(
                        color, (int) (0xFF * (isTransparent ? 0.9f : 1)));
            } else {
                // For non-colorized notifications, use the semi-transparent normal color token
                // when the row is transparent, and the opaque color token otherwise.
                if (!isTransparent && mBgTint == NO_COLOR) {
                    color = mOpaqueColor;
                }
            }
        }

        super.setBackgroundTintColor(color);
        NotificationContentView view = getShowingLayout();
        if (view != null) {
            view.setBackgroundTintColor(color);
        }
    }

@@ -3113,7 +3128,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                    mChildrenContainer.setOnKeyguard(onKeyguard);
                }
            }
            updateColors();
            updateBackgroundTint();
        }
    }

@@ -4633,6 +4648,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView

    @Override
    protected boolean usesTransparentBackground() {
        return super.usesTransparentBackground() && !mIsHeadsUp && !mOnKeyguard;
        // Row background should be opaque when it's displayed as a heads-up notification or
        // displayed on keyguard.
        // TODO(b/388891313): Account for isBlurSupported when it is initialized and updated
        // correctly.
        return  notificationRowTransparency() && !mIsHeadsUp && !mOnKeyguard;
    }
}
+18 −41
Original line number Diff line number Diff line
@@ -36,9 +36,9 @@ 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;
@@ -52,7 +52,6 @@ import java.util.Arrays;
public class NotificationBackgroundView extends View implements Dumpable,
        ExpandableNotificationRow.DismissButtonTargetVisibilityListener {

    private static final int MAX_ALPHA = 0xFF;
    private final boolean mDontModifyCorners;
    private Drawable mBackground;
    private int mClipTopAmount;
@@ -73,8 +72,6 @@ public class NotificationBackgroundView extends View implements Dumpable,
    private final ColorStateList mLightColoredStatefulColors;
    private final ColorStateList mDarkColoredStatefulColors;
    private int mNormalColor;
    private boolean mBgIsColorized = false;
    private boolean mForceOpaque = false;
    private final int convexR = 9;
    private final int concaveR = 22;

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

    public void setNormalColor(int color) {
        mNormalColor = color;
        mFocusOverlayStroke = getResources().getDimension(R.dimen.notification_focus_stroke_width);
    }

    @Override
@@ -140,21 +139,6 @@ 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.

@@ -311,28 +295,21 @@ public class NotificationBackgroundView extends View implements Dumpable,
        return ((LayerDrawable) mBackground).getDrawable(1);
    }

    private void updateBaseLayerColor() {
    public void setTint(int tintColor) {
        Drawable baseLayer = getBaseBackgroundLayer();
        if (notificationRowTransparency()) {
            // 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.
        int color = isColorized()
                ? ColorUtils.setAlphaComponent(mTintColor, (int) (MAX_ALPHA * 0.9f))
                : mNormalColor;
        getBaseBackgroundLayer().setColorFilter(
            baseLayer.setColorFilter(
                    new PorterDuffColorFilter(
                        color,
                        PorterDuff.Mode.SRC)); // SRC operator discards the drawable's color+alpha
    }

    public void setTint(int tintColor) {
        Drawable baseLayer = getBaseBackgroundLayer();
                            tintColor,
                            // SRC operator discards the drawable's color+alpha
                            PorterDuff.Mode.SRC));
        } else {
            baseLayer.mutate().setTintMode(PorterDuff.Mode.SRC_ATOP);
            baseLayer.setTint(tintColor);
        mTintColor = tintColor;
        if (notificationRowTransparency()) {
            updateBaseLayerColor();
        }
        mTintColor = tintColor;
        setStatefulColors();
        invalidate();
    }