diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 1a78f45..775791a 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -64,6 +64,8 @@ dependencies {
// About Libraries
implementation(libs.aboutlibraries.core)
implementation(libs.aboutlibraries.compose)
+ // M3 Color
+ implementation(libs.com.kyant0.m3color)
// Kotlin Coroutines
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.coroutines.android)
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Color.kt b/app/src/main/kotlin/cn/super12138/todo/ui/theme/Color.kt
deleted file mode 100644
index 9233036..0000000
--- a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Color.kt
+++ /dev/null
@@ -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)
\ No newline at end of file
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/theme/PaletteStyle.kt b/app/src/main/kotlin/cn/super12138/todo/ui/theme/PaletteStyle.kt
new file mode 100644
index 0000000..73158c7
--- /dev/null
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/theme/PaletteStyle.kt
@@ -0,0 +1,13 @@
+package cn.super12138.todo.ui.theme
+
+enum class PaletteStyle {
+ TonalSpot,
+ Neutral,
+ Vibrant,
+ Expressive,
+ Rainbow,
+ FruitSalad,
+ Monochrome,
+ Fidelity,
+ Content,
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Theme.kt b/app/src/main/kotlin/cn/super12138/todo/ui/theme/Theme.kt
index 0ff3880..cfbd8c7 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Theme.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/theme/Theme.kt
@@ -1,55 +1,38 @@
package cn.super12138.todo.ui.theme
-import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
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.ui.platform.LocalContext
-
-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),
- */
-)
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.colorResource
@Composable
fun ToDoTheme(
+ color: Color? = null,
darkTheme: Boolean = isSystemInDarkTheme(),
+ style: PaletteStyle = PaletteStyle.TonalSpot,
+ contrastLevel: Double = 0.0,
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
- val colorScheme = when {
- dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
- val context = LocalContext.current
- if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
- }
-
- darkTheme -> DarkColorScheme
- else -> LightColorScheme
+ val baseColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && dynamicColor) {
+ colorResource(id = android.R.color.system_accent1_500)
+ } else {
+ Color(0xFF0061A4)
}
+ // 关键色,如果指定就使用
+ val keyColor = color ?: baseColor
+
+ val colorScheme = dynamicColorScheme(
+ keyColor = keyColor,
+ isDark = darkTheme,
+ style = style,
+ contrastLevel = contrastLevel
+ )
+
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/theme/ThemeExt.kt b/app/src/main/kotlin/cn/super12138/todo/ui/theme/ThemeExt.kt
new file mode 100644
index 0000000..41d520a
--- /dev/null
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/theme/ThemeExt.kt
@@ -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)
\ No newline at end of file
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Type.kt b/app/src/main/kotlin/cn/super12138/todo/ui/theme/Type.kt
index c25d260..265850d 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/theme/Type.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/theme/Type.kt
@@ -1,34 +1,5 @@
package cn.super12138.todo.ui.theme
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(
- 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
- )
- */
-)
\ No newline at end of file
+val Typography = Typography()
\ No newline at end of file
diff --git a/app/src/main/res/values-night-v27/themes.xml b/app/src/main/res/values-night-v27/themes.xml
new file mode 100644
index 0000000..9dfe26c
--- /dev/null
+++ b/app/src/main/res/values-night-v27/themes.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night-v29/themes.xml b/app/src/main/res/values-night-v29/themes.xml
new file mode 100644
index 0000000..6dee08e
--- /dev/null
+++ b/app/src/main/res/values-night-v29/themes.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
new file mode 100644
index 0000000..ef6bd95
--- /dev/null
+++ b/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-v27/themes.xml b/app/src/main/res/values-v27/themes.xml
new file mode 100644
index 0000000..60b6d70
--- /dev/null
+++ b/app/src/main/res/values-v27/themes.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml
new file mode 100644
index 0000000..41d0610
--- /dev/null
+++ b/app/src/main/res/values-v29/themes.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
deleted file mode 100644
index f8c6127..0000000
--- a/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- #FFBB86FC
- #FF6200EE
- #FF3700B3
- #FF03DAC5
- #FF018786
- #FF000000
- #FFFFFFFF
-
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 4ac2d6f..3597c13 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,5 +1,8 @@
-
-
+
\ No newline at end of file
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 44271e0..7278d29 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -13,6 +13,8 @@ navigation = "2.8.5"
material3 = "1.4.0-alpha05"
# AboutLibraries
aboutLibsRelease = "11.3.0-rc02"
+# M3 Color
+m3color = "2024.6"
# Kotlin
kotlinCoroutines = "1.9.0"
# 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-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
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" }
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 5d1c1f1..f9b1b8c 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -16,6 +16,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
+ maven("https://jitpack.io")
}
}