From aa764bd0a89bb619f07aba0951241c14e70ae1b4 Mon Sep 17 00:00:00 2001 From: timklge <2026103+timklge@users.noreply.github.com> Date: Mon, 2 Jun 2025 16:11:29 +0200 Subject: [PATCH] Make bar background transparent by default (#37) fix #35 --- .../de/timklge/karoopowerbar/CustomProgressBar.kt | 9 +++++++-- .../de/timklge/karoopowerbar/ForegroundService.kt | 4 ++-- .../kotlin/de/timklge/karoopowerbar/Settings.kt | 1 + .../main/kotlin/de/timklge/karoopowerbar/Window.kt | 2 ++ .../de/timklge/karoopowerbar/screens/MainScreen.kt | 14 ++++++++++++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/CustomProgressBar.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/CustomProgressBar.kt index c610dfc..2c5d459 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/CustomProgressBar.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/CustomProgressBar.kt @@ -27,6 +27,7 @@ class CustomProgressBar @JvmOverloads constructor( var location: PowerbarLocation = PowerbarLocation.BOTTOM var label: String = "" var showLabel: Boolean = true + var barBackground: Boolean = false @ColorInt var progressColor: Int = 0xFF2b86e6.toInt() var size = CustomProgressBarSize.MEDIUM @@ -102,7 +103,9 @@ class CustomProgressBar @JvmOverloads constructor( 15f + size.barHeight ) - canvas.drawRect(0f, 15f, canvas.width.toFloat(), 15f + size.barHeight, backgroundPaint) + if (barBackground){ + canvas.drawRect(0f, 15f, canvas.width.toFloat(), 15f + size.barHeight, backgroundPaint) + } if (progress != null) { canvas.drawRoundRect(rect, 2f, 2f, blurPaint) @@ -138,7 +141,9 @@ class CustomProgressBar @JvmOverloads constructor( canvas.height.toFloat() ) - canvas.drawRect(0f, canvas.height.toFloat() - size.barHeight, canvas.width.toFloat(), canvas.height.toFloat(), backgroundPaint) + if (barBackground){ + canvas.drawRect(0f, canvas.height.toFloat() - size.barHeight, canvas.width.toFloat(), canvas.height.toFloat(), backgroundPaint) + } if (progress != null) { canvas.drawRoundRect(rect, 2f, 2f, blurPaint) diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/ForegroundService.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/ForegroundService.kt index fdb34fe..2b869bd 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/ForegroundService.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/ForegroundService.kt @@ -53,7 +53,7 @@ class ForegroundService : Service() { windows.clear() if (settings.source != SelectedSource.NONE && showBars) { - Window(this@ForegroundService, PowerbarLocation.BOTTOM, settings.showLabelOnBars, settings.barSize).apply { + Window(this@ForegroundService, PowerbarLocation.BOTTOM, settings.showLabelOnBars, settings.barBackground, settings.barSize).apply { selectedSource = settings.source windows.add(this) open() @@ -61,7 +61,7 @@ class ForegroundService : Service() { } if (settings.topBarSource != SelectedSource.NONE && showBars){ - Window(this@ForegroundService, PowerbarLocation.TOP, settings.showLabelOnBars, settings.barSize).apply { + Window(this@ForegroundService, PowerbarLocation.TOP, settings.showLabelOnBars, settings.barBackground, settings.barSize).apply { selectedSource = settings.topBarSource open() windows.add(this) diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/Settings.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/Settings.kt index 2abcbd1..fd9523c 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/Settings.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/Settings.kt @@ -21,6 +21,7 @@ data class PowerbarSettings( val onlyShowWhileRiding: Boolean = true, val showLabelOnBars: Boolean = true, val useZoneColors: Boolean = true, + val barBackground: Boolean = false, val barSize: CustomProgressBarSize = CustomProgressBarSize.MEDIUM, val minCadence: Int = defaultMinCadence, val maxCadence: Int = defaultMaxCadence, diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt index 110c12b..93bc41e 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt @@ -46,6 +46,7 @@ class Window( private val context: Context, val powerbarLocation: PowerbarLocation = PowerbarLocation.BOTTOM, val showLabel: Boolean, + val barBackground: Boolean, val powerbarSize: CustomProgressBarSize ) { private val rootView: View @@ -122,6 +123,7 @@ class Window( powerbar.progress = null powerbar.location = powerbarLocation powerbar.showLabel = showLabel + powerbar.barBackground = barBackground powerbar.size = powerbarSize powerbar.invalidate() diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt index 84f4e6a..1359af6 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt @@ -66,8 +66,6 @@ import de.timklge.karoopowerbar.settingsKey import de.timklge.karoopowerbar.streamSettings import de.timklge.karoopowerbar.streamUserProfile import io.hammerhead.karooext.KarooSystemService -import io.hammerhead.karooext.models.HardwareType -import io.hammerhead.karooext.models.PlayBeepPattern import io.hammerhead.karooext.models.UserProfile import kotlinx.coroutines.delay import kotlinx.coroutines.flow.combine @@ -147,6 +145,7 @@ fun MainScreen(onFinish: () -> Unit) { var colorBasedOnZones by remember { mutableStateOf(false) } var showLabelOnBars by remember { mutableStateOf(true) } var barSize by remember { mutableStateOf(CustomProgressBarSize.MEDIUM) } + var barBackground by remember { mutableStateOf(false) } var minCadence by remember { mutableStateOf("0") } var maxCadence by remember { mutableStateOf("0") } @@ -176,6 +175,7 @@ fun MainScreen(onFinish: () -> Unit) { val newSettings = PowerbarSettings( source = bottomSelectedSource, topBarSource = topSelectedSource, onlyShowWhileRiding = onlyShowWhileRiding, showLabelOnBars = showLabelOnBars, + barBackground = barBackground, useZoneColors = colorBasedOnZones, minCadence = minCadence.toIntOrNull() ?: PowerbarSettings.defaultMinCadence, maxCadence = maxCadence.toIntOrNull() ?: PowerbarSettings.defaultMaxCadence, @@ -227,6 +227,7 @@ fun MainScreen(onFinish: () -> Unit) { showLabelOnBars = settings.showLabelOnBars colorBasedOnZones = settings.useZoneColors barSize = settings.barSize + barBackground = settings.barBackground minCadence = settings.minCadence.toString() maxCadence = settings.maxCadence.toString() isImperial = profile.preferredUnit.distance == UserProfile.PreferredUnit.UnitType.IMPERIAL @@ -470,6 +471,15 @@ fun MainScreen(onFinish: () -> Unit) { Text("Show value on bars") } + Row(verticalAlignment = Alignment.CenterVertically) { + Switch(checked = barBackground, onCheckedChange = { + barBackground = it + coroutineScope.launch { updateSettings() } + }) + Spacer(modifier = Modifier.width(10.dp)) + Text("Opaque background") + } + Row(verticalAlignment = Alignment.CenterVertically) { Switch(checked = onlyShowWhileRiding, onCheckedChange = { onlyShowWhileRiding = it