Skip to content

Commit

Permalink
SystemUI: Add dual-tone light and dark themes for QS
Browse files Browse the repository at this point in the history
Google's dual-tone QS design where the notification panel has a
semantically higher elevation adds depth to the notification+QS shade,
and we don't necessarily have to give it up just because our QS has
light and dark themes.

To preserve the dual-tone effect, use a darker background color for the
QS section:

Light:
    Notifications: neutral1 20 (surface_light)
    Notification panel: neutral1 50 (light BG)
    QS background: neutral1 100 (darker light BG / surface_header_light)
    Inactive QS tiles: neutral1 20 (surface_light)

Dark:
    Notifications: neutral1 800 (surface_dark)
    Notification panel: neutral1 900 (dark BG)
    QS background: neutral1 950 (surface_header_dark_sysui modulated to L* 5)
    Inactive QS tiles: neutral1 800 (surface_dark)

The dark QS background could be neutral1 0 (black) like it was before,
but I don't think it looks as good because it can't be tinted based on
the active wallpaper and thus stands out from other colors.

Unfortunately, Google's current CAM16-based modulation causes hue shifts
in extreme light and dark shades (e.g. L* = 98 / 5), but we'll fix this
by generating and overlaying modulated surface colors in our
ThemeOverlayController implementation.

Demo screenshots: https://twitter.com/kdrag0n/status/1445922541218922496

Change-Id: Icdc4957ecb4e0201377351f1a3e1c6928d6b3955
  • Loading branch information
kdrag0n committed Jun 7, 2022
1 parent 379fd16 commit a566e9f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions core/res/res/color/surface_header_dark_sysui.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2021 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">
<item android:color="@color/system_neutral1_500" android:lStar="5" />
</selector>
1 change: 1 addition & 0 deletions core/res/res/values-night/values.xml
Expand Up @@ -22,6 +22,7 @@
<item name="colorSecondary">@color/secondary_device_default_settings</item>
<item name="colorAccent">@color/accent_device_default_dark</item>
<item name="colorError">@color/error_color_device_default_dark</item>
<item name="colorSurfaceHeader">@color/surface_header_dark_sysui</item>
<item name="colorControlNormal">?attr/textColorPrimary</item>
<item name="alertDialogTheme">@style/Theme.DeviceDefault.Dialog.Alert</item>
<item name="forceDarkAllowed">false</item>
Expand Down
2 changes: 1 addition & 1 deletion packages/SystemUI/res/values/styles.xml
Expand Up @@ -333,7 +333,7 @@
<item name="android:windowIsFloating">true</item>
<item name="android:homeAsUpIndicator">@drawable/ic_arrow_back</item>
<item name="offStateColor">@*android:color/surface_light</item>
<item name="underSurfaceColor">@android:color/system_neutral1_50</item>
<item name="underSurfaceColor">@android:color/system_neutral1_100</item>
<item name="android:colorBackground">@android:color/system_neutral1_50</item>
<item name="android:itemTextAppearance">@style/Control.MenuItem</item>
</style>
Expand Down
Expand Up @@ -180,6 +180,7 @@ public void setUnocclusionAnimationRunning(boolean unocclusionAnimationRunning)
private UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController;

private GradientColors mColors;
private GradientColors mBehindColors;
private boolean mNeedsDrawableColorUpdate;

private float mScrimBehindAlphaKeyguard = KEYGUARD_SCRIM_ALPHA;
Expand Down Expand Up @@ -276,6 +277,7 @@ public void onUiModeChanged() {
);

mColors = new GradientColors();
mBehindColors = new GradientColors();
}

/**
Expand Down Expand Up @@ -874,7 +876,7 @@ protected void updateScrims() {
&& !mBlankScreen;

mScrimInFront.setColors(mColors, animateScrimInFront);
mScrimBehind.setColors(mColors, animateBehindScrim);
mScrimBehind.setColors(mBehindColors, animateBehindScrim);
mNotificationsScrim.setColors(mColors, animateScrimNotifications);

dispatchBackScrimState(mScrimBehind.getViewAlpha());
Expand Down Expand Up @@ -1214,11 +1216,20 @@ private void updateThemeColors() {
if (mScrimBehind == null) return;
int background = Utils.getColorAttr(mScrimBehind.getContext(),
android.R.attr.colorBackgroundFloating).getDefaultColor();
int surfaceBackground = Utils.getColorAttr(mScrimBehind.getContext(),
com.android.internal.R.attr.colorSurfaceHeader).getDefaultColor();
int accent = Utils.getColorAccent(mScrimBehind.getContext()).getDefaultColor();

mColors.setMainColor(background);
mColors.setSecondaryColor(accent);
mColors.setSupportsDarkText(
ColorUtils.calculateContrast(mColors.getMainColor(), Color.WHITE) > 4.5);

mBehindColors.setMainColor(surfaceBackground);
mBehindColors.setSecondaryColor(accent);
mBehindColors.setSupportsDarkText(
ColorUtils.calculateContrast(mBehindColors.getMainColor(), Color.WHITE) > 4.5);

mNeedsDrawableColorUpdate = true;
}

Expand Down

0 comments on commit a566e9f

Please sign in to comment.