### User Profile Dynamic Theme Example Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/image-bitmap-extensions.md Shows how to create a dynamic theme for a user profile screen using two colors extracted from the user's image. It uses `rememberThemeColors` to get multiple colors and applies them to the theme. ```kotlin @Composable fun UserProfileScreen(userId: String) { val userImage = remember { loadUserProfileImage(userId) } val colors = rememberThemeColors( image = userImage, desired = 2 ) val primaryColor = colors.getOrNull(0) ?: Color.Blue val secondaryColor = colors.getOrNull(1) ?: Color.Gray DynamicMaterialTheme( seedColor = primaryColor, secondary = secondaryColor ) { UserProfileContent(userImage) } } ``` -------------------------------- ### Direct Color Access Example Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Demonstrates how to instantiate MaterialKolors and access primary and background colors. ```kotlin val scheme = DynamicScheme( seedColor = Color.Blue, isDark = true, style = PaletteStyle.TonalSpot, ) val kolors = MaterialKolors(scheme, isAmoled = true) val primaryColor = kolors.primary() val backgroundColor = kolors.background() ``` -------------------------------- ### Usage Example for Static Hue Classification Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/hct-color-space.md Demonstrates how to use the static helper methods to check if a hue is in the blue range and print a message. ```kotlin val hue = 260.0 if (Hct.isBlue(hue)) { println("This is a blue color") } ``` -------------------------------- ### Usage Example: Compose Color to HCT Conversion Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/hct-color-space.md Shows how to convert a Compose Color to HCT and print its hue, chroma, and tone values. ```kotlin val composeColor = Color(0xFF6750A4) val hct = composeColor.toHct() println("Hue: ${hct.hue}, Chroma: ${hct.chroma}, Tone: ${hct.tone}") ``` -------------------------------- ### Album Art Based Theme Example Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/image-bitmap-extensions.md Demonstrates how to create a dynamic Material Theme using an album art image. It extracts a primary color from the album art and applies it as the seed color for the theme. ```kotlin @Composable fun AlbumArtTheme(albumArt: ImageBitmap) { val primaryColor = rememberThemeColor( image = albumArt, fallback = Color.Gray ) DynamicMaterialTheme( seedColor = primaryColor, isDark = isSystemInDarkTheme() ) { Column( modifier = Modifier .fillMaxSize() .background(MaterialTheme.colorScheme.background) ) { Image( bitmap = albumArt, contentDescription = "Album art", modifier = Modifier .fillMaxWidth() .aspectRatio(1f), contentScale = ContentScale.Crop ) Text( "Song Title", color = MaterialTheme.colorScheme.primary ) } } } ``` -------------------------------- ### DynamicMaterialTheme Usage Example (State Variant) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-material-theme.md Demonstrates how to use the state variant of DynamicMaterialTheme. It shows how to create and remember a theme state, apply it to the composable, and dynamically change the seed color of the theme by updating the state. ```kotlin @Composable fun ThemedApp() { val themeState = rememberDynamicMaterialThemeState( seedColor = Color.Blue, isDark = false, ) DynamicMaterialTheme( state = themeState, animate = true, content = { // Access theme colors from MaterialTheme Button( onClick = { themeState.seedColor = Color.Red } ) { Text("Change Theme") } } ) } ``` -------------------------------- ### Get Surface Bright Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the brightest surface color. ```kotlin public fun surfaceBright(): Color ``` -------------------------------- ### Dynamic Material Theme State Updates Example Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-material-theme.md Demonstrates how to update properties of a `DynamicMaterialThemeState` to dynamically change the theme. This includes toggling dark mode, changing the style, and updating the seed color. ```kotlin @Composable fun ThemeSwitcher() { val themeState = rememberDynamicMaterialThemeState( seedColor = Color.Blue, isDark = false, ) DynamicMaterialTheme(state = themeState) { Row( modifier = Modifier .fillMaxWidth() .padding(16.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Button(onClick = { themeState.isDark = !themeState.isDark }) { Text("Toggle Dark Mode") } Button(onClick = { themeState.style = PaletteStyle.Vibrant }) { Text("Make Vibrant") } Button(onClick = { themeState.seedColor = Color.Red }) { Text("Red Theme") } } } } ``` -------------------------------- ### Converting Between Color Spaces Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/README.md Illustrates converting a standard RGB color to the HCT (Hue, Chroma, Tone) color space and then manipulating it. The example converts to HCT, shifts the hue, and converts back to an RGB color. ```kotlin import androidx.compose.ui.graphics.Color val color = Color(0xFF6750A4) val hct = color.toHct() val shifted = hct.withHue(200.0).toColor() ``` -------------------------------- ### App UI with DynamicMaterialTheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-material-theme.md Example of how to wrap your application's UI with DynamicMaterialTheme using a specific seed color and system dark theme preference. This sets up the Material Theme for the entire app. ```kotlin @Composable fun App() { DynamicMaterialTheme( seedColor = Color(0xFF6750A4), isDark = isSystemInDarkTheme(), ) { // Your app UI Scaffold( topBar = { TopAppBar(title = { Text("My App") }) } ) { padding -> Text("Hello, World!", modifier = Modifier.padding(padding)) } } } ``` -------------------------------- ### Accessibility-First Application with High Contrast Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Use `Contrast.High.value` to ensure all text and UI elements have maximum accessibility. This is ideal for applications prioritizing accessibility from the start. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.foundation.isSystemInDarkTheme @Composable fun AccessibleApp() { DynamicMaterialTheme( seedColor = Color.Blue, isDark = isSystemInDarkTheme(), contrastLevel = Contrast.High.value // Maximum accessibility ) { // All text and UI elements will have excellent contrast } } ``` -------------------------------- ### Usage Example: HCT to Compose Color Conversion Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/hct-color-space.md Demonstrates converting an HCT color (created from hue, chroma, and tone) back to a Compose Color. ```kotlin val hct = Hct.from(260.0, 80.0, 50.0) val color = hct.toColor() // Ready for use in Compose UI ``` -------------------------------- ### Create DynamicScheme with Custom Colors Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Example of creating a DynamicScheme, forcing a specific red color for the primary palette while allowing other palettes to be generated. The style is set to Vibrant. ```kotlin fun createTheme(seedColor: Color): DynamicScheme { return DynamicScheme( seedColor = seedColor, isDark = true, primary = Color(0xFFFF0000), // Force red primary style = PaletteStyle.Vibrant ) } ``` -------------------------------- ### Get On Secondary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to be used on secondary surfaces. Ensures text and icons are legible on secondary color backgrounds. ```kotlin public fun onSecondary(): Color ``` -------------------------------- ### Get Shadow Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the shadow color. ```kotlin public fun shadow(): Color ``` -------------------------------- ### Get Scrim Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the scrim color, which is a semi-transparent overlay. ```kotlin public fun scrim(): Color ``` -------------------------------- ### Get On Primary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to be used on primary surfaces, such as text or icons. Ensures contrast and readability against the primary color. ```kotlin public fun onPrimary(): Color ``` -------------------------------- ### Get Outline Variant Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the variant outline color. ```kotlin public fun outlineVariant(): Color ``` -------------------------------- ### Get Outline Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the outline color for borders and dividers. ```kotlin public fun outline(): Color ``` -------------------------------- ### Project Structure Overview Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/MANIFEST.md This snippet illustrates the directory structure of the generated documentation for the MaterialKolor library. ```tree output/ ├── README.md (Main index and overview) ├── configuration.md (Configuration reference) ├── types.md (Type definitions and enums) └── api-reference/ (Detailed API documentation) ├── dynamic-color-scheme.md (Color scheme generation) ├── dynamic-material-theme.md (Theme composables) ├── dynamic-scheme-extensions.md (DynamicScheme utilities) ├── color-extensions.md (Color manipulation) ├── harmonize-extensions.md (Color harmonization) ├── blend-extensions.md (Color blending) ├── temperature-extensions.md (Color temperature analysis) ├── image-bitmap-extensions.md (Image color extraction) ├── material-kolors-class.md (Material color tokens) ├── palette-style.md (Palette style enum) ├── contrast.md (Contrast enum) └── hct-color-space.md (HCT color space reference) ``` -------------------------------- ### Get Surface Dim Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the dimmest surface color. ```kotlin public fun surfaceDim(): Color ``` -------------------------------- ### Get Inverse Surface Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the inverse surface color. ```kotlin public fun inverseSurface(): Color ``` -------------------------------- ### Dynamic Theme Style Showcase Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/palette-style.md Demonstrate all available palette styles by iterating through them and applying each to a theme. This is useful for visualizing the effect of each style with a given seed color. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.foundation.layout.Column import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.ui.graphics.Color import com.materialkolor.android.DynamicMaterialTheme import com.materialkolor.android.PaletteStyle @Composable fun StyleShowcase(seedColor: Color) { Column { PaletteStyle.values().forEach { style -> DynamicMaterialTheme( seedColor = seedColor, isDark = false, style = style ) { Text("${style.name} Style", color = MaterialTheme.colorScheme.primary) } } } } ``` -------------------------------- ### Get Surface Variant Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the variant surface color. ```kotlin public fun surfaceVariant(): Color ``` -------------------------------- ### Get Surface Container Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the standard container surface color. ```kotlin public fun surfaceContainer(): Color ``` -------------------------------- ### Demonstrate matchSaturation Parameter Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/harmonize-extensions.md Illustrates the effect of the `matchSaturation` parameter when harmonizing colors. Set to true to also match the saturation level of the target color. ```kotlin val brandColor = Color(0xFF6750A4) // Saturated purple val desaturatedRed = Color(0xFFBB6666) // Less saturated red // Without matchSaturation: Red hue with original desaturated saturation val result1 = desaturatedRed.harmonize(brandColor, matchSaturation = false) // With matchSaturation: Red hue with brand's saturation level val result2 = desaturatedRed.harmonize(brandColor, matchSaturation = true) ``` -------------------------------- ### Accessibility-First Configuration with High Contrast Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/configuration.md Optimize for users with vision impairments by using a monochrome style and adjusting the contrast level based on user preferences for high contrast. ```kotlin @Composable fun AccessibleApp(userPreferences: AccessibilityPreferences) { rememberDynamicColorScheme( seedColor = Color.Blue, isDark = true, style = PaletteStyle.Monochrome, // No hue variation contrastLevel = if (userPreferences.highContrast) 1.0 else 0.0 ) } ``` -------------------------------- ### Get Inverse On Surface Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to use on inverse surfaces. ```kotlin public fun inverseOnSurface(): Color ``` -------------------------------- ### Live Contrast Preview with Multiple Levels Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Displays a visual comparison of different contrast levels (Reduced, Default, Medium, High) applied to sample text and UI elements. This allows users or developers to see the impact of each contrast setting. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp @Composable fun ContrastComparison() { val contrasts = listOf( Contrast.Reduced, Contrast.Default, Contrast.Medium, Contrast.High ) Column( modifier = Modifier .fillMaxWidth() .padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp) ) { contrasts.forEach { contrast -> DynamicMaterialTheme( seedColor = Color.Blue, isDark = false, contrastLevel = contrast.value ) { Box( modifier = Modifier .fillMaxWidth() .background(MaterialTheme.colorScheme.background) .padding(16.dp) ) { Column { Text( "${contrast.name} Contrast (${contrast.value})", color = MaterialTheme.colorScheme.onBackground, style = MaterialTheme.typography.titleMedium ) Text( "Sample text with primary color", color = MaterialTheme.colorScheme.primary ) Text( "Sample text with secondary color", color = MaterialTheme.colorScheme.secondary ) } } } } } } ``` -------------------------------- ### Get Neutral Palette Key Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the key color for the neutral palette. ```kotlin public fun neutralPaletteKeyColor(): Color ``` -------------------------------- ### Get On Surface Variant Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to use on surface variant elements. ```kotlin public fun onSurfaceVariant(): Color ``` -------------------------------- ### Get Error Palette Key Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the key color for the error palette. ```kotlin public fun errorPaletteKeyColor(): Color ``` -------------------------------- ### Get Surface Container Highest Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the highest emphasis container surface color. ```kotlin public fun surfaceContainerHighest(): Color ``` -------------------------------- ### Adjust Contrast Level in Real-time with DynamicMaterialThemeState Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Demonstrates how to dynamically adjust the contrast level of a Material Design theme using `DynamicMaterialThemeState`. This allows users to select their preferred contrast setting. ```kotlin @Composable fun ContrastAdjuster() { val state = rememberDynamicMaterialThemeState( seedColor = Color.Blue, isDark = false ) DynamicMaterialTheme(state = state) { Row( modifier = Modifier .fillMaxWidth() .padding(16.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { listOf( Contrast.Reduced, Contrast.Default, Contrast.Medium, Contrast.High ).forEach { contrast -> Button(onClick = { state.contrastLevel = contrast.value }) { Text(contrast.name) } } } } } ``` -------------------------------- ### Get Surface Container High Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the high emphasis container surface color. ```kotlin public fun surfaceContainerHigh(): Color ``` -------------------------------- ### Apply Dynamic Color Scheme within Theme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Demonstrates how to use `rememberDynamicColorScheme` to generate a color scheme and apply it to your MaterialTheme in Compose. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.material3.MaterialTheme import androidx.compose.material3.rememberDynamicColorScheme @Composable fun MyApp() { val scheme = rememberDynamicColorScheme( seedColor = Color.Blue, isDark = false ) MaterialTheme(colorScheme = scheme) { // The ColorScheme is derived from MaterialKolors // Colors are automatically applied } } ``` -------------------------------- ### Get Surface Container Lowest Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the lowest emphasis container surface color. ```kotlin public fun surfaceContainerLowest(): Color ``` -------------------------------- ### Get Surface Container Low Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the low emphasis container surface color. ```kotlin public fun surfaceContainerLow(): Color ``` -------------------------------- ### Manually Generate Color Scheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Shows how to manually generate a `ColorScheme` by using `MaterialKolors` with a `DynamicScheme` and injecting the computed colors. ```kotlin import androidx.compose.material3.ColorScheme import androidx.compose.ui.graphics.Color import androidx.compose.material3.dynamicColorScheme import androidx.compose.material3.PaletteStyle fun generateColorScheme(seedColor: Color, isDark: Boolean): ColorScheme { val dynamicScheme = DynamicScheme( seedColor = seedColor, isDark = isDark, style = PaletteStyle.Vibrant, ) val kolors = MaterialKolors(dynamicScheme) return ColorScheme( primary = kolors.primary(), secondary = kolors.secondary(), tertiary = kolors.tertiary(), surface = kolors.surface(), background = kolors.background(), // ... all other color slots ) } ``` -------------------------------- ### Get Primary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the primary color from the MaterialKolors instance. This is a fundamental color for the theme. ```kotlin public fun primary(): Color ``` -------------------------------- ### Apply Medium Contrast Theme with DynamicMaterialTheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Applies a Material Design theme with a medium contrast level using the `DynamicMaterialTheme` composable. This offers a good balance between accessibility and design aesthetics. ```kotlin @Composable fun App() { DynamicMaterialTheme( seedColor = Color.Blue, isDark = false, contrastLevel = Contrast.Medium.value ) { // Content } } ``` -------------------------------- ### Composable Color Picker with Dynamic Scheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Demonstrates a Jetpack Compose UI for selecting a seed color and tone to generate a dynamic color scheme. Use this to visually explore color variations. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.tooling.preview.Preview import io.material.colors.DynamicScheme import io.material.colors.PaletteStyle import io.material.colors.rememberDynamicScheme // Helper extension function to convert Color to Hex String (assuming it exists) fun Color.toHex(): String { // Implementation depends on how Color is represented (e.g., ARGB) // For simplicity, returning a placeholder return "#${Integer.toHexString(this.hashCode()).substring(0, 6)}" } @Composable fun PaletteColorPicker() { var seedColor by remember { mutableStateOf(Color.Blue) } var selectedTone by remember { mutableStateOf(50) } val scheme = rememberDynamicScheme( seedColor = seedColor, isDark = false ) Column(modifier = Modifier.padding(16.dp)) { // Seed color selector TextField( value = seedColor.toHex(), onValueChange = { /* Parse hex */ }, label = { Text("Seed Color") } ) // Tone slider Slider( value = selectedTone.toFloat(), onValueChange = { selectedTone = it.toInt() }, valueRange = 0f..100f, modifier = Modifier.fillMaxWidth() ) // Color display Box( modifier = Modifier .fillMaxWidth() .height(100.dp) .background(Color(scheme.primaryPalette.tone(selectedTone))) ) // Show color value Text("Tone $selectedTone: ${Color(scheme.primaryPalette.tone(selectedTone)).toHex()}") } } ``` -------------------------------- ### Get Control Highlight Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color for highlighted control elements. This is specific to Android. ```kotlin public fun controlHighlight(): Color ``` -------------------------------- ### DynamicScheme Constructor (KTX Variant) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Constructs a DynamicScheme with custom color palettes from Colors. This constructor allows for fine-grained control over primary, secondary, tertiary, neutral, and error colors, as well as style, contrast, and platform specifications. ```kotlin public fun DynamicScheme( seedColor: Color, isDark: Boolean, primary: Color? = null, secondary: Color? = null, tertiary: Color? = null, neutral: Color? = null, neutralVariant: Color? = null, error: Color? = null, style: PaletteStyle = TonalSpot, contrastLevel: Double = Contrast.Default.value, specVersion: ColorSpec.SpecVersion = ColorSpec.SpecVersion.Default, platform: DynamicScheme.Platform = DynamicScheme.Platform.Default, ): DynamicScheme ``` -------------------------------- ### Get Control Normal Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color for normal control elements. This is specific to Android. ```kotlin public fun controlNormal(): Color ``` -------------------------------- ### DynamicScheme Constructor (KTX Variant) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Creates a DynamicScheme instance with custom color palettes from Colors. This constructor allows for fine-grained control over the generated color scheme by providing specific color overrides. ```APIDOC ## DynamicScheme Constructor (KTX Variant) ### Description Creates a DynamicScheme with custom color palettes from Colors. ### Method `public fun DynamicScheme( seedColor: Color, isDark: Boolean, primary: Color? = null, secondary: Color? = null, tertiary: Color? = null, neutral: Color? = null, neutralVariant: Color? = null, error: Color? = null, style: PaletteStyle = TonalSpot, contrastLevel: Double = Contrast.Default.value, specVersion: ColorSpec.SpecVersion = ColorSpec.SpecVersion.Default, platform: DynamicScheme.Platform = DynamicScheme.Platform.Default, ): DynamicScheme ### Parameters * **seedColor** (Color) - Required - The seed color used to generate the dynamic color scheme. * **isDark** (Boolean) - Required - Whether the scheme is for a dark or light theme. * **primary** (Color?) - Optional - A custom primary color to override the generated one. * **secondary** (Color?) - Optional - A custom secondary color to override the generated one. * **tertiary** (Color?) - Optional - A custom tertiary color to override the generated one. * **neutral** (Color?) - Optional - A custom neutral color to override the generated one. * **neutralVariant** (Color?) - Optional - A custom neutral variant color to override the generated one. * **error** (Color?) - Optional - A custom error color to override the generated one. * **style** (PaletteStyle) - Optional - The style of the palette (e.g., TonalSpot, Vibrant). Defaults to TonalSpot. * **contrastLevel** (Double) - Optional - The desired contrast level. Defaults to `Contrast.Default.value`. * **specVersion** (ColorSpec.SpecVersion) - Optional - The color specification version. Defaults to `ColorSpec.SpecVersion.Default`. * **platform** (DynamicScheme.Platform) - Optional - The target platform. Defaults to `DynamicScheme.Platform.Default`. ### Returns `DynamicScheme` - The dynamic scheme (not remembered). ### Usage Example ```kotlin fun createTheme(seedColor: Color): DynamicScheme { return DynamicScheme( seedColor = seedColor, isDark = true, primary = Color(0xFFFF0000), // Force red primary style = PaletteStyle.Vibrant ) } ``` ``` -------------------------------- ### Get Control Activated Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color for activated control elements. This is specific to Android. ```kotlin public fun controlActivated(): Color ``` -------------------------------- ### Get Neutral Variant Palette Key Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the key color for the neutral variant palette. ```kotlin public fun neutralVariantPaletteKeyColor(): Color ``` -------------------------------- ### Generate Color Scheme with Vibrant Style Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/palette-style.md Demonstrates how to generate a color scheme using the `dynamicColorScheme` function with the `PaletteStyle.Vibrant` setting. Requires seed color, dark mode preference, and style. ```kotlin val scheme = dynamicColorScheme( seedColor = Color(0xFF6750A4), isDark = false, style = PaletteStyle.Vibrant ) ``` -------------------------------- ### Get Surface Tint Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the surface tint color, which is the primary color tinted into surfaces. ```kotlin public fun surfaceTint(): Color ``` -------------------------------- ### Create Color Gradient using Blend Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/blend-extensions.md Demonstrates creating a visual color gradient by repeatedly applying the `blend` function with increasing amounts. This is useful for UI elements requiring smooth color transitions. ```kotlin @Composable fun ColorGradient() { val colorA = Color(0xFF6750A4) val colorB = Color(0xFFFFB000) Row(modifier = Modifier.fillMaxWidth()) { repeat(11) { val amount = index / 10f val color = colorA.blend(colorB, amount) Box( modifier = Modifier .weight(1f) .height(50.dp) .background(color) ) } } } ``` -------------------------------- ### Get Surface Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the surface color. Returns pure black on AMOLED in dark mode. ```kotlin public fun surface(): Color ``` -------------------------------- ### MaterialKolors Constructor Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Initializes the MaterialKolors class with a dynamic scheme and an optional AMOLED setting. ```APIDOC ## MaterialKolors Constructor ### Description Initializes the MaterialKolors class with a dynamic scheme and an optional AMOLED setting. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```kotlin public class MaterialKolors(private val scheme: DynamicScheme, private val isAmoled: Boolean = false) ``` ### Parameters - **scheme** (DynamicScheme) - Required - The dynamic scheme to generate colors from - **isAmoled** (Boolean) - Optional - Whether to use pure black for AMOLED displays (default: false) ``` -------------------------------- ### Get Background Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the background color. Returns pure black on AMOLED in dark mode. ```kotlin public fun background(): Color ``` -------------------------------- ### Manually Build Custom Theme ColorScheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Constructs a `ColorScheme` object manually by extracting specific tones from a `DynamicScheme`. Use this for fine-grained control over theme colors. ```kotlin import androidx.compose.material3.ColorScheme import androidx.compose.ui.graphics.Color import io.material.colors.DynamicScheme import io.material.colors.PaletteStyle fun buildCustomTheme( seedColor: Color, isDark: Boolean, brandPrimary: Color? = null ): ColorScheme { val scheme = DynamicScheme( seedColor = seedColor, isDark = isDark, primary = brandPrimary, // Override primary if provided style = PaletteStyle.Fidelity ) // Manually construct ColorScheme from palettes return ColorScheme( primary = Color(scheme.primaryPalette.tone(if (isDark) 80 else 40)), onPrimary = Color(scheme.primaryPalette.tone(if (isDark) 20 else 100)), primaryContainer = Color(scheme.primaryPalette.tone(if (isDark) 30 else 90)), onPrimaryContainer = Color(scheme.primaryPalette.tone(if (isDark) 90 else 10)), secondary = Color(scheme.secondaryPalette.tone(if (isDark) 80 else 40)), onSecondary = Color(scheme.secondaryPalette.tone(if (isDark) 20 else 100)), secondaryContainer = Color(scheme.secondaryPalette.tone(if (isDark) 30 else 90)), onSecondaryContainer = Color(scheme.secondaryPalette.tone(if (isDark) 90 else 10)), // ... continue for all color slots ) } ``` -------------------------------- ### Get Error Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the error color. This color is used to indicate errors or warnings in the UI. ```kotlin public fun error(): Color ``` -------------------------------- ### Get Highest Surface Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the highest surface color based on the provided dynamic scheme configuration. ```kotlin public fun highestSurface(scheme: DynamicScheme): Color ``` -------------------------------- ### Creating an Accessible Theme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/README.md Illustrates how to create an accessible Material Design 3 color scheme using MaterialKolor, specifying a seed color, dark mode, monochrome style, and high contrast. ```kotlin import com.materialkolor.compose.rememberDynamicColorScheme import com.materialkolor.model.Contrast import com.materialkolor.model.PaletteStyle import androidx.compose.ui.graphics.Color rememberDynamicColorScheme( seedColor = Color.Blue, isDark = true, style = PaletteStyle.Monochrome, contrastLevel = Contrast.High.value ) ``` -------------------------------- ### Create Temperature Cache Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/temperature-extensions.md Instantiate `TemperatureCache` with an input `Color` to create a cache object. This cache can then be used to compute complementary and analogous colors. ```kotlin public fun TemperatureCache(input: Color): TemperatureCache ``` ```kotlin val baseColor = Color(0xFF6750A4) val cache = TemperatureCache(baseColor) // The cache can be used to find complementary and analogous colors // (See Material Design color utilities documentation for more details) ``` -------------------------------- ### Get On Surface Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to use on surface elements. Returns white on AMOLED in dark mode. ```kotlin public fun onSurface(): Color ``` -------------------------------- ### Interactive Color Mixer with Blend Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/blend-extensions.md Demonstrates an interactive color mixer using `blend` to interpolate between two base colors based on a slider's value. This allows for real-time visualization of color blending. ```kotlin @Composable fun ColorMixer() { var blendAmount by remember { mutableStateOf(0.5f) } val colorA = Color(0xFF6750A4) // Purple val colorB = Color(0xFFFFB000) // Gold val mixed = colorA.blend(colorB, blendAmount) Column( modifier = Modifier .fillMaxWidth() .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { // Display colors Row( modifier = Modifier .fillMaxWidth() .height(100.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Box(modifier = Modifier .weight(1f) .background(colorA)) Box(modifier = Modifier .weight(1f) .background(mixed)) Box(modifier = Modifier .weight(1f) .background(colorB)) } // Blend slider Slider( value = blendAmount, onValueChange = { blendAmount = it }, modifier = Modifier.fillMaxWidth(), valueRange = 0f..1f ) Text("Blend: ${(blendAmount * 100).toInt()}%") } } ``` -------------------------------- ### Get On Background Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the color to use on background surfaces. Returns white on AMOLED in dark mode. ```kotlin public fun onBackground(): Color ``` -------------------------------- ### Contrast-Aware Theme Selection Based on User Type Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Dynamically adjusts the contrast level based on user attributes like high contrast mode preference or age. This ensures an appropriate visual experience for different user segments. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color @Composable fun SmartThemeApp(userPreferences: UserPreferences) { val contrastLevel = when { userPreferences.highContrastMode -> Contrast.High.value userPreferences.isOlderUser -> Contrast.Medium.value else -> Contrast.Default.value } DynamicMaterialTheme( seedColor = userPreferences.themeColor, isDark = userPreferences.darkMode, contrastLevel = contrastLevel ) { // App content } } ``` -------------------------------- ### Get Tertiary Fixed Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the fixed tertiary color. This color is constant and does not change with theme variants. ```kotlin public fun tertiaryFixed(): Color ``` -------------------------------- ### Get Secondary Fixed Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the fixed secondary color. This color is constant and does not change with theme variants. ```kotlin public fun secondaryFixed(): Color ``` -------------------------------- ### Apply Expressive Style with DynamicMaterialTheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/palette-style.md Shows how to apply the `PaletteStyle.Expressive` to the `DynamicMaterialTheme` composable. Requires seed color, dark mode preference, and style. ```kotlin @Composable fun App() { DynamicMaterialTheme( seedColor = Color.Blue, isDark = false, style = PaletteStyle.Expressive ) { // Content } } ``` -------------------------------- ### Get Inverse Primary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the inverse primary color. This is typically used on inverse surfaces for contrast. ```kotlin public fun inversePrimary(): Color ``` -------------------------------- ### Access Palette Key Colors Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Illustrates how to retrieve specific palette key colors like primary, secondary, and error from a `MaterialKolors` instance. ```kotlin import androidx.compose.ui.graphics.Color import androidx.compose.material3.dynamicColorScheme import androidx.compose.material3.PaletteStyle fun getPaletteKeyColors(seedColor: Color): Map { val scheme = DynamicScheme( seedColor = seedColor, isDark = false, style = PaletteStyle.TonalSpot, ) val kolors = MaterialKolors(scheme) return mapOf( "primary" to kolors.primaryPaletteKeyColor(), "secondary" to kolors.secondaryPaletteKeyColor(), "tertiary" to kolors.tertiaryPaletteKeyColor(), "error" to kolors.errorPaletteKeyColor(), "neutral" to kolors.neutralPaletteKeyColor(), "neutralVariant" to kolors.neutralVariantPaletteKeyColor(), ) } ``` -------------------------------- ### Generate Color Scheme with Direct Numeric Contrast Value Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/contrast.md Shows how to use a direct numeric value for the contrast level when generating a color scheme with `dynamicColorScheme`. This provides flexibility for custom contrast settings. ```kotlin // You can also use the numeric values directly val scheme = dynamicColorScheme( seedColor = Color.Blue, isDark = false, contrastLevel = 0.5 // Medium contrast ) ``` -------------------------------- ### Get Text Hint Inverse Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the hint text color on inverse backgrounds. This is specific to Android. ```kotlin public fun textHintInverse(): Color ``` -------------------------------- ### Get Text Primary Inverse Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the primary text color on inverse backgrounds. This is specific to Android. ```kotlin public fun textPrimaryInverse(): Color ``` -------------------------------- ### Configure Target Platform for Color Scheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/configuration.md Optimize color schemes for different device types like phones or wearables. Defaults to PHONE. ```kotlin val phoneScheme = rememberDynamicColorScheme( seedColor = Color.Blue, isDark = false, platform = DynamicScheme.Platform.PHONE ) ``` ```kotlin val watchScheme = rememberDynamicColorScheme( seedColor = Color.Blue, isDark = false, platform = DynamicScheme.Platform.WATCH ) ``` -------------------------------- ### Get Error Container Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the error container color. This color is used for elements that contain error-colored content. ```kotlin public fun errorContainer(): Color ``` -------------------------------- ### Basic Dynamic Material Theme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/README.md Create a basic dynamic Material Design 3 theme using a seed color and system dark theme preference. This is suitable for most common use cases. ```kotlin import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import io.github.alexzhirnov.materialkolor.DynamicMaterialTheme @Composable fun MyApp() { DynamicMaterialTheme( seedColor = Color(0xFF6750A4), isDark = isSystemInDarkTheme() ) { // Your content } } ``` -------------------------------- ### Advanced Dynamic Material Theme Configuration Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/README.md Configure a dynamic Material Design 3 theme with advanced options including seed color, dark mode, palette style, contrast level, and animation. This allows for fine-grained control over the theme's appearance and behavior. ```kotlin import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import io.github.alexzhirnov.materialkolor.DynamicMaterialTheme import io.github.alexzhirnov.materialkolor.theme.Contrast import io.github.alexzhirnov.materialkolor.theme.PaletteStyle @Composable fun AdvancedTheme() { DynamicMaterialTheme( seedColor = Color.Blue, isDark = false, style = PaletteStyle.Vibrant, contrastLevel = Contrast.High.value, animate = true ) { // Theme automatically applies to MaterialTheme } } ``` -------------------------------- ### Get Tertiary Container Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the tertiary container color. This color is used for elements that contain tertiary-colored content. ```kotlin public fun tertiaryContainer(): Color ``` -------------------------------- ### Get Tertiary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the tertiary color of the theme. Used for accent elements that are distinct from primary and secondary colors. ```kotlin public fun tertiary(): Color ``` -------------------------------- ### DynamicScheme Configuration Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/types.md Base class for dynamic color schemes, providing settings and color palettes. It includes source color, variant, darkness, contrast level, and platform. ```kotlin public open class DynamicScheme( public val sourceColorHct: Hct, public val variant: Variant, public val isDark: Boolean, public val contrastLevel: Double, public val primaryPalette: TonalPalette, public val secondaryPalette: TonalPalette, public val tertiaryPalette: TonalPalette, public val neutralPalette: TonalPalette, public val neutralVariantPalette: TonalPalette, public val platform: Platform = Platform.PHONE, specVersion: ColorSpec.SpecVersion = ColorSpec.SpecVersion.SPEC_2021, public val errorPalette: TonalPalette, ) ``` -------------------------------- ### Get Secondary Container Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the secondary container color. This color is used for elements that contain secondary-colored content. ```kotlin public fun secondaryContainer(): Color ``` -------------------------------- ### Add Material Color Utilities Dependency (Without Compose) Source: https://github.com/jordond/materialkolor/blob/main/README.md If Compose is not used and only the core color utilities are needed, use the 'material-color-utilities' artifact instead. This is a Kotlin Multiplatform port of Google's Material Color Utilities. ```toml [versions] materialKolor = "4.1.1" [libraries] materialKolor-utilities = { module = "com.materialkolor:material-color-utilities", version.ref = "materialKolor" } ``` -------------------------------- ### Get Secondary Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the secondary color of the theme. Used for less prominent elements compared to the primary color. ```kotlin public fun secondary(): Color ``` -------------------------------- ### DynamicScheme Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/types.md Base class providing settings and color palettes for dynamic color schemes. ```APIDOC ## DynamicScheme Base class providing settings and color palettes for dynamic color schemes. ### Class Definition ```kotlin public open class DynamicScheme( public val sourceColorHct: Hct, public val variant: Variant, public val isDark: Boolean, public val contrastLevel: Double, public val primaryPalette: TonalPalette, public val secondaryPalette: TonalPalette, public val tertiaryPalette: TonalPalette, public val neutralPalette: TonalPalette, public val neutralVariantPalette: TonalPalette, public val platform: Platform = Platform.PHONE, specVersion: ColorSpec.SpecVersion = ColorSpec.SpecVersion.SPEC_2021, public val errorPalette: TonalPalette, ) ``` ### Enum: Platform - `PHONE` (default) - `WATCH` ``` -------------------------------- ### Get Primary Fixed Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the fixed primary color. This color remains constant regardless of theme variants. ```kotlin public fun primaryFixed(): Color ``` -------------------------------- ### Optimize Image Theming with Asynchronous Color Extraction Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/image-bitmap-extensions.md Extracts the theme color from a large ImageBitmap asynchronously to prevent blocking the UI thread. Uses `LaunchedEffect` and `Dispatchers.Default` for background processing. Ensure `DynamicMaterialTheme` and `themeColor` extension function are available. ```kotlin import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import com.materialkol.themeColor import com.materialkol.DynamicMaterialTheme @Composable fun OptimizedImageTheming(largeImage: ImageBitmap) { // Extract color asynchronously to avoid blocking composition var themeColor by remember { mutableStateOf(Color.Blue) } LaunchedEffect(largeImage) { // Run on background dispatcher to avoid janky UI themeColor = withContext(Dispatchers.Default) { largeImage.themeColor(fallback = Color.Blue) } } DynamicMaterialTheme(seedColor = themeColor) { // UI content } } ``` -------------------------------- ### Get Primary Container Color Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves the primary container color. This color is used for elements that contain primary-colored content. ```kotlin public fun primaryContainer(): Color ``` -------------------------------- ### DynamicScheme.Platform Enum Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/types.md Defines the target platform for the dynamic scheme. Use PHONE for phones/tablets and WATCH for wearables. ```kotlin public enum class DynamicScheme.Platform { PHONE, WATCH, ; public companion object { public val Default: DynamicScheme.Platform = PHONE } } ``` -------------------------------- ### Get Text Secondary and Tertiary Inverse Color (Android) Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/material-kolors-class.md Retrieves secondary/tertiary text color on inverse backgrounds. This is specific to Android. ```kotlin public fun textSecondaryAndTertiaryInverse(): Color ``` -------------------------------- ### Accessing Tones from DynamicScheme Palettes Source: https://github.com/jordond/materialkolor/blob/main/_autodocs/api-reference/dynamic-scheme-extensions.md Demonstrates how to access specific color tones (0-100) from the primary, secondary, tertiary, neutral, and error palettes of a DynamicScheme. This is useful for applying specific shades of colors throughout a UI. ```kotlin val scheme = rememberDynamicScheme( seedColor = Color.Blue, isDark = false ) // Primary palette tones from 0-100 val tone0 = scheme.primaryPalette.tone(0) // Darkest val tone50 = scheme.primaryPalette.tone(50) // Mid val tone100 = scheme.primaryPalette.tone(100) // Lightest // Access other palettes val secondary0 = scheme.secondaryPalette.tone(0) val tertiary50 = scheme.tertiaryPalette.tone(50) val neutral0 = scheme.neutralPalette.tone(0) val error100 = scheme.errorPalette.tone(100) ```