diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f6ecd1..21d5f2e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## Unreleased + +### Fixed + +- Support for monochrome system color palette (#199). + ## 2.1.0 ### New diff --git a/app/src/androidTest/kotlin/codes/swistak/batterymonitor/testsupport/ContrastTestSupport.kt b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/testsupport/ContrastTestSupport.kt new file mode 100644 index 00000000..1ec20943 --- /dev/null +++ b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/testsupport/ContrastTestSupport.kt @@ -0,0 +1,26 @@ +/* + Copyright (c) 2026 Tomasz Świstak + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. +*/ +package codes.swistak.batterymonitor.testsupport + +import androidx.compose.material3.darkColorScheme +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.graphics.luminance + +internal val monochromaticDarkColorScheme = darkColorScheme( + primary = Color.White, + onPrimary = Color(0xFF1B1B1B), + primaryContainer = Color(0xFFD4D4D4), + onPrimaryContainer = Color.Black +) + +internal fun contrast(foreground: Color, background: Color): Float { + val fg = foreground.compositeOver(background).luminance() + val bg = background.luminance() + return (maxOf(fg, bg) + 0.05f) / (minOf(fg, bg) + 0.05f) +} diff --git a/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/components/BatteryCellHeroContrastInstrumentedTest.kt b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/components/BatteryCellHeroContrastInstrumentedTest.kt new file mode 100644 index 00000000..fd9095e1 --- /dev/null +++ b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/components/BatteryCellHeroContrastInstrumentedTest.kt @@ -0,0 +1,135 @@ +/* + Copyright (c) 2026 Tomasz Świstak + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. +*/ +package codes.swistak.batterymonitor.ui.components + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.view.View +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.width +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalLayoutDirection +import androidx.compose.ui.semantics.SemanticsProperties +import androidx.compose.ui.semantics.getOrNull +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.dp +import androidx.test.core.app.ActivityScenario +import codes.swistak.batterymonitor.testsupport.ComposeTestActivity +import codes.swistak.batterymonitor.testsupport.awaitCondition +import codes.swistak.batterymonitor.testsupport.composeNodes +import codes.swistak.batterymonitor.testsupport.contrast +import codes.swistak.batterymonitor.testsupport.monochromaticDarkColorScheme +import codes.swistak.batterymonitor.testsupport.runOnMain +import org.junit.Assert.assertTrue +import org.junit.Test +import kotlin.math.roundToInt + +class BatteryCellHeroContrastInstrumentedTest { + @Test + fun fill_and_markings_are_visible_on_both_sides_of_the_fill_boundary() { + ActivityScenario.launch(ComposeTestActivity::class.java).use { scenario -> + val showTarget = mutableStateOf(false) + lateinit var decor: View + scenario.onActivity { activity -> + decor = activity.window.decorView + activity.setContent { + CompositionLocalProvider( + LocalDensity provides Density(PIXELS_PER_DP.toFloat()), + LocalLayoutDirection provides LayoutDirection.Ltr + ) { + MaterialTheme(colorScheme = monochromaticDarkColorScheme) { + BatteryCellHero( + title = "Battery", + level = 50, + status = "", + detail = "", + spokenSummary = if (showTarget.value) TARGET else CHARGING, + modifier = Modifier.width(320.dp), + targetPercent = if (showTarget.value) 50 else null, + charging = !showTarget.value + ) + } + } + } + } + + withCellImage(decor, CHARGING) { image -> + val empty = image.colorAt(30, 18) + val filled = image.colorAt(30, 102) + val separation = contrast(filled, empty) + assertTrue("Fill against empty cell had $separation:1 contrast", separation >= 3f) + image.assertFeature("Upper tick", Rect(5f, 29f, 12f, 31f), empty) + image.assertFeature("Lower tick", Rect(5f, 89f, 12f, 91f), filled) + image.assertFeature("Upper bolt", Rect(20f, 47f, 40f, 58f), empty) + image.assertFeature("Lower bolt", Rect(20f, 62f, 40f, 73f), filled) + } + + runOnMain { showTarget.value = true } + withCellImage(decor, TARGET) { image -> + val empty = image.colorAt(30, 18) + val filled = image.colorAt(30, 102) + image.assertFeature("Target line above fill", Rect(22f, 58.5f, 38f, 60f), empty) + image.assertFeature("Target line over fill", Rect(22f, 60f, 38f, 61.5f), filled) + image.assertFeature("Target ring above fill", Rect(54f, 56f, 55.5f, 57f), empty) + image.assertFeature("Target ring over fill", Rect(54f, 63f, 55.5f, 64f), filled) + } + } + } + + private fun withCellImage(decor: View, summary: String, inspect: (Bitmap) -> Unit) { + fun cardBounds(): Rect? = composeNodes(decor).singleOrNull { + it.config.getOrNull(SemanticsProperties.ContentDescription) == listOf(summary) + }?.boundsInWindow?.takeIf { it.width > 0f } + + awaitCondition({ "$summary did not render" }) { runOnMain { cardBounds() != null } } + runOnMain { + val card = checkNotNull(cardBounds()) + val image = Bitmap.createBitmap( + 60 * PIXELS_PER_DP, 120 * PIXELS_PER_DP, Bitmap.Config.ARGB_8888 + ) + try { + // Crop to the non-expanded cell interior, excluding the terminal, border and inset. + val canvas = Canvas(image) + canvas.translate( + 90f * PIXELS_PER_DP - card.right, + 56f * PIXELS_PER_DP - card.center.y.roundToInt() + ) + decor.draw(canvas) + inspect(image) + } finally { + image.recycle() + } + } + } + + private fun Bitmap.colorAt(xDp: Int, yDp: Int): Color = + Color(getPixel(xDp * PIXELS_PER_DP, yDp * PIXELS_PER_DP)) + + private fun Bitmap.assertFeature(name: String, boundsDp: Rect, background: Color) { + var best = 1f + for (y in (boundsDp.top * PIXELS_PER_DP).toInt() until (boundsDp.bottom * PIXELS_PER_DP).toInt()) { + for (x in (boundsDp.left * PIXELS_PER_DP).toInt() until (boundsDp.right * PIXELS_PER_DP).toInt()) { + best = maxOf(best, contrast(Color(getPixel(x, y)), background)) + } + } + assertTrue("$name had $best:1 contrast", best >= 3f) + } + + private companion object { + const val PIXELS_PER_DP = 2 + const val CHARGING = "Battery charging at half capacity" + const val TARGET = "Battery at the charging target" + } +} diff --git a/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContrastInstrumentedTest.kt b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContrastInstrumentedTest.kt new file mode 100644 index 00000000..48a60dd3 --- /dev/null +++ b/app/src/androidTest/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContrastInstrumentedTest.kt @@ -0,0 +1,199 @@ +/* + Copyright (c) 2026 Tomasz Świstak + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. +*/ +package codes.swistak.batterymonitor.ui.navigation + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.view.View +import androidx.activity.compose.setContent +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalLayoutDirection +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.SemanticsProperties +import androidx.compose.ui.semantics.getAllSemanticsNodes +import androidx.compose.ui.semantics.getOrNull +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.LayoutDirection +import androidx.test.core.app.ActivityScenario +import codes.swistak.batterymonitor.testsupport.ComposeTestActivity +import codes.swistak.batterymonitor.testsupport.awaitCondition +import codes.swistak.batterymonitor.testsupport.composeNodes +import codes.swistak.batterymonitor.testsupport.contrast +import codes.swistak.batterymonitor.testsupport.monochromaticDarkColorScheme +import codes.swistak.batterymonitor.testsupport.runOnMain +import codes.swistak.batterymonitor.ui.theme.Brightness +import codes.swistak.batterymonitor.ui.theme.ColorSource +import codes.swistak.batterymonitor.ui.theme.batteryColorScheme +import org.junit.Assert.assertTrue +import org.junit.Test +import kotlin.math.abs + +class SideMenuContrastInstrumentedTest { + @Test + fun selected_drawer_text_and_icon_use_the_role_paired_with_the_rendered_container() { + ActivityScenario.launch(ComposeTestActivity::class.java).use { scenario -> + lateinit var activity: ComposeTestActivity + scenario.onActivity { activity = it } + + val dark = darkColorScheme() + val batteryBlue = + listOf(Brightness.Light, Brightness.Dark, Brightness.TrueBlack).map { brightness -> + "Battery Blue $brightness" to batteryColorScheme( + activity, ColorSource.BatteryBlue, brightness + ) + } + val cases = listOf( + "Material You monochromatic dark" to monochromaticDarkColorScheme, + "Material You monochromatic light" to lightColorScheme( + primary = Color.Black, + onPrimary = Color.White, + primaryContainer = Color(0xFF343434), + onPrimaryContainer = Color.White + ), + "Material You chromatic light" to lightColorScheme(), + "Material You chromatic dark" to dark, + "Material You True Black" to dark.copy( + background = Color.Black, surface = Color(0xFF10151B) + ) + ) + batteryBlue + + val palette = mutableStateOf(cases.first()) + runOnMain { + activity.setContent { + val (name, colors) = palette.value + // Use a fixed density so strokes and glyphs contain solid foreground pixels. + CompositionLocalProvider( + LocalDensity provides Density(2f), + LocalLayoutDirection provides LayoutDirection.Ltr + ) { + MaterialTheme(colorScheme = colors) { + Surface { + SideMenuContent( + appName = "Test app", + closeLabel = "Close", + batteryGroupLabel = "Battery", + toolsGroupLabel = "Tools", + batterySections = listOf(MenuSection("current", MENU_LABEL)), + toolSections = emptyList(), + selectedId = "current", + onSelect = {}, + onClose = {}, + modifier = Modifier.testTag(name), + showCloseButton = false + ) + } + } + } + } + } + + val decor = activity.window.decorView + for ((name, colors) in cases) { + runOnMain { palette.value = name to colors } + awaitCondition({ "$name drawer did not render" }) { + runOnMain { + val nodes = composeNodes(decor) + nodes.any { it.config.getOrNull(SemanticsProperties.TestTag) == name } && nodes.any { + it.config.getOrNull(SemanticsProperties.Selected) == true && it.boundsInWindow.width > 0f + } + } + } + val (background, label, icon) = runOnMain { captureSelectedColors(decor) } + assertColor( + "$name selected background", + colors.primaryContainer.compositeOver(colors.surface), + background + ) + val foreground = colors.onPrimaryContainer.compositeOver(background) + assertColor("$name selected text", foreground, label) + assertColor("$name selected icon", foreground, icon) + assertTrue( + "$name text contrast must be at least 4.5:1", + contrast(label, background) >= 4.5f + ) + assertTrue( + "$name icon contrast must be at least 3:1", contrast(icon, background) >= 3f + ) + } + } + } + + private fun captureSelectedColors(decor: View): Triple { + val row = composeNodes(decor).single { + it.config.getOrNull(SemanticsProperties.Selected) == true + } + val rowBounds = row.boundsInWindow + val labelBounds = + requireNotNull(row.root).semanticsOwner.getAllSemanticsNodes(mergingEnabled = false) + .single { node -> + node.config.getOrNull(SemanticsProperties.Text) + ?.any { it.text == MENU_LABEL } == true + }.boundsInWindow + + // The icon precedes the label and has no semantics of its own. Sample the middle of that + // region to keep the antialiased ends of the selection pill out of the comparison. + val iconBounds = Rect( + rowBounds.left + rowBounds.height / 8f, + rowBounds.center.y - rowBounds.height / 6f, + labelBounds.left, + rowBounds.center.y + rowBounds.height / 6f + ) + val image = Bitmap.createBitmap(decor.width, decor.height, Bitmap.Config.ARGB_8888) + try { + decor.draw(Canvas(image)) + val backgroundX = (labelBounds.right + rowBounds.right) / 2f + val background = Color(image.getPixel(backgroundX.toInt(), rowBounds.center.y.toInt())) + return Triple( + background, + image.strongestForeground(labelBounds, background), + image.strongestForeground(iconBounds, background) + ) + } finally { + image.recycle() + } + } + + private fun Bitmap.strongestForeground(bounds: Rect, background: Color): Color { + var foreground = background + var bestContrast = 1f + for (y in bounds.top.toInt() until bounds.bottom.toInt()) { + for (x in bounds.left.toInt() until bounds.right.toInt()) { + val pixel = Color(getPixel(x, y)) + val pixelContrast = contrast(pixel, background) + if (pixelContrast > bestContrast) { + foreground = pixel + bestContrast = pixelContrast + } + } + } + return foreground + } + + private fun assertColor(message: String, expected: Color, actual: Color) { + val difference = maxOf( + abs(expected.red - actual.red), + abs(expected.green - actual.green), + abs(expected.blue - actual.blue) + ) + assertTrue("$message expected $expected, rendered $actual", difference <= 2f / 255f) + } + + private companion object { + const val MENU_LABEL = "Current" + } +} diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/components/DesignComponents.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/components/DesignComponents.kt index 669f3b92..14e6364a 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/components/DesignComponents.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/components/DesignComponents.kt @@ -43,9 +43,16 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.ClipOp import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.Path +import androidx.compose.ui.graphics.addOutline +import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.drawscope.clipPath +import androidx.compose.ui.graphics.drawscope.translate import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.semantics.Role @@ -150,50 +157,67 @@ fun BatteryCellHero( .width(if (expanded) 80.dp else 72.dp) .height(if (expanded) 150.dp else 132.dp) .border(2.dp, colors.onPrimaryContainer, RoundedCornerShape(20.dp)) - .padding(6.dp), contentAlignment = Alignment.BottomCenter + .padding(6.dp) ) { - Box( - Modifier - .fillMaxWidth() - .fillMaxHeight((level ?: 0).coerceIn(0, 100) / 100f) - .clip(RoundedCornerShape(12.dp)) - .background(colors.primary) - ) + val emptyColor = colors.primaryContainer + val filledColor = colors.onPrimaryContainer + val fillShape = RoundedCornerShape(12.dp) + val fillFraction = (level ?: 0).coerceIn(0, 100) / 100f + val bolt = if (charging) painterResource(R.drawable.ui_bolt) else null Canvas(Modifier.matchParentSize()) { - val tickColor = colors.onPrimaryContainer.copy(alpha = 0.35f) - repeat(3) { tick -> - val y = size.height * (1 - (tick + 1) / 4f) - drawLine( - tickColor, - Offset(4.dp.toPx(), y), - Offset(13.dp.toPx(), y), - 1.dp.toPx() + val fillHeight = size.height * fillFraction + val filledArea = Path().apply { + addOutline( + fillShape.createOutline( + Size(size.width, fillHeight), layoutDirection, this@Canvas + ) ) + translate(Offset(0f, size.height - fillHeight)) } - targetPercent?.takeIf { it in 0..100 }?.let { target -> - val radius = 3.dp.toPx() - val y = (size.height * (1 - target / 100f)).coerceIn( - radius, size.height - radius - ) - val markerColor = colors.onPrimaryContainer.copy(alpha = 0.8f) - drawLine( - markerColor, Offset(0f, y), Offset(size.width, y), 1.5.dp.toPx() + + fun DrawScope.drawCellDetails(foreground: Color, background: Color) { + repeat(3) { tick -> + val y = size.height * (1 - (tick + 1) / 4f) + drawLine( + foreground, + Offset(4.dp.toPx(), y), + Offset(13.dp.toPx(), y), + 1.dp.toPx() + ) + } + targetPercent?.takeIf { it in 0..100 }?.let { target -> + val radius = 3.dp.toPx() + val y = (size.height * (1 - target / 100f)).coerceIn( + radius, size.height - radius + ) + drawLine( + foreground, Offset(0f, y), Offset(size.width, y), 1.5.dp.toPx() + ) + val center = Offset(size.width - 5.dp.toPx(), y) + drawCircle(foreground, radius + 1.dp.toPx(), center) + drawCircle(background, radius, center) + } + bolt?.let { painter -> + val side = 28.dp.toPx() + translate(center.x - side / 2f, center.y - side / 2f) { + with(painter) { + draw( + Size(side, side), + colorFilter = ColorFilter.tint(foreground) + ) + } + } + } + } + + drawPath(filledArea, filledColor) + clipPath(filledArea, ClipOp.Difference) { + drawCellDetails( + filledColor, emptyColor ) - val center = Offset(size.width - 5.dp.toPx(), y) - drawCircle(markerColor, radius + 1.dp.toPx(), center) - drawCircle(colors.primaryContainer, radius, center) } + clipPath(filledArea) { drawCellDetails(emptyColor, filledColor) } } - if (charging) Icon( - painterResource(R.drawable.ui_bolt), - null, - Modifier - .align(Alignment.Center) - .size(28.dp), - tint = if ((level - ?: 0) >= 50 - ) colors.onPrimary else colors.onPrimaryContainer - ) } } } diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/diagnostics/MonitorOperationScreen.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/diagnostics/MonitorOperationScreen.kt index 933ec929..ed6f0347 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/diagnostics/MonitorOperationScreen.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/diagnostics/MonitorOperationScreen.kt @@ -30,6 +30,7 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Switch +import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -118,6 +119,9 @@ internal fun MonitorOperationScreen( } } val checked = action.checked + val colors = MaterialTheme.colorScheme + val supporting = + if (highlighted) colors.onPrimaryContainer else colors.onSurfaceVariant Row( Modifier .fillMaxWidth() @@ -145,27 +149,37 @@ internal fun MonitorOperationScreen( painterResource(settingIcon(key)), null, Modifier.size(22.dp), - tint = MaterialTheme.colorScheme.primary + tint = if (highlighted) colors.onPrimaryContainer else colors.primary ) Column(Modifier.weight(1f)) { Text( stringResource(action.title), - style = MaterialTheme.typography.bodyLarge + style = MaterialTheme.typography.bodyLarge, + color = if (highlighted) colors.onPrimaryContainer else colors.onSurface ) if (action.summary.isNotEmpty()) Text( action.summary, style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant + color = supporting ) if (!action.isVisible) Text( stringResource(R.string.diag_value_not_available), style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant + color = supporting ) } checked?.let { Switch( - checked = it, onCheckedChange = null, enabled = enabled + checked = it, + onCheckedChange = null, + enabled = enabled, + colors = if (highlighted) SwitchDefaults.colors( + checkedTrackColor = colors.onPrimaryContainer, + checkedThumbColor = colors.primaryContainer, + uncheckedTrackColor = colors.primaryContainer, + uncheckedThumbColor = colors.onPrimaryContainer, + uncheckedBorderColor = colors.onPrimaryContainer + ) else SwitchDefaults.colors() ) } } diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/FullscreenChartScreen.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/FullscreenChartScreen.kt index 46ce8b56..cdb5294a 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/FullscreenChartScreen.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/FullscreenChartScreen.kt @@ -1285,7 +1285,6 @@ private fun ChartSelector( Surface( onClick = onClick, color = MaterialTheme.colorScheme.surfaceVariant, - contentColor = MaterialTheme.colorScheme.primary, shape = MaterialTheme.shapes.small, modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryRangeControl.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryRangeControl.kt index 5af2788d..869469b2 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryRangeControl.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryRangeControl.kt @@ -181,10 +181,7 @@ internal fun HistoryRangeControl( horizontalArrangement = Arrangement.spacedBy(8.dp) ) { Icon( - painterResource(R.drawable.ui_calendar), - null, - Modifier.size(20.dp), - tint = MaterialTheme.colorScheme.primary + painterResource(R.drawable.ui_calendar), null, Modifier.size(20.dp) ) Column(Modifier.weight(1f)) { Text( @@ -214,10 +211,7 @@ internal fun HistoryRangeControl( color = MaterialTheme.colorScheme.onSurfaceVariant ) Icon( - painterResource(R.drawable.ui_chev), - null, - Modifier.size(20.dp), - tint = MaterialTheme.colorScheme.primary + painterResource(R.drawable.ui_chev), null, Modifier.size(20.dp) ) } } @@ -350,11 +344,11 @@ internal fun HistoryRangeControl( } if (dialogsAllowed) AlertDialog( onDismissRequest = { - if (!handled && mode == editorMode) { - handled = true - mode = null - } - }, + if (!handled && mode == editorMode) { + handled = true + mode = null + } + }, modifier = Modifier.imePadding(), title = { Text(stringResource(R.string.history_range)) }, text = { diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryScreen.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryScreen.kt index 6c9a68fe..610ae23d 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryScreen.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/history/HistoryScreen.kt @@ -607,7 +607,6 @@ internal fun HistoryRoute( if (emphasized) MaterialTheme.colorScheme.onPrimaryContainer else MaterialTheme.colorScheme.onSurface val secondary = if (emphasized) foreground else MaterialTheme.colorScheme.onSurfaceVariant - val selectionColor = MaterialTheme.colorScheme.primary val first = index == 0 val last = index == entries.lastIndex val shape = RoundedCornerShape( @@ -688,7 +687,7 @@ internal fun HistoryRoute( val x = if (layoutDirection == LayoutDirection.Rtl) size.width - width else 0f drawRect( - selectionColor, + foreground, topLeft = Offset(x, 0f), size = Size(width, size.height) ) @@ -706,10 +705,7 @@ internal fun HistoryRoute( Modifier.size(35.dp), contentAlignment = Alignment.Center ) { Icon( - painterResource(icon), - null, - Modifier.size(19.dp), - tint = if (emphasized) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.primary + painterResource(icon), null, Modifier.size(19.dp) ) } } diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContent.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContent.kt index fc9ef615..83605e75 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContent.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/navigation/SideMenuContent.kt @@ -151,7 +151,7 @@ private fun MenuItem( modifier: Modifier = Modifier ) { val colors = MaterialTheme.colorScheme - val foreground = if (isSelected) colors.primary else colors.onSurfaceVariant + val foreground = if (isSelected) colors.onPrimaryContainer else colors.onSurfaceVariant Row( modifier .fillMaxWidth() diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/settings/SettingsScreen.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/settings/SettingsScreen.kt index 35c42ade..ac190589 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/ui/settings/SettingsScreen.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/ui/settings/SettingsScreen.kt @@ -40,6 +40,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.RadioButton import androidx.compose.material3.Switch +import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable @@ -393,6 +394,8 @@ private fun SettingItem( highlighted: Boolean, onClick: () -> Unit ) { + val colors = MaterialTheme.colorScheme + val highlightContentColor = colors.onPrimaryContainer.takeIf { highlighted } val checked = if (descriptor.control is SettingsControl.Toggle) descriptor.value == true else null val enabled = descriptor.unavailable == null @@ -433,25 +436,35 @@ private fun SettingItem( painterResource(settingIcon(descriptor.key)), null, Modifier.size(24.dp), - tint = MaterialTheme.colorScheme.primary + tint = highlightContentColor ?: colors.primary ) Spacer(Modifier.width(14.dp)) Column(Modifier.weight(1f)) { - Text(descriptor.title, color = MaterialTheme.colorScheme.onSurface) + Text(descriptor.title, color = highlightContentColor ?: colors.onSurface) if (summary.isNotBlank() && summary != descriptor.title) Text( summary, style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant + color = highlightContentColor ?: colors.onSurfaceVariant ) } Spacer(Modifier.width(12.dp)) - if (checked != null) Switch(checked, null, enabled = enabled) - else Icon( - painterResource(R.drawable.ui_chev), - null, - Modifier.size(20.dp), - tint = MaterialTheme.colorScheme.onSurfaceVariant - ) + if (checked != null) { + val switchColors = if (highlighted) SwitchDefaults.colors( + checkedThumbColor = colors.primaryContainer, + checkedTrackColor = colors.onPrimaryContainer, + uncheckedThumbColor = colors.onPrimaryContainer, + uncheckedTrackColor = colors.primaryContainer, + uncheckedBorderColor = colors.onPrimaryContainer + ) else SwitchDefaults.colors() + Switch(checked, null, enabled = enabled, colors = switchColors) + } else { + Icon( + painterResource(R.drawable.ui_chev), + null, + Modifier.size(20.dp), + tint = highlightContentColor ?: colors.onSurfaceVariant + ) + } } if (!last) HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant) } diff --git a/app/src/main/kotlin/codes/swistak/batterymonitor/widgets/WidgetRenderer.kt b/app/src/main/kotlin/codes/swistak/batterymonitor/widgets/WidgetRenderer.kt index 0a962ed8..3671f454 100644 --- a/app/src/main/kotlin/codes/swistak/batterymonitor/widgets/WidgetRenderer.kt +++ b/app/src/main/kotlin/codes/swistak/batterymonitor/widgets/WidgetRenderer.kt @@ -131,8 +131,9 @@ internal object WidgetRenderer { views.setInt( R.id.widget_border, "setImageAlpha", config.backgroundOpacityPercent * 255 / 100 ) - views.setInt(R.id.widget_customize, "setColorFilter", primary) - views.setInt(R.id.widget_family_icon, "setColorFilter", primary) + val iconColor = if (family == WidgetFamily.STATUS) foreground else primary + views.setInt(R.id.widget_customize, "setColorFilter", iconColor) + views.setInt(R.id.widget_family_icon, "setColorFilter", iconColor) views.setTextColor(R.id.widget_title, foreground) views.setTextViewText(R.id.widget_title, titleWithTime ?: title) val titleLines = if (titleWithTime != null || family == WidgetFamily.TREND) 2 else 1 @@ -255,7 +256,7 @@ internal object WidgetRenderer { ) if (showBattery) body.setImageViewBitmap( R.id.widget_battery_cell, - widgetBatteryBitmap(context, artHeightDp, primary, reading?.levelPercent) + widgetBatteryBitmap(context, artHeightDp, foreground, reading?.levelPercent) ) val readingWidthDp = if (showBattery) { contentWidthDp - (artHeightDp * BATTERY_ASPECT).roundToInt() - 8