Better night mode handling
Provides a default behavior for splash screen that uses light and dark
colors when available.
Test: Manual on API 27 to API 31, check that the splash screen with no
customization respect dark and light colors
Bug: 208823639
Change-Id: I60dab3006ad7e0ebd754486ec4d5a2e84d5ffee6
diff --git a/core/core-splashscreen/src/main/res/values-night/styles.xml b/core/core-splashscreen/src/main/res/values-night/styles.xml
new file mode 100644
index 0000000..714d8bc
--- /dev/null
+++ b/core/core-splashscreen/src/main/res/values-night/styles.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ Copyright 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.
+ -->
+
+<resources>
+ <style name="Base.Theme.SplashScreen.DayNight" parent="Base.Theme.SplashScreen"/>
+</resources>
\ No newline at end of file
diff --git a/core/core-splashscreen/src/main/res/values-v27/styles.xml b/core/core-splashscreen/src/main/res/values-v27/styles.xml
index caa29a6..b87ab9d 100644
--- a/core/core-splashscreen/src/main/res/values-v27/styles.xml
+++ b/core/core-splashscreen/src/main/res/values-v27/styles.xml
@@ -17,7 +17,15 @@
<resources>
- <style name="Theme.SplashScreen" parent="Theme.SplashScreenBase">
- <item name="android:windowLayoutInDisplayCutoutMode">default</item>
+ <style name="Base.v27.Theme.SplashScreen" parent="Base.v21.Theme.SplashScreen">
+ <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
+
+ <style name="Base.v27.Theme.SplashScreen.Light" parent="Base.v21.Theme.SplashScreen.Light">
+ <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
+ </style>
+
+ <style name="Base.Theme.SplashScreen.Light" parent="Base.v27.Theme.SplashScreen.Light"/>
+ <style name="Base.Theme.SplashScreen" parent="Base.v27.Theme.SplashScreen"/>
+
</resources>
\ No newline at end of file
diff --git a/core/core-splashscreen/src/main/res/values-v29/styles.xml b/core/core-splashscreen/src/main/res/values-v29/styles.xml
index dfc370f..b08397a 100644
--- a/core/core-splashscreen/src/main/res/values-v29/styles.xml
+++ b/core/core-splashscreen/src/main/res/values-v29/styles.xml
@@ -15,9 +15,12 @@
-->
<resources>
-
- <style name="Theme.SplashScreen" parent="Theme.SplashScreenBase">
+ <style name="Base.Theme.SplashScreen" parent="android:Theme.DeviceDefault.DayNight">
+ <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="android:enforceStatusBarContrast">false</item>
<item name="android:enforceNavigationBarContrast">false</item>
</style>
+
+ <style name="Base.Theme.SplashScreen.Light" parent="Base.Theme.SplashScreen">
+ </style>
</resources>
\ No newline at end of file
diff --git a/core/core-splashscreen/src/main/res/values-v31/styles.xml b/core/core-splashscreen/src/main/res/values-v31/styles.xml
index 90b4c18..2e4d189 100644
--- a/core/core-splashscreen/src/main/res/values-v31/styles.xml
+++ b/core/core-splashscreen/src/main/res/values-v31/styles.xml
@@ -15,14 +15,12 @@
-->
<resources>
-
- <style name="Theme.SplashScreen" parent="android:Theme.DeviceDefault.NoActionBar">
+ <style name="Theme.SplashScreen" parent="Base.Theme.SplashScreen.DayNight">
<item name="android:windowSplashScreenAnimatedIcon">?windowSplashScreenAnimatedIcon</item>
<item name="android:windowSplashScreenBackground">?windowSplashScreenBackground</item>
<item name="android:windowSplashScreenAnimationDuration">
?windowSplashScreenAnimationDuration
</item>
- <item name="android:windowSplashScreenIconBackgroundColor">@android:color/transparent</item>
</style>
<style name="Theme.SplashScreen.IconBackground" parent="Theme.SplashScreen">
diff --git a/core/core-splashscreen/src/main/res/values/styles.xml b/core/core-splashscreen/src/main/res/values/styles.xml
index 52335ac..4b7fe61 100644
--- a/core/core-splashscreen/src/main/res/values/styles.xml
+++ b/core/core-splashscreen/src/main/res/values/styles.xml
@@ -16,7 +16,21 @@
<resources>
- <style name="Theme.SplashScreenBase" parent="android:Theme.NoTitleBar">
+ <style name="Base.v21.Theme.SplashScreen" parent="android:Theme.DeviceDefault.NoActionBar">
+ </style>
+
+ <style name="Base.v21.Theme.SplashScreen.Light" parent="android:Theme.DeviceDefault.Light.NoActionBar">
+ </style>
+
+ <style name="Base.Theme.SplashScreen.Light" parent="Base.v21.Theme.SplashScreen.Light" />
+ <style name="Base.Theme.SplashScreen" parent="Base.v21.Theme.SplashScreen" />
+
+ <style name="Base.Theme.SplashScreen.DayNight" parent="Base.Theme.SplashScreen.Light" />
+
+ <!-- Splash Screen attributes common to all versions -->
+ <style name="Theme.SplashScreen.Common" parent="Base.Theme.SplashScreen.DayNight">
+ <item name="android:windowActionBar">false</item>
+ <item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">
@drawable/compat_splash_screen_no_icon_background
</item>
@@ -28,12 +42,12 @@
<item name="splashScreenIconSize">@dimen/splashscreen_icon_size_no_background</item>
</style>
- <style name="Theme.SplashScreen" parent="Theme.SplashScreenBase">
+ <style name="Theme.SplashScreen" parent="Theme.SplashScreen.Common">
<item name="postSplashScreenTheme">?android:attr/theme</item>
<item name="windowSplashScreenAnimationDuration">
@integer/default_icon_animation_duration
</item>
- <item name="windowSplashScreenBackground">@android:color/background_light</item>
+ <item name="windowSplashScreenBackground">?android:colorBackground</item>
<item name="windowSplashScreenAnimatedIcon">@android:drawable/sym_def_app_icon</item>
</style>