Skip to content

Commit

Permalink
Added real time altitude to trip data screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixam97 committed May 6, 2024
1 parent 39a586a commit 2908949
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 59 deletions.
4 changes: 2 additions & 2 deletions automotive/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
defaultConfig {
minSdkVersion 29
targetSdkVersion 33
versionCode 233
versionName "0.27.0.0027"
versionCode 234
versionName "0.27.0.0028"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
104 changes: 54 additions & 50 deletions automotive/src/carapp/java/com/ixam97/carStatsViewer/carApp/Gauge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class Gauge(
max: Float = 100f,
valueString: String? = null,
unitString: String? = null,
selected: Boolean = false
): Bitmap = draw(size, size, value, min, max, valueString, unitString, selected)
selected: Boolean = false,
textOnly: Boolean = false,
): Bitmap = draw(size, size, value, min, max, valueString, unitString, selected, textOnly)

fun draw(
width: Int,
Expand All @@ -81,7 +82,8 @@ class Gauge(
max: Float = 100f,
valueString: String? = null,
unitString: String? = null,
selected: Boolean = false
selected: Boolean = false,
textOnly: Boolean = false,
): Bitmap {

valuePaint.textSize = max(width, height) / 4f
Expand All @@ -108,60 +110,62 @@ class Gauge(
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 {
if (width < height) {
left = 0f
right = floatWidth
bottom = zeroLineY
top = valueLineY
} else {
left = zeroLineX
right = valueLineX
top = topLine
bottom = floatHeight
if (!textOnly) {
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 {
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)
}
canvas.drawRect(gageBarRect, if (value > 0) posPaint else negPaint)
}

if (min < 0) {
gageZeroLine.apply {
if (width < height) {
reset()
moveTo(0f, zeroLineY)
lineTo(floatWidth, zeroLineY)
close()
} else {
reset()
moveTo(zeroLineX, topLine)
lineTo(zeroLineX, floatHeight)
close()
if (min < 0) {
gageZeroLine.apply {
if (width < height) {
reset()
moveTo(0f, zeroLineY)
lineTo(floatWidth, zeroLineY)
close()
} else {
reset()
moveTo(zeroLineX, topLine)
lineTo(zeroLineX, floatHeight)
close()
}
}
canvas.drawPath(gageZeroLine, zeroLinePaint)
}
canvas.drawPath(gageZeroLine, zeroLinePaint)
}

gageBorder.apply {
reset()
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()
gageBorder.apply {
reset()
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)
}
canvas.drawPath(gageBorder, borderPaint)

valueString?.let { it ->
canvas.drawText(it, 0f, topLine - textOffsetY, valuePaint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ixam97.carStatsViewer.carApp

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import androidx.annotation.OptIn
import androidx.car.app.CarContext
import androidx.car.app.ScreenManager
Expand Down Expand Up @@ -62,11 +63,6 @@ class TripDataTemplate(val carContext: CarContext) {
carContext.getString(R.string.summary_traveled_distance),
R.drawable.ic_distance_large
))
addRow(createDataRow(
StringFormatters.getEnergyString(it.used_energy.toFloat()),
carContext.getString(R.string.summary_used_energy),
R.drawable.ic_energy_large
))
addRow(createDataRow(
StringFormatters.getAvgConsumptionString(it.used_energy.toFloat(), it.driven_distance.toFloat()),
carContext.getString(R.string.summary_average_consumption),
Expand All @@ -82,6 +78,11 @@ class TripDataTemplate(val carContext: CarContext) {
carContext.getString(R.string.summary_travel_time),
R.drawable.ic_time_large
))
addRow(createDataRow(
StringFormatters.getEnergyString(it.used_energy.toFloat()),
carContext.getString(R.string.summary_used_energy),
R.drawable.ic_energy_large
))
}
addAction(configAction(showTitle = true))
if (session.session_type == 1) {
Expand All @@ -93,8 +94,9 @@ class TripDataTemplate(val carContext: CarContext) {

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)
canvas.drawBitmap(gauge.drawPowerGauge(480, 170, realTimeData.power?:0f), 0f, 0f ,null)
canvas.drawBitmap(gauge.drawConsumptionGauge(480, 170, realTimeData.instConsumption, realTimeData.speed), 0f, 180f, null)
canvas.drawBitmap(gauge.draw(width = 480, height = 140, value = realTimeData.alt?:0f, valueString = realTimeData.alt?.toInt().toString(), unitString = "m", textOnly = true), 0f, 360f, null)

setImage(gaugeBitmap.asCarIcon())
}
Expand Down

0 comments on commit 2908949

Please sign in to comment.