feat: 适配主题色和 edge to edge
顺便精简无用资源
This commit is contained in:
parent
2d7b3edf15
commit
daab0172a5
15 changed files with 179 additions and 89 deletions
|
|
@ -64,6 +64,8 @@ dependencies {
|
||||||
// About Libraries
|
// About Libraries
|
||||||
implementation(libs.aboutlibraries.core)
|
implementation(libs.aboutlibraries.core)
|
||||||
implementation(libs.aboutlibraries.compose)
|
implementation(libs.aboutlibraries.compose)
|
||||||
|
// M3 Color
|
||||||
|
implementation(libs.com.kyant0.m3color)
|
||||||
// Kotlin Coroutines
|
// Kotlin Coroutines
|
||||||
implementation(libs.kotlinx.coroutines.core)
|
implementation(libs.kotlinx.coroutines.core)
|
||||||
implementation(libs.kotlinx.coroutines.android)
|
implementation(libs.kotlinx.coroutines.android)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package cn.super12138.todo.ui.theme
|
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
|
|
||||||
val Purple80 = Color(0xFFD0BCFF)
|
|
||||||
val PurpleGrey80 = Color(0xFFCCC2DC)
|
|
||||||
val Pink80 = Color(0xFFEFB8C8)
|
|
||||||
|
|
||||||
val Purple40 = Color(0xFF6650a4)
|
|
||||||
val PurpleGrey40 = Color(0xFF625b71)
|
|
||||||
val Pink40 = Color(0xFF7D5260)
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package cn.super12138.todo.ui.theme
|
||||||
|
|
||||||
|
enum class PaletteStyle {
|
||||||
|
TonalSpot,
|
||||||
|
Neutral,
|
||||||
|
Vibrant,
|
||||||
|
Expressive,
|
||||||
|
Rainbow,
|
||||||
|
FruitSalad,
|
||||||
|
Monochrome,
|
||||||
|
Fidelity,
|
||||||
|
Content,
|
||||||
|
}
|
||||||
|
|
@ -1,55 +1,38 @@
|
||||||
package cn.super12138.todo.ui.theme
|
package cn.super12138.todo.ui.theme
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.darkColorScheme
|
|
||||||
import androidx.compose.material3.dynamicDarkColorScheme
|
|
||||||
import androidx.compose.material3.dynamicLightColorScheme
|
|
||||||
import androidx.compose.material3.lightColorScheme
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.colorResource
|
||||||
private val DarkColorScheme = darkColorScheme(
|
|
||||||
primary = Purple80,
|
|
||||||
secondary = PurpleGrey80,
|
|
||||||
tertiary = Pink80
|
|
||||||
)
|
|
||||||
|
|
||||||
private val LightColorScheme = lightColorScheme(
|
|
||||||
primary = Purple40,
|
|
||||||
secondary = PurpleGrey40,
|
|
||||||
tertiary = Pink40
|
|
||||||
|
|
||||||
/* Other default colors to override
|
|
||||||
background = Color(0xFFFFFBFE),
|
|
||||||
surface = Color(0xFFFFFBFE),
|
|
||||||
onPrimary = Color.White,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onTertiary = Color.White,
|
|
||||||
onBackground = Color(0xFF1C1B1F),
|
|
||||||
onSurface = Color(0xFF1C1B1F),
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ToDoTheme(
|
fun ToDoTheme(
|
||||||
|
color: Color? = null,
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
|
style: PaletteStyle = PaletteStyle.TonalSpot,
|
||||||
|
contrastLevel: Double = 0.0,
|
||||||
// Dynamic color is available on Android 12+
|
// Dynamic color is available on Android 12+
|
||||||
dynamicColor: Boolean = true,
|
dynamicColor: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
val colorScheme = when {
|
val baseColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && dynamicColor) {
|
||||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
colorResource(id = android.R.color.system_accent1_500)
|
||||||
val context = LocalContext.current
|
} else {
|
||||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
Color(0xFF0061A4)
|
||||||
}
|
|
||||||
|
|
||||||
darkTheme -> DarkColorScheme
|
|
||||||
else -> LightColorScheme
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关键色,如果指定就使用
|
||||||
|
val keyColor = color ?: baseColor
|
||||||
|
|
||||||
|
val colorScheme = dynamicColorScheme(
|
||||||
|
keyColor = keyColor,
|
||||||
|
isDark = darkTheme,
|
||||||
|
style = style,
|
||||||
|
contrastLevel = contrastLevel
|
||||||
|
)
|
||||||
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = colorScheme,
|
colorScheme = colorScheme,
|
||||||
typography = Typography,
|
typography = Typography,
|
||||||
|
|
|
||||||
79
app/src/main/kotlin/cn/super12138/todo/ui/theme/ThemeExt.kt
Normal file
79
app/src/main/kotlin/cn/super12138/todo/ui/theme/ThemeExt.kt
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
package cn.super12138.todo.ui.theme
|
||||||
|
|
||||||
|
import androidx.compose.material3.ColorScheme
|
||||||
|
import androidx.compose.runtime.Stable
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import com.kyant.m3color.hct.Hct
|
||||||
|
import com.kyant.m3color.scheme.SchemeContent
|
||||||
|
import com.kyant.m3color.scheme.SchemeExpressive
|
||||||
|
import com.kyant.m3color.scheme.SchemeFidelity
|
||||||
|
import com.kyant.m3color.scheme.SchemeFruitSalad
|
||||||
|
import com.kyant.m3color.scheme.SchemeMonochrome
|
||||||
|
import com.kyant.m3color.scheme.SchemeNeutral
|
||||||
|
import com.kyant.m3color.scheme.SchemeRainbow
|
||||||
|
import com.kyant.m3color.scheme.SchemeTonalSpot
|
||||||
|
import com.kyant.m3color.scheme.SchemeVibrant
|
||||||
|
|
||||||
|
@Stable
|
||||||
|
fun dynamicColorScheme(
|
||||||
|
keyColor: Color,
|
||||||
|
isDark: Boolean,
|
||||||
|
style: PaletteStyle = PaletteStyle.TonalSpot,
|
||||||
|
contrastLevel: Double = 0.0
|
||||||
|
): ColorScheme {
|
||||||
|
val hct = Hct.fromInt(keyColor.toArgb())
|
||||||
|
val scheme = when (style) {
|
||||||
|
PaletteStyle.TonalSpot -> SchemeTonalSpot(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Neutral -> SchemeNeutral(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Vibrant -> SchemeVibrant(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Expressive -> SchemeExpressive(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Rainbow -> SchemeRainbow(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.FruitSalad -> SchemeFruitSalad(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Monochrome -> SchemeMonochrome(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Fidelity -> SchemeFidelity(hct, isDark, contrastLevel)
|
||||||
|
PaletteStyle.Content -> SchemeContent(hct, isDark, contrastLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ColorScheme(
|
||||||
|
background = scheme.background.toColor(),
|
||||||
|
error = scheme.error.toColor(),
|
||||||
|
errorContainer = scheme.errorContainer.toColor(),
|
||||||
|
inverseOnSurface = scheme.inverseOnSurface.toColor(),
|
||||||
|
inversePrimary = scheme.inversePrimary.toColor(),
|
||||||
|
inverseSurface = scheme.inverseSurface.toColor(),
|
||||||
|
onBackground = scheme.onBackground.toColor(),
|
||||||
|
onError = scheme.onError.toColor(),
|
||||||
|
onErrorContainer = scheme.onErrorContainer.toColor(),
|
||||||
|
onPrimary = scheme.onPrimary.toColor(),
|
||||||
|
onPrimaryContainer = scheme.onPrimaryContainer.toColor(),
|
||||||
|
onSecondary = scheme.onSecondary.toColor(),
|
||||||
|
onSecondaryContainer = scheme.onSecondaryContainer.toColor(),
|
||||||
|
onSurface = scheme.onSurface.toColor(),
|
||||||
|
onSurfaceVariant = scheme.onSurfaceVariant.toColor(),
|
||||||
|
onTertiary = scheme.onTertiary.toColor(),
|
||||||
|
onTertiaryContainer = scheme.onTertiaryContainer.toColor(),
|
||||||
|
outline = scheme.outline.toColor(),
|
||||||
|
outlineVariant = scheme.outlineVariant.toColor(),
|
||||||
|
primary = scheme.primary.toColor(),
|
||||||
|
primaryContainer = scheme.primaryContainer.toColor(),
|
||||||
|
scrim = scheme.scrim.toColor(),
|
||||||
|
secondary = scheme.secondary.toColor(),
|
||||||
|
secondaryContainer = scheme.secondaryContainer.toColor(),
|
||||||
|
surface = scheme.surface.toColor(),
|
||||||
|
surfaceBright = scheme.surfaceBright.toColor(),
|
||||||
|
surfaceContainer = scheme.surfaceContainer.toColor(),
|
||||||
|
surfaceContainerLow = scheme.surfaceContainerLow.toColor(),
|
||||||
|
surfaceContainerLowest = scheme.surfaceContainerLowest.toColor(),
|
||||||
|
surfaceContainerHigh = scheme.surfaceContainerHigh.toColor(),
|
||||||
|
surfaceContainerHighest = scheme.surfaceContainerHighest.toColor(),
|
||||||
|
surfaceDim = scheme.surfaceDim.toColor(),
|
||||||
|
surfaceTint = scheme.surfaceTint.toColor(),
|
||||||
|
surfaceVariant = scheme.surfaceVariant.toColor(),
|
||||||
|
tertiary = scheme.tertiary.toColor(),
|
||||||
|
tertiaryContainer = scheme.tertiaryContainer.toColor(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
private inline fun Int.toColor(): Color = Color(this)
|
||||||
|
|
@ -1,34 +1,5 @@
|
||||||
package cn.super12138.todo.ui.theme
|
package cn.super12138.todo.ui.theme
|
||||||
|
|
||||||
import androidx.compose.material3.Typography
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
|
|
||||||
// Set of Material typography styles to start with
|
val Typography = Typography()
|
||||||
val Typography = Typography(
|
|
||||||
bodyLarge = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
lineHeight = 24.sp,
|
|
||||||
letterSpacing = 0.5.sp
|
|
||||||
)
|
|
||||||
/* Other default text styles to override
|
|
||||||
titleLarge = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 22.sp,
|
|
||||||
lineHeight = 28.sp,
|
|
||||||
letterSpacing = 0.sp
|
|
||||||
),
|
|
||||||
labelSmall = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
fontSize = 11.sp,
|
|
||||||
lineHeight = 16.sp,
|
|
||||||
letterSpacing = 0.5.sp
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
)
|
|
||||||
11
app/src/main/res/values-night-v27/themes.xml
Normal file
11
app/src/main/res/values-night-v27/themes.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.NoActionBar">
|
||||||
|
<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:windowLightNavigationBar">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
12
app/src/main/res/values-night-v29/themes.xml
Normal file
12
app/src/main/res/values-night-v29/themes.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.NoActionBar">
|
||||||
|
<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:windowLightNavigationBar">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
<item name="android:enforceNavigationBarContrast">false</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
8
app/src/main/res/values-night/themes.xml
Normal file
8
app/src/main/res/values-night/themes.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.NoActionBar">
|
||||||
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
11
app/src/main/res/values-v27/themes.xml
Normal file
11
app/src/main/res/values-v27/themes.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.Light.NoActionBar">
|
||||||
|
<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:windowLightNavigationBar">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
12
app/src/main/res/values-v29/themes.xml
Normal file
12
app/src/main/res/values-v29/themes.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.Light.NoActionBar">
|
||||||
|
<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:windowLightNavigationBar">true</item>
|
||||||
|
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
|
||||||
|
<item name="android:enforceNavigationBarContrast">false</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<color name="purple_200">#FFBB86FC</color>
|
|
||||||
<color name="purple_500">#FF6200EE</color>
|
|
||||||
<color name="purple_700">#FF3700B3</color>
|
|
||||||
<color name="teal_200">#FF03DAC5</color>
|
|
||||||
<color name="teal_700">#FF018786</color>
|
|
||||||
<color name="black">#FF000000</color>
|
|
||||||
<color name="white">#FFFFFFFF</color>
|
|
||||||
</resources>
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<style name="Theme.ToDo" parent="android:Theme.Material.Light.NoActionBar">
|
||||||
<style name="Theme.ToDo" parent="android:Theme.Material.Light.NoActionBar" />
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -13,6 +13,8 @@ navigation = "2.8.5"
|
||||||
material3 = "1.4.0-alpha05"
|
material3 = "1.4.0-alpha05"
|
||||||
# AboutLibraries
|
# AboutLibraries
|
||||||
aboutLibsRelease = "11.3.0-rc02"
|
aboutLibsRelease = "11.3.0-rc02"
|
||||||
|
# M3 Color
|
||||||
|
m3color = "2024.6"
|
||||||
# Kotlin
|
# Kotlin
|
||||||
kotlinCoroutines = "1.9.0"
|
kotlinCoroutines = "1.9.0"
|
||||||
# Test
|
# Test
|
||||||
|
|
@ -57,6 +59,9 @@ androidx-room-runtime = { group = "androidx.room", name = "room-runtime", versio
|
||||||
aboutlibraries-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "aboutLibsRelease" }
|
aboutlibraries-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "aboutLibsRelease" }
|
||||||
aboutlibraries-compose = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "aboutLibsRelease" }
|
aboutlibraries-compose = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "aboutLibsRelease" }
|
||||||
|
|
||||||
|
# M3 Color
|
||||||
|
com-kyant0-m3color = { group = "com.github.Kyant0", name = "m3color", version.ref = "m3color" }
|
||||||
|
|
||||||
# Kotlin
|
# Kotlin
|
||||||
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinCoroutines" }
|
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinCoroutines" }
|
||||||
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinCoroutines" }
|
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinCoroutines" }
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ dependencyResolutionManagement {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven("https://jitpack.io")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue