The window theme was always the light framework theme, so the launch window, and with it the Android 12+ splash, was white even in dark mode. - `Theme.Agendula` is now a DayNight theme (AppCompat, as in Calendula). Only the values that differ are qualified: the window background colour and a bool for the status-bar icons. - The window background is the background Compose then draws: the dynamic one on Android 12+ (`system_background_light/dark` on 14+, the nearest neutral-variant tone on 12–13), the fallback scheme's colour otherwise. A unit test keeps the XML fallback colours equal to `Color.kt`. - The app's own theme setting is handed to the system (`SystemTheme`): on Android 12+ through `UiModeManager.setApplicationNightMode`, so a Light or Dark chosen in Agendula wins over the system's on the splash as well; on Android 13+ the splash theme is also switched to pure black for the Black theme and to the fixed colours when dynamic colour is off. Deviation from the issue: it only asked for the system's dark mode, but following the system alone would have given a dark flash to anyone using Light in Agendula with a dark system, and kept the white one for Dark in Agendula with a light system. Limits: on Android 10–11 the splash can only follow the system's dark mode. On 12, Black and "dynamic colour off" start on the dynamic background, since the splash theme can't be switched there. Changing the theme in Settings now recreates the screen once, as switching the system's dark mode already did. Closes #119 Co-authored-by: Jean-Luc Makiola <business@jeanlucmakiola.de> Reviewed-on: https://codeberg.org/jlmakiola/agendula/pulls/132
This commit is contained in:
1 parent
41767f8b8b
commit
c3812e7d94
14 files changed
+153
-2
No files matched your search
@@ -33,6 +33,8 @@ All notable changes to this project are documented here. The format follows
|
||||
up there (#122).
|
||||
- Completing a task from the list, a widget or another device now cancels its
|
||||
upcoming reminder and clears one already showing (#127, #129).
|
||||
- The splash screen follows the app's theme, including Black and dynamic
|
||||
colour, instead of flashing white in dark mode (#119).
|
||||
|
||||
## [1.2.0] - 2026-10-26
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.net.toUri
|
||||
import de.jeanlucmakiola.agendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.agendula.data.prefs.is24Hour
|
||||
import de.jeanlucmakiola.agendula.ui.common.LocalFirstDayOfWeek
|
||||
import de.jeanlucmakiola.agendula.ui.common.LocalUse24HourFormat
|
||||
@@ -33,9 +34,12 @@ import de.jeanlucmakiola.agendula.ui.crash.CrashReportActivity
|
||||
import de.jeanlucmakiola.agendula.ui.navigation.NavRequest
|
||||
import de.jeanlucmakiola.agendula.ui.settings.SettingsViewModel
|
||||
import de.jeanlucmakiola.agendula.ui.theme.AgendulaTheme
|
||||
import de.jeanlucmakiola.agendula.ui.theme.SystemTheme
|
||||
import de.jeanlucmakiola.floret.crash.CrashReportDialog
|
||||
import de.jeanlucmakiola.floret.crash.CrashReporter
|
||||
import de.jeanlucmakiola.floret.crash.submitCrashReport
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -49,6 +53,8 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
@Inject lateinit var launchHooks: Set<@JvmSuppressWildcards LaunchHook>
|
||||
|
||||
@Inject lateinit var settingsPrefs: SettingsPrefs
|
||||
|
||||
// A captured crash report awaiting the user's decision, surfaced as a dialog
|
||||
// over the app on the next launch (the single-crash path). A startup
|
||||
// crash-loop is handled out of band, before setContent — see below.
|
||||
@@ -72,6 +78,13 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
AppShortcuts.publish(this)
|
||||
|
||||
// The stored setting, never the view model's placeholder: a night mode
|
||||
// that flips back and forth would recreate the activity each time.
|
||||
lifecycleScope.launch {
|
||||
settingsPrefs.settings.map { it.themeMode to it.dynamicColor }.distinctUntilChanged()
|
||||
.collect { (mode, dynamicColor) -> SystemTheme.apply(this@MainActivity, mode, dynamicColor) }
|
||||
}
|
||||
|
||||
// Only on a fresh launch: after a rotation or process restore the intent
|
||||
// is the same old one and the back stack already holds its destination.
|
||||
val fromHistory = intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package de.jeanlucmakiola.agendula.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.UiModeManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.StyleRes
|
||||
import de.jeanlucmakiola.agendula.R
|
||||
import de.jeanlucmakiola.agendula.data.prefs.ThemeMode
|
||||
|
||||
/**
|
||||
* Hands the app's theme setting to the system, which draws the launch window
|
||||
* and splash before any of the app runs (#119). The system keeps both across
|
||||
* launches, so the next start already matches.
|
||||
*/
|
||||
object SystemTheme {
|
||||
|
||||
/** The light or dark the app's resources follow, as [UiModeManager.setApplicationNightMode] takes it. */
|
||||
fun nightModeOf(mode: ThemeMode): Int = when (mode) {
|
||||
ThemeMode.SYSTEM -> UiModeManager.MODE_NIGHT_AUTO
|
||||
ThemeMode.LIGHT -> UiModeManager.MODE_NIGHT_NO
|
||||
ThemeMode.DARK, ThemeMode.BLACK -> UiModeManager.MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
/** The splash theme whose background is the one the app opens on. */
|
||||
@StyleRes
|
||||
fun splashThemeOf(mode: ThemeMode, dynamicColor: Boolean): Int = when {
|
||||
mode.isPureBlack -> R.style.Theme_Agendula_Black
|
||||
dynamicColor -> R.style.Theme_Agendula
|
||||
else -> R.style.Theme_Agendula_Fallback
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies [mode] and [dynamicColor]. A night mode the activity does not
|
||||
* have yet recreates it, once; the same one again changes nothing.
|
||||
*/
|
||||
fun apply(activity: Activity, mode: ThemeMode, dynamicColor: Boolean) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
activity.getSystemService(UiModeManager::class.java)?.setApplicationNightMode(nightModeOf(mode))
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
activity.splashScreen.setSplashScreenTheme(splashThemeOf(mode, dynamicColor))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
<!-- Nearest to the dynamic scheme's background, tone 6 of the neutral variant. -->
|
||||
<color name="window_background">@android:color/system_neutral2_900</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<color name="window_background">@android:color/system_background_dark</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<bool name="light_system_bars">false</bool>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<color name="window_background_fallback">#FF161113</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
<!-- Nearest to the dynamic scheme's background, tone 98 of the neutral variant. -->
|
||||
<color name="window_background">@android:color/system_neutral2_10</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<color name="window_background">@android:color/system_background_light</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<bool name="light_system_bars">true</bool>
|
||||
</resources>
|
||||
@@ -2,4 +2,8 @@
|
||||
<!-- Seed color: warm mauve. Material 3 derives Light & Dark schemes from this. -->
|
||||
<!-- Adaptive icon background -->
|
||||
<color name="ic_launcher_background">#FF7A5C6B</color>
|
||||
<!-- The Compose fallback schemes' background, kept equal by WindowColorsTest. -->
|
||||
<color name="window_background_fallback">#FFFEFBFC</color>
|
||||
<!-- The launch window and splash: the dynamic background where there is one. -->
|
||||
<color name="window_background">@color/window_background_fallback</color>
|
||||
</resources>
|
||||
@@ -1,7 +1,19 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<style name="Theme.Agendula" parent="android:Theme.Material.Light.NoActionBar">
|
||||
<!-- The launch window and splash; Compose draws the rest. Its light or dark
|
||||
follows the app's theme setting, handed to the system by SystemTheme. -->
|
||||
<style name="Theme.Agendula" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="android:windowBackground">@color/window_background</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:windowLightStatusBar">true</item>
|
||||
<item name="android:windowLightStatusBar">@bool/light_system_bars</item>
|
||||
</style>
|
||||
|
||||
<!-- Splash themes picked at runtime on API 33+, see SystemTheme. -->
|
||||
<style name="Theme.Agendula.Fallback">
|
||||
<item name="android:windowBackground">@color/window_background_fallback</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Agendula.Black">
|
||||
<item name="android:windowBackground">@android:color/black</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.jeanlucmakiola.agendula.ui.theme
|
||||
|
||||
import android.app.UiModeManager
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.R
|
||||
import de.jeanlucmakiola.agendula.data.prefs.ThemeMode
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SystemThemeTest {
|
||||
|
||||
@Test
|
||||
fun `the system follows the app's light or dark`() {
|
||||
assertThat(SystemTheme.nightModeOf(ThemeMode.SYSTEM)).isEqualTo(UiModeManager.MODE_NIGHT_AUTO)
|
||||
assertThat(SystemTheme.nightModeOf(ThemeMode.LIGHT)).isEqualTo(UiModeManager.MODE_NIGHT_NO)
|
||||
assertThat(SystemTheme.nightModeOf(ThemeMode.DARK)).isEqualTo(UiModeManager.MODE_NIGHT_YES)
|
||||
assertThat(SystemTheme.nightModeOf(ThemeMode.BLACK)).isEqualTo(UiModeManager.MODE_NIGHT_YES)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the splash opens on the background the app draws`() {
|
||||
assertThat(SystemTheme.splashThemeOf(ThemeMode.SYSTEM, dynamicColor = true)).isEqualTo(R.style.Theme_Agendula)
|
||||
assertThat(SystemTheme.splashThemeOf(ThemeMode.DARK, dynamicColor = false)).isEqualTo(R.style.Theme_Agendula_Fallback)
|
||||
assertThat(SystemTheme.splashThemeOf(ThemeMode.BLACK, dynamicColor = true)).isEqualTo(R.style.Theme_Agendula_Black)
|
||||
assertThat(SystemTheme.splashThemeOf(ThemeMode.BLACK, dynamicColor = false)).isEqualTo(R.style.Theme_Agendula_Black)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.jeanlucmakiola.agendula.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
/** The launch window's colour has to be the background Compose then draws, or the splash flashes. */
|
||||
class WindowColorsTest {
|
||||
|
||||
private fun fallbackIn(qualifier: String): Int {
|
||||
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.parse(File("src/main/res/$qualifier/colors.xml"))
|
||||
val colors = doc.getElementsByTagName("color")
|
||||
val hex = (0 until colors.length).map { colors.item(it) }
|
||||
.single { it.attributes.getNamedItem("name").nodeValue == "window_background_fallback" }
|
||||
.textContent.trim().removePrefix("#")
|
||||
return hex.toLong(16).toInt()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the window matches the fallback schemes`() {
|
||||
assertThat(fallbackIn("values")).isEqualTo(AgendulaLightFallback.background.toArgb())
|
||||
assertThat(fallbackIn("values-night")).isEqualTo(AgendulaDarkFallback.background.toArgb())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user