Skip to content
Snippets Groups Projects
Commit 9139fe4e authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge "Updated Notification Hover colors to account for colorized notifications" into main

parents 9fded33b 0c2052d5
No related branches found
No related tags found
No related merge requests found
<?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
<?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
......@@ -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
......@@ -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);
}
private Drawable getBaseBackgroundLayer() {
return ((LayerDrawable) mBackground).getDrawable(0);
}
private Drawable getStatefulBackgroundLayer() {
return ((LayerDrawable) mBackground).getDrawable(1);
}
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);
}
Drawable baseLayer = getBaseBackgroundLayer();
baseLayer.mutate().setTintMode(PorterDuff.Mode.SRC_ATOP);
baseLayer.setTint(tintColor);
mTintColor = tintColor;
setStatefulColors();
invalidate();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment