Skip to content

Commit

Permalink
feat: Add basic theming for AA app
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Aug 15, 2023
1 parent d834faa commit d901fd0
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<string name="pref.aa.profile_2.displayed_parameter_ids">Edit Virtual Screen 2</string>
<string name="pref.aa.profile_3.displayed_parameter_ids">Edit Virtual Screen 3</string>
<string name="pref.aa.profile_4.displayed_parameter_ids">Edit Virtual Screen 4</string>
<string name="pref.aa.theme.progress_bar_color">Progress bar color</string>
<string name="pref.aa.theme.divider_color">Divider color</string>
<string name="pref.aa.theme.current_value_color">Current value color</string>


<string name="pref.displayed_parameter_ids">Edit displayed OBD2 PIDs</string>
Expand Down Expand Up @@ -283,6 +286,7 @@
<string name="virtual_screen_7">7</string>
<string name="virtual_screen_8">8</string>


<string-array name="pref.numbers_1_20">
<item name="0">0</item>
<item name="1">1</item>
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,24 @@
android:key="pref.aa.status.fps.enabled"
android:title="@string/pref.aa.surface.fps.display_status" />

</PreferenceScreen>
<PreferenceCategory android:title="@string/pref.theme">
<com.kizitonwose.colorpreferencecompat.ColorPreferenceCompat
android:defaultValue="0xffff0000"
android:key="pref.aa.theme.progressColor"
android:title="@string/pref.aa.theme.progress_bar_color" />

<com.kizitonwose.colorpreferencecompat.ColorPreferenceCompat
android:defaultValue="0xffffffff"
android:key="pref.aa.theme.dividerColor"
android:title="@string/pref.aa.theme.divider_color" />

<com.kizitonwose.colorpreferencecompat.ColorPreferenceCompat
android:defaultValue="0xffffffff"
android:key="pref.aa.theme.currentValueColor"
android:title="@string/pref.aa.theme.current_value_color" />

</PreferenceCategory>
</PreferenceScreen>

<PreferenceScreen
android:summary="@string/pref.graph_category"
Expand Down
21 changes: 15 additions & 6 deletions automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Color
import android.util.Log
import androidx.car.app.CarContext
import androidx.car.app.Screen
Expand Down Expand Up @@ -205,34 +206,34 @@ internal class CarScreen(carContext: CarContext,

private fun profilesActionStrip(): ActionStrip = ActionStrip.Builder()

.addAction(createAction(R.drawable.action_virtual_screen_1, CarColor.YELLOW) {
.addAction(createAction(R.drawable.action_virtual_screen_1, mapColor(settings.colorTheme().actionsBtnVirtualScreensColor)) {
settings.applyVirtualScreen1()
metricsCollector.applyFilter(settings.getSelectedPIDs())
surfaceController.renderFrame()
})
.addAction(createAction(R.drawable.action_virtual_screen_2, CarColor.YELLOW) {
.addAction(createAction(R.drawable.action_virtual_screen_2, mapColor(settings.colorTheme().actionsBtnVirtualScreensColor)) {
settings.applyVirtualScreen2()
metricsCollector.applyFilter(settings.getSelectedPIDs())
surfaceController.renderFrame()
})

.addAction(createAction(R.drawable.action_virtual_screen_3, CarColor.YELLOW) {
.addAction(createAction(R.drawable.action_virtual_screen_3, mapColor(settings.colorTheme().actionsBtnVirtualScreensColor)) {
settings.applyVirtualScreen3()
metricsCollector.applyFilter(settings.getSelectedPIDs())
surfaceController.renderFrame()
})
.addAction(createAction(R.drawable.action_virtual_screen_4, CarColor.YELLOW) {
.addAction(createAction(R.drawable.action_virtual_screen_4, mapColor(settings.colorTheme().actionsBtnVirtualScreensColor)) {
settings.applyVirtualScreen4()
metricsCollector.applyFilter(settings.getSelectedPIDs())
surfaceController.renderFrame()
})
.build()

private fun actions(): ActionStrip = ActionStrip.Builder()
.addAction(createAction(R.drawable.actions_connect, CarColor.GREEN) {
.addAction(createAction(R.drawable.actions_connect, mapColor(settings.colorTheme().actionsBtnConnectColor)) {
dataLogger.start()
})
.addAction(createAction(R.drawable.action_disconnect, CarColor.BLUE) {
.addAction(createAction(R.drawable.action_disconnect,mapColor(settings.colorTheme().actionsBtnDisconnectColor)) {
toast.show(carContext, R.string.toast_connection_disconnect)
stopDataLogging()
})
Expand All @@ -258,6 +259,14 @@ internal class CarScreen(carContext: CarContext,
dataLogger.stop()
}

private fun mapColor(color: Int): CarColor =
when (color){
Color.BLUE -> CarColor.BLUE
Color.GREEN -> CarColor.GREEN
Color.YELLOW -> CarColor.YELLOW
else -> CarColor.PRIMARY
}

init {
lifecycle.addObserver(this)
dataLogger.observe(this) {
Expand Down
16 changes: 15 additions & 1 deletion automotive/src/main/java/org/obd/graphs/aa/SettingsImpl.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.obd.graphs.aa

import android.graphics.Color
import org.obd.graphs.renderer.ScreenSettings
import org.obd.graphs.preferences.*
import org.obd.graphs.renderer.ColorTheme



private const val PREF_THEME_PROGRESS_BAR_COLOR= "pref.aa.theme.progressColor"
private const val PREF_THEME_DIVIDER_COLOR= "pref.aa.theme.dividerColor"
private const val PREF_THEME_CURR_VALUE_COLOR= "pref.aa.theme.currentValueColor"

private const val PREF_CURRENT_VIRTUAL_SCREEN = "pref.aa.pids.vs.current"
private const val PREF_SELECTED_PIDS = "pref.aa.pids.selected"
Expand All @@ -20,7 +28,13 @@ const val VIRTUAL_SCREEN_3 = "pref.aa.pids.profile_3"
const val VIRTUAL_SCREEN_4 = "pref.aa.pids.profile_4"

internal class SettingsImpl : ScreenSettings {

override fun colorTheme(): ColorTheme {
return ColorTheme(
progressColor = Prefs.getInt(PREF_THEME_PROGRESS_BAR_COLOR, Color.RED),
dividerColor = Prefs.getInt(PREF_THEME_DIVIDER_COLOR, Color.WHITE),
currentValueColor = Prefs.getInt(PREF_THEME_CURR_VALUE_COLOR, Color.WHITE)
)
}
override fun applyVirtualScreen1() = applyVirtualScreen(VIRTUAL_SCREEN_1)
override fun applyVirtualScreen2() = applyVirtualScreen(VIRTUAL_SCREEN_2)
override fun applyVirtualScreen3() = applyVirtualScreen(VIRTUAL_SCREEN_3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
)
}

fun drawStatusBar(area: Rect, fps: Double): Float {
fun drawStatusBar(area: Rect, fps: Double, colorTheme: ColorTheme): Float {
val statusVerticalPos = area.top + 6f
var text = statusLabel
var horizontalAlignment = MARGIN_START.toFloat()
Expand All @@ -117,10 +117,10 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
val color: Int
if (dataLogger.isRunning()) {
text = statusConnected
color = Color.GREEN
color = colorTheme.statusConnectedColor
} else {
text = statusDisconnected
color = Color.YELLOW
color = colorTheme.statusDisconnectedColor
}

drawText(
Expand Down Expand Up @@ -151,7 +151,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
text,
horizontalAlignment,
statusVerticalPos,
Color.YELLOW,
colorTheme.currentProfileColor,
18f,
statusPaint
)
Expand Down Expand Up @@ -186,10 +186,11 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
metric: CarMetric,
horizontalPos: Float,
verticalPos: Float,
textSize: Float
textSize: Float,
colorTheme: ColorTheme
) {
valuePaint.typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)
valuePaint.color = Color.WHITE
valuePaint.color = colorTheme.currentValueColor
valuePaint.textSize = textSize
valuePaint.textAlign = Paint.Align.RIGHT
val text = metric.source.valueToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package org.obd.graphs.renderer

import android.graphics.Color
import org.obd.graphs.ui.common.COLOR_CARDINAL

data class ColorTheme(val dividerColor: Int = Color.WHITE,
val progressColor: Int = COLOR_CARDINAL,
val statusConnectedColor: Int = Color.GREEN,
val statusDisconnectedColor: Int = Color.YELLOW,
val currentValueColor: Int = Color.WHITE,
val currentProfileColor: Int = Color.YELLOW,

val actionsBtnConnectColor: Int = Color.GREEN,
val actionsBtnDisconnectColor: Int = Color.BLUE,
val actionsBtnVirtualScreensColor: Int = Color.YELLOW)

interface ScreenSettings {

fun colorTheme(): ColorTheme = ColorTheme()

fun applyVirtualScreen1() {}
fun applyVirtualScreen2() {}
fun applyVirtualScreen3() {}
Expand All @@ -14,7 +31,7 @@ interface ScreenSettings {
fun getCurrentVirtualScreen(): String = ""
fun applyVirtualScreen(key: String) {}

fun isStatusPanelEnabled (): Boolean = true
fun isStatusPanelEnabled(): Boolean = true

fun getMaxAllowedItemsInColumn(): Int = 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.graphics.Rect
import android.util.Log
import org.obd.graphs.bl.collector.CarMetric
import org.obd.graphs.bl.collector.CarMetricsCollector
import org.obd.graphs.ui.common.COLOR_CARDINAL
import org.obd.graphs.ui.common.COLOR_PHILIPPINE_GREEN
import kotlin.math.min

private const val LOG_KEY = "SimpleScreenRenderer"
Expand Down Expand Up @@ -41,7 +39,7 @@ internal class SimpleScreenRenderer(
var verticalPos = area.top + textHeight.toFloat() / 2

if (settings.isStatusPanelEnabled()) {
verticalPos = drawingManager.drawStatusBar(area, fps.get()) + 18
verticalPos = drawingManager.drawStatusBar(area, fps.get(), settings.colorTheme()) + 18
drawingManager.drawDivider(MARGIN_START.toFloat(), area.width().toFloat(), area.top + 10f, Color.DKGRAY)
}

Expand Down Expand Up @@ -71,7 +69,8 @@ internal class SimpleScreenRenderer(
metric,
valueHorizontalPos,
verticalPos + 10,
textSize.toFloat() + 14
textSize.toFloat() + 14,
colorTheme = settings.colorTheme()
)


Expand Down Expand Up @@ -131,14 +130,14 @@ internal class SimpleScreenRenderer(
drawingManager.drawProgressBar(
margin.toFloat(),
itemWidth(area, metrics).toFloat(), verticalPos, metric,
color = COLOR_CARDINAL
color = settings.colorTheme().progressColor
)

verticalPos += calculateDividerSpacing(metrics)

drawingManager.drawDivider(
margin.toFloat(), itemWidth(area, metrics).toFloat(), verticalPos,
color = COLOR_PHILIPPINE_GREEN
color = settings.colorTheme().dividerColor
)

verticalPos += if (settings.isHistoryEnabled()) {
Expand Down

0 comments on commit d901fd0

Please sign in to comment.