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

Commit 0c2052d5 authored by Joshua Mokut's avatar Joshua Mokut
Browse files

Updated Notification Hover colors to account for colorized notifications

Notification background hover layer now uses one of three color state lists:
light colorized notification hover color, dark colorized notification hover color or the default notification hover color
for uncolorized notifications

Fixes: 314091474
Test:  create a notification -> hover with mouse -> ensure notification has a hover effect;
create a colorized notification -> hover with mouse -> ensure notification has a hover effect without losing its initial color.
Flag: NA
Change-Id: Ib9a1c8ef7b8ac1efba9c0f108208539ff4daceee
parent 6f601837
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2023 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    <!-- Pressed state's alpha is set to 0.00 temporarily until this bug is resolved permanently
    b/313920497 Design intended alpha is 0.15-->
    <item android:state_pressed="true" android:color="#ffffff" android:alpha="0.00" />
    <item android:state_hovered="true" android:color="#ffffff" android:alpha="0.11" />
    <item android:color="@color/transparent" />
</selector>
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2023 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    <!-- Pressed state's alpha is set to 0.00 temporarily until this bug is resolved permanently
    b/313920497 Design intended alpha is 0.15-->
    <item android:state_pressed="true" android:color="#000000" android:alpha="0.00" />
    <item android:state_hovered="true" android:color="#000000" android:alpha="0.11" />
    <item android:color="@color/transparent" />
</selector>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
    </item>
    <item>
        <shape>
            <solid android:color="@color/notification_overlay_color" />
            <solid android:color="@color/notification_state_color_default" />
        </shape>
    </item>
</layer-list>
 No newline at end of file
+36 −15
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.util.ContrastColorUtil;
import com.android.settingslib.Utils;
import com.android.systemui.Dumpable;
import com.android.systemui.res.R;

@@ -58,11 +60,19 @@ public class NotificationBackgroundView extends View implements Dumpable {
    private int mExpandAnimationWidth = -1;
    private int mExpandAnimationHeight = -1;
    private int mDrawableAlpha = 255;
    private final ColorStateList mLightColoredStatefulColors;
    private final ColorStateList mDarkColoredStatefulColors;
    private final int mNormalColor;

    public NotificationBackgroundView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mDontModifyCorners = getResources().getBoolean(
                R.bool.config_clipNotificationsToOutline);
        mDontModifyCorners = getResources().getBoolean(R.bool.config_clipNotificationsToOutline);
        mLightColoredStatefulColors = getResources().getColorStateList(
                R.color.notification_state_color_light);
        mDarkColoredStatefulColors = getResources().getColorStateList(
                R.color.notification_state_color_dark);
        mNormalColor = Utils.getColorAttrDefaultColor(mContext,
                com.android.internal.R.attr.materialColorSurfaceContainerHigh);
    }

    @Override
@@ -121,6 +131,18 @@ public class NotificationBackgroundView extends View implements Dumpable {
        }
    }

    /**
     * Stateful colors are colors that will overlay on the notification original color when one of
     * hover states, pressed states or other similar states is activated.
     */
    private void setStatefulColors() {
        if (mTintColor != mNormalColor) {
            ColorStateList newColor = ContrastColorUtil.isColorDark(mTintColor)
                    ? mDarkColoredStatefulColors : mLightColoredStatefulColors;
            ((GradientDrawable) getStatefulBackgroundLayer().mutate()).setColor(newColor);
        }
    }

    /**
     * Sets a background drawable. As we need to change our bounds independently of layout, we need
     * the notion of a background independently of the regular View background..
@@ -149,21 +171,20 @@ public class NotificationBackgroundView extends View implements Dumpable {
        setCustomBackground(d);
    }

    public void setTint(int tintColor) {
        if (tintColor != 0) {
            ColorStateList stateList = new ColorStateList(new int[][]{
                    new int[]{com.android.internal.R.attr.state_pressed},
                    new int[]{com.android.internal.R.attr.state_hovered},
                    new int[]{}},

                    new int[]{tintColor, 0, tintColor}
            );
            mBackground.setTintMode(PorterDuff.Mode.SRC_ATOP);
            mBackground.setTintList(stateList);
        } else {
            mBackground.setTintList(null);
    private Drawable getBaseBackgroundLayer() {
        return ((LayerDrawable) mBackground).getDrawable(0);
    }

    private Drawable getStatefulBackgroundLayer() {
        return ((LayerDrawable) mBackground).getDrawable(1);
    }

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