diff --git a/automotive/src/main/res/values-de/strings.xml b/automotive/src/main/res/values-de/strings.xml
index 2b038740..0fdb47d4 100644
--- a/automotive/src/main/res/values-de/strings.xml
+++ b/automotive/src/main/res/values-de/strings.xml
@@ -275,6 +275,7 @@
Tripdaten
Tripauswahl
Dashboard
+ Klassisches Dashboard
Verschiedenes
Manuellert Trip wurde zurückgesetzt
Erneut tippen, um manuellen Trip zurückzusetzen.
diff --git a/automotive/src/main/res/values/strings.xml b/automotive/src/main/res/values/strings.xml
index 487b13ac..03ca1df3 100644
--- a/automotive/src/main/res/values/strings.xml
+++ b/automotive/src/main/res/values/strings.xml
@@ -363,6 +363,7 @@
Trip Data
Trip selection
Dashboard
+ Legacy Dashboard
Miscellaneous
Car Status
Manual Trip has been reset.
diff --git a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/Gauge.kt b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/Gauge.kt
index 3dea87b1..7638477f 100644
--- a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/Gauge.kt
+++ b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/Gauge.kt
@@ -9,6 +9,7 @@ import android.graphics.RectF
import androidx.car.app.CarContext
import com.ixam97.carStatsViewer.CarStatsViewer
import com.ixam97.carStatsViewer.R
+import kotlin.math.max
import kotlin.math.roundToInt
class Gauge(
@@ -70,65 +71,103 @@ class Gauge(
valueString: String? = null,
unitString: String? = null,
selected: Boolean = false
+ ): Bitmap = draw(size, size, value, min, max, valueString, unitString, selected)
+
+ fun draw(
+ width: Int,
+ height: Int,
+ value: Float,
+ min: Float = 0f,
+ max: Float = 100f,
+ valueString: String? = null,
+ unitString: String? = null,
+ selected: Boolean = false
): Bitmap {
- valuePaint.textSize = size / 4f
- unitPaint.textSize = size / 8f
+ valuePaint.textSize = max(width, height) / 4f
+ unitPaint.textSize = max(width, height) / 8f
val bottomLine: Float = if (valueString != null) {
- size - valuePaint.textSize
+ height - valuePaint.textSize
+ } else {
+ height.toFloat()
+ }
+
+ val topLine: Float = if (valueString != null) {
+ valuePaint.textSize
} else {
- size.toFloat()
+ 0f
}
- val bottomOffset = size / 50f
+ val textOffsetY = valuePaint.textSize / 10f
if (min >= max) throw Exception("Min can't be larger than Max!")
- val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
+ val bitmap = Bitmap.createBitmap(max(width, height), max(width, height), Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
- val floatSize = size.toFloat()
+ val floatHeight = height.toFloat()
+ val floatWidth = width.toFloat()
val zeroLineY: Float = bottomLine * (max / (max - min))
+ val zeroLineX: Float = floatWidth - (floatWidth * (max / (max - min)))
var valueLineY: Float = (zeroLineY - value * (bottomLine / (max - min)))
+ var valueLineX: Float = (zeroLineX + value) * (floatWidth / (max - min))
if (valueLineY > bottomLine) valueLineY = bottomLine
else if (valueLineY <= 0) valueLineY = 0f
+ if (valueLineX > floatWidth) valueLineX = floatWidth
+ else if (valueLineX <= 0) valueLineX = 0f
+
if (value > 0 || value < 0) {
gageBarRect.apply {
- left = 0f
- right = floatSize
- bottom = zeroLineY
- top = valueLineY
+ if (width < height) {
+ left = 0f
+ right = floatWidth
+ bottom = zeroLineY
+ top = valueLineY
+ } else {
+ left = zeroLineX
+ right = valueLineX
+ top = topLine
+ bottom = floatHeight
+ }
}
canvas.drawRect(gageBarRect, if (value > 0) posPaint else negPaint)
}
if (min < 0) {
gageZeroLine.apply {
- reset()
- moveTo(0f, zeroLineY)
- lineTo(floatSize, zeroLineY)
+ if (width < height) {
+ reset()
+ moveTo(0f, zeroLineY)
+ lineTo(floatWidth, zeroLineY)
+ close()
+ } else {
+ reset()
+ moveTo(zeroLineX, topLine)
+ lineTo(zeroLineX, floatHeight)
+ close()
+ }
}
canvas.drawPath(gageZeroLine, zeroLinePaint)
}
gageBorder.apply {
reset()
- moveTo(0f + borderPaint.strokeWidth/2, 0f + borderPaint.strokeWidth/2)
- lineTo(0f + borderPaint.strokeWidth/2, bottomLine - borderPaint.strokeWidth/2)
- lineTo(floatSize - borderPaint.strokeWidth/2, bottomLine - borderPaint.strokeWidth/2)
- lineTo(floatSize - borderPaint.strokeWidth/2, 0f + borderPaint.strokeWidth/2)
+ moveTo(0f + borderPaint.strokeWidth/2, topLine + borderPaint.strokeWidth/2)
+ lineTo(0f + borderPaint.strokeWidth/2, floatHeight - borderPaint.strokeWidth/2)
+ lineTo(floatWidth - borderPaint.strokeWidth/2, floatHeight - borderPaint.strokeWidth/2)
+ lineTo(floatWidth - borderPaint.strokeWidth/2, topLine + borderPaint.strokeWidth/2)
close()
}
canvas.drawPath(gageBorder, borderPaint)
valueString?.let { it ->
- canvas.drawText(it, 0f, floatSize - bottomOffset, valuePaint)
+ canvas.drawText(it, 0f, topLine - textOffsetY, valuePaint)
if (unitString != null) {
val xOffset = valuePaint.measureText(valueString) + 10f
- canvas.drawText(unitString, xOffset, floatSize - bottomOffset, unitPaint)
+ canvas.drawText(unitString, xOffset, topLine - textOffsetY, unitPaint)
}
}
@@ -142,12 +181,12 @@ class Gauge(
return bitmap
}
- fun drawPowerGauge(size: Int, value: Float): Bitmap {
+ fun drawPowerGauge(width: Int, height: Int, value: Float): Bitmap {
val valueString = "${((value/1_000_000) * 10).toInt() / 10f }"
- return draw(size, value/1_000_000, min = -150f, max = 300f, valueString, "kW")
+ return draw(width, height, value/1_000_000, min = -150f, max = 300f, valueString, "kW")
}
- fun drawConsumptionGauge(size: Int, valueInstCons: Float?, valueSpeed: Float?): Bitmap {
+ fun drawConsumptionGauge(width: Int, height: Int, valueInstCons: Float?, valueSpeed: Float?): Bitmap {
val instConsVal: Number? = if (valueInstCons != null && (valueSpeed?:0f) * 3.6 > 3) {
if (appPreferences.consumptionUnit) {
appPreferences.distanceUnit.asUnit(valueInstCons).roundToInt()
@@ -168,6 +207,6 @@ class Gauge(
val instCons = if ((valueSpeed?:0f) * 3.6 > 3) valueInstCons else null
- return draw(size, instCons?:0f, -300f, 600f, valueString, consUnit)
+ return draw(width, height, instCons?:0f, -300f, 600f, valueString, consUnit)
}
}
\ No newline at end of file
diff --git a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/MenuTab.kt b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/MenuTab.kt
index 8434edb6..226e858e 100644
--- a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/MenuTab.kt
+++ b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/MenuTab.kt
@@ -34,8 +34,8 @@ internal fun CarStatsViewerScreen.MenuList() = ListTemplate.Builder().apply {
setSingleList(ItemList.Builder().apply {
addItem(Row.Builder().apply{
- setTitle(carContext.getString(R.string.car_app_dashboard))
- setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_diagram)).build())
+ setTitle(carContext.getString(R.string.car_app_legacy_dashboard))
+ setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_car_app_dashboard)).build())
setBrowsable(true)
setOnClickListener {
carContext.startActivity(mainActivityIntent)
@@ -43,7 +43,7 @@ internal fun CarStatsViewerScreen.MenuList() = ListTemplate.Builder().apply {
}.build())
addItem(Row.Builder().apply{
setTitle(carContext.getString(R.string.history_title))
- setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_history)).build())
+ setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_car_app_history)).build())
setBrowsable(true)
setOnClickListener {
carContext.startActivity(historyActivityIntent)
@@ -51,7 +51,7 @@ internal fun CarStatsViewerScreen.MenuList() = ListTemplate.Builder().apply {
}.build())
addItem(Row.Builder().apply{
setTitle(carContext.getString(R.string.settings_title))
- setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_settings)).build())
+ setImage(CarIcon.Builder(IconCompat.createWithResource(carContext, R.drawable.ic_car_app_settings)).build())
setBrowsable(true)
setOnClickListener {
carContext.startActivity(settingsActivityIntent)
diff --git a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/TripDataTemplate.kt b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/TripDataTemplate.kt
index 01461e7b..bf01a025 100644
--- a/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/TripDataTemplate.kt
+++ b/automotive/src/play/java/com/ixam97/carStatsViewer/carApp/TripDataTemplate.kt
@@ -1,5 +1,7 @@
package com.ixam97.carStatsViewer.carApp
+import android.graphics.Bitmap
+import android.graphics.Canvas
import androidx.annotation.OptIn
import androidx.car.app.CarContext
import androidx.car.app.ScreenManager
@@ -82,17 +84,27 @@ class TripDataTemplate(val carContext: CarContext) {
))
}
addAction(configAction(showTitle = true))
- if (session.session_type == 1 && carContext.carAppApiLevel >= 7) {
+ if (session.session_type == 1) {
addAction(resetAction(showTitle = true))
}
val selectedGaugeIndex = CarStatsViewer.appPreferences.carAppSelectedRealTimeData
- if (realTimeData != null) when (selectedGaugeIndex) {
- 1 -> setImage(gauge.drawPowerGauge(480, realTimeData.power?:0f).asCarIcon())
- 2 -> setImage(gauge.drawConsumptionGauge(480, realTimeData.instConsumption, realTimeData.speed).asCarIcon())
- else -> { /* Don't show an image */ }
+ if (realTimeData != null) {
+
+ val gaugeBitmap = Bitmap.createBitmap(480, 480, Bitmap.Config.ARGB_8888)
+ val canvas = Canvas(gaugeBitmap)
+ canvas.drawBitmap(gauge.drawPowerGauge(480, 230, realTimeData.power?:0f), 0f, 0f ,null)
+ canvas.drawBitmap(gauge.drawConsumptionGauge(480, 230, realTimeData.instConsumption, realTimeData.speed), 0f, 250f, null)
+
+ setImage(gaugeBitmap.asCarIcon())
}
+ // if (realTimeData != null) when (selectedGaugeIndex) {
+ // 1 -> setImage(.asCarIcon())
+ // 2 -> setImage(.asCarIcon())
+ // else -> { /* Don't show an image */ }
+ // }
+
}
}.build()).build()
diff --git a/automotive/src/play/res/drawable/ic_car_app_history.xml b/automotive/src/play/res/drawable/ic_car_app_history.xml
new file mode 100644
index 00000000..1b29fc44
--- /dev/null
+++ b/automotive/src/play/res/drawable/ic_car_app_history.xml
@@ -0,0 +1,10 @@
+
+
+