From 0e5a83a9c4fcb4f54994af61986bb26f0fccdbdd Mon Sep 17 00:00:00 2001 From: NUmeroAndDev Date: Sun, 11 Aug 2024 12:54:22 +0900 Subject: [PATCH] Support color constrast --- .../github/droidkaigi/confsched/KaigiApp.kt | 24 ++++++++++++++++++- .../confsched/designsystem/theme/Theme.kt | 14 ++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app-android/src/main/java/io/github/droidkaigi/confsched/KaigiApp.kt b/app-android/src/main/java/io/github/droidkaigi/confsched/KaigiApp.kt index e82982422..5777d9463 100644 --- a/app-android/src/main/java/io/github/droidkaigi/confsched/KaigiApp.kt +++ b/app-android/src/main/java/io/github/droidkaigi/confsched/KaigiApp.kt @@ -1,6 +1,7 @@ package io.github.droidkaigi.confsched import android.annotation.SuppressLint +import android.app.UiModeManager import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent @@ -14,6 +15,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -31,6 +33,7 @@ import io.github.droidkaigi.confsched.about.aboutScreenRoute import io.github.droidkaigi.confsched.about.navigateAboutScreen import io.github.droidkaigi.confsched.contributors.contributorsScreenRoute import io.github.droidkaigi.confsched.contributors.contributorsScreens +import io.github.droidkaigi.confsched.designsystem.theme.ColorContrast import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme import io.github.droidkaigi.confsched.eventmap.eventMapScreens import io.github.droidkaigi.confsched.eventmap.navigateEventMapScreen @@ -69,7 +72,9 @@ fun KaigiApp( displayFeatures: PersistentList, modifier: Modifier = Modifier, ) { - KaigiTheme { + KaigiTheme( + colorContrast = colorContrast(), + ) { Surface( modifier = modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background, @@ -341,3 +346,20 @@ private class ExternalNavController( .launchUrl(context, uri) } } + +@Composable +@ReadOnlyComposable +private fun colorContrast(): ColorContrast { + val uiModeManager = + LocalContext.current.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + when (uiModeManager.contrast) { + in 0.0f..0.33f -> ColorContrast.Default + in 0.34f..0.66f -> ColorContrast.Medium + in 0.67f..1.0f -> ColorContrast.High + else -> ColorContrast.Default + } + } else { + ColorContrast.Default + } +} diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt index b5082f359..a62b5fcde 100644 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt @@ -8,6 +8,9 @@ import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.Color +import io.github.droidkaigi.confsched.designsystem.theme.ColorContrast.Default +import io.github.droidkaigi.confsched.designsystem.theme.ColorContrast.High +import io.github.droidkaigi.confsched.designsystem.theme.ColorContrast.Medium private val lightScheme = lightColorScheme( primary = primaryLight, @@ -251,9 +254,14 @@ private val fixedAccentColors = FixedAccentColors( @Composable fun KaigiTheme( + colorContrast: ColorContrast = Default, content: @Composable () -> Unit, ) { - val colorScheme = darkScheme + val colorScheme = when (colorContrast) { + Default -> darkScheme + Medium -> mediumContrastDarkColorScheme + High -> highContrastDarkColorScheme + } MaterialTheme( colorScheme = colorScheme, @@ -266,3 +274,7 @@ fun KaigiTheme( }, ) } + +enum class ColorContrast { + Default, Medium, High +}