1.8 KiB
1.8 KiB
Dominant Color Extraction for Now Playing Metadata Background
Task
Detect the dominant color of the album artwork and use it as the background color for the metadata section of the Now Playing screen. Text colors are automatically inverted for contrast.
Changes Made
New dependency
gradle/libs.versions.toml: Addedandroidx.palette:palette-ktx:1.0.0app/build.gradle.kts: Addedimplementation(libs.palette)
RadioApplication.kt
- Added a shared
ImageLoaderinstance (Coil 3) for use in palette extraction.
NowPlayingScreen.kt
- Palette extraction: Uses
LaunchedEffect(artworkUrl)to load a 64x64 thumbnail via Coil'sImageLoader, then runsPalette.from(bitmap).generate()onDispatchers.IO. DominantColorsdata class: Holdsbackground,onBackground, andaccentcolors extracted from the artwork.- Contrast logic:
contrastingTextColor()checks luminance and picks black or white text. Accent color is picked from light/dark vibrant or muted swatches depending on background brightness. - All child composables (
TrackInfoSection,TimerSection,TransportControls,SettingsSection) now accept explicit color parameters instead of reading fromMaterialTheme.colorScheme. - Metadata panel backgrounds: Both
PortraitContent(bottom half) andLandscapeContent(right half) applyModifier.background(bgColor)using the extracted dominant color. - Slider and Switch colors: Themed to match the extracted accent color.
- Landscape TopAppBar: Also uses the dominant background color for consistency.
Follow-up Items
- Consider animating the color transition when artwork changes (e.g.,
animateColorAsState). - May want to add a subtle gradient at the seam between artwork panel and metadata panel.