Last active
November 25, 2022 22:16
-
-
Save joreilly/29a5882bbe48e328d65ef3d46e1240b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun generateDynamicColorSchemeFile(darkTheme: Boolean, context: Context) { | |
val colorScheme = if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) | |
val file = FileSpec.builder("", "Colors") | |
.addCclorProperty("md_theme_light_primary", colorScheme.primary) | |
.addCclorProperty("md_theme_light_onPrimary", colorScheme.onPrimary) | |
.addCclorProperty("md_theme_light_primaryContainer", colorScheme.primaryContainer) | |
.addCclorProperty("md_theme_light_onPrimaryContainer", colorScheme.onPrimaryContainer) | |
.addCclorProperty("md_theme_light_secondary", colorScheme.secondary) | |
.addCclorProperty("md_theme_light_onSecondary", colorScheme.onSecondary) | |
.addCclorProperty("md_theme_light_secondaryContainer", colorScheme.secondaryContainer) | |
.addCclorProperty("md_theme_light_onSecondaryContainer", colorScheme.onSecondaryContainer) | |
.addCclorProperty("md_theme_light_tertiary", colorScheme.tertiary) | |
.addCclorProperty("md_theme_light_onTertiary", colorScheme.onTertiary) | |
.addCclorProperty("md_theme_light_tertiaryContainer", colorScheme.tertiaryContainer) | |
.addCclorProperty("md_theme_light_onTertiaryContainer", colorScheme.onTertiaryContainer) | |
.addCclorProperty("md_theme_light_error", colorScheme.error) | |
.addCclorProperty("md_theme_light_errorContainer", colorScheme.errorContainer) | |
.addCclorProperty("md_theme_light_onError", colorScheme.onError) | |
.addCclorProperty("md_theme_light_onErrorContainer", colorScheme.onErrorContainer) | |
.addCclorProperty("md_theme_light_background", colorScheme.background) | |
.addCclorProperty("md_theme_light_onBackground", colorScheme.onBackground) | |
.addCclorProperty("md_theme_light_surface", colorScheme.surface) | |
.addCclorProperty("md_theme_light_onSurface", colorScheme.onSurface) | |
.addCclorProperty("md_theme_light_surfaceVariant", colorScheme.surfaceVariant) | |
.addCclorProperty("md_theme_light_onSurfaceVariant", colorScheme.onSurfaceVariant) | |
.addCclorProperty("md_theme_light_outline", colorScheme.outline) | |
.addCclorProperty("md_theme_light_inverseOnSurface", colorScheme.inverseOnSurface) | |
.addCclorProperty("md_theme_light_inverseSurface", colorScheme.inverseSurface) | |
.addCclorProperty("md_theme_light_inversePrimary", colorScheme.inversePrimary) | |
.addCclorProperty("md_theme_light_surfaceTint", colorScheme.surfaceTint) | |
.build() | |
context.getExternalFilesDir("")?.let { | |
file.writeTo(it) | |
} | |
} | |
private fun FileSpec.Builder.addCclorProperty(propertyName: String, color: Color): FileSpec.Builder { | |
val colorInitializer = "Color(${color.red}f, ${color.green}f, ${color.blue}f, ${color.alpha}f)" | |
val propertySpec = PropertySpec.builder(propertyName, Color::class, KModifier.INTERNAL) | |
.initializer(colorInitializer) | |
.build() | |
return addProperty(propertySpec) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment