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

Commit aa6b9b69 authored by Rahul Banerjee's avatar Rahul Banerjee Committed by Android (Google) Code Review
Browse files

Merge "Add transparency to Notification Rows" into main

parents b52ca7d4 233b6921
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.row;
package com.android.systemui.statusbar.notification.row;


import static com.android.systemui.Flags.notificationBackgroundTintOptimization;
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.BOTTOM;
import static com.android.systemui.statusbar.notification.row.ExpandableView.ClipSide.TOP;
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;
import com.android.internal.jank.InteractionJankMonitor.Configuration;
import com.android.internal.jank.InteractionJankMonitor.Configuration;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.common.shared.colors.SurfaceEffectColors;
import com.android.systemui.res.R;
import com.android.systemui.res.R;
import com.android.systemui.shade.TouchLogger;
import com.android.systemui.shade.TouchLogger;
import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.NotificationShelf;
@@ -122,8 +124,12 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    }
    }


    private void updateColors() {
    private void updateColors() {
        if (notificationRowTransparency()) {
            mNormalColor = SurfaceEffectColors.surfaceEffect1(getResources());
        } else {
            mNormalColor = mContext.getColor(
            mNormalColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
        }
        mTintedRippleColor = mContext.getColor(
        mTintedRippleColor = mContext.getColor(
                R.color.notification_ripple_tinted_color);
                R.color.notification_ripple_tinted_color);
        mNormalRippleColor = mContext.getColor(
        mNormalRippleColor = mContext.getColor(
+7 −0
Original line number Original line 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 android.service.notification.NotificationListenerService.REASON_CANCEL;


import static com.android.systemui.Flags.notificationsPinnedHunInShade;
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.flags.Flags.ENABLE_NOTIFICATIONS_SIMULATE_SLOW_MEASURE;
import static com.android.systemui.statusbar.notification.NotificationUtils.logKey;
import static com.android.systemui.statusbar.notification.NotificationUtils.logKey;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.PARENT_DISMISSED;
import static com.android.systemui.statusbar.notification.collection.NotificationEntry.DismissState.PARENT_DISMISSED;
@@ -1636,6 +1637,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        if (view != null) {
        if (view != null) {
            view.setBackgroundTintColor(color);
            view.setBackgroundTintColor(color);
        }
        }
        if (notificationRowTransparency()
                && (mBackgroundNormal != null)
                && (mEntry != null)) {
            mBackgroundNormal.setBgIsColorized(
                    mEntry.getSbn().getNotification().isColorized());
        }
    }
    }


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


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


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


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


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


@@ -82,8 +87,12 @@ public class NotificationBackgroundView extends View implements Dumpable,
                R.color.notification_state_color_light);
                R.color.notification_state_color_light);
        mDarkColoredStatefulColors = getResources().getColorStateList(
        mDarkColoredStatefulColors = getResources().getColorStateList(
                R.color.notification_state_color_dark);
                R.color.notification_state_color_dark);
        if (notificationRowTransparency()) {
            mNormalColor = SurfaceEffectColors.surfaceEffect1(getResources());
        } else  {
            mNormalColor = mContext.getColor(
            mNormalColor = mContext.getColor(
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
                    com.android.internal.R.color.materialColorSurfaceContainerHigh);
        }
        mFocusOverlayStroke = getResources().getDimension(R.dimen.notification_focus_stroke_width);
        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) {
    private Path calculateDismissButtonCutoutPath(Rect backgroundBounds) {
        // TODO(b/365585705): Adapt to RTL after the UX design is finalized.
        // 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);
        setCustomBackground(d);
    }
    }


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


@@ -288,11 +312,27 @@ public class NotificationBackgroundView extends View implements Dumpable,
        return ((LayerDrawable) mBackground).getDrawable(1);
        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) {
    public void setTint(int tintColor) {
        Drawable baseLayer = getBaseBackgroundLayer();
        Drawable baseLayer = getBaseBackgroundLayer();
        baseLayer.mutate().setTintMode(PorterDuff.Mode.SRC_ATOP);
        baseLayer.mutate().setTintMode(PorterDuff.Mode.SRC_ATOP);
        baseLayer.setTint(tintColor);
        baseLayer.setTint(tintColor);
        mTintColor = tintColor;
        mTintColor = tintColor;
        if (notificationRowTransparency()) {
            updateBaseLayerColor();
        }
        setStatefulColors();
        setStatefulColors();
        invalidate();
        invalidate();
    }
    }