diff --git a/app/src/main/java/org/obd/graphs/ui/gauge/GaugeAdapter.kt b/app/src/main/java/org/obd/graphs/ui/gauge/GaugeAdapter.kt index c97330fe..7d9d42d9 100644 --- a/app/src/main/java/org/obd/graphs/ui/gauge/GaugeAdapter.kt +++ b/app/src/main/java/org/obd/graphs/ui/gauge/GaugeAdapter.kt @@ -36,6 +36,8 @@ import org.obd.graphs.bl.collector.Metric import org.obd.graphs.R import org.obd.graphs.ValueConverter import org.obd.graphs.bl.datalogger.dataLogger +import org.obd.graphs.bl.query.format +import org.obd.graphs.bl.query.valueToFloat import org.obd.graphs.modules import org.obd.graphs.preferences.Prefs import org.obd.graphs.round @@ -129,7 +131,7 @@ class GaugeAdapter( position: Int ) { val metric = data.elementAt(position) - val pid = metric.source.command.pid + val pid = metric.pid() if (!holder.init) { holder.label.text = pid.longDescription ?: pid.description @@ -151,7 +153,7 @@ class GaugeAdapter( holder.value.run { val units = (metric.source.command as ObdCommand).pid.units?:"" - val txt = "${metric.valueToString()} $units" + val txt = "${metric.source.format(castToInt = false)} $units" text = txt highLightText( @@ -162,7 +164,7 @@ class GaugeAdapter( if (pid.historgam.isMinEnabled) { holder.minValue.run { - val txt = "min\n ${metric.toNumber(metric.min)}" + val txt = "min\n ${metric.min.format(pid)}" text = txt highLightText( "min", 0.5f, @@ -174,7 +176,7 @@ class GaugeAdapter( if (pid.historgam.isMaxEnabled) { holder.maxValue.run { - val txt = "max\n ${metric.toNumber(metric.max)} " + val txt = "max\n ${metric.max.format(pid)}" text = txt highLightText( "max", 0.5f, @@ -185,7 +187,7 @@ class GaugeAdapter( if (pid.historgam.isAvgEnabled) { holder.avgValue?.run { - val txt = "avg\n ${metric.toNumber(metric.mean)}" + val txt = "avg\n ${metric.mean.format(pid)}" text = txt highLightText( "avg", 0.5f, @@ -223,7 +225,7 @@ class GaugeAdapter( endValue = it.max.toFloat() } } - value = metric.valueToFloat() + value = metric.source.valueToFloat() invalidate() } } diff --git a/app/src/main/java/org/obd/graphs/ui/graph/TripDetailsViewAdapter.kt b/app/src/main/java/org/obd/graphs/ui/graph/TripDetailsViewAdapter.kt index d68e6e3c..db59c811 100644 --- a/app/src/main/java/org/obd/graphs/ui/graph/TripDetailsViewAdapter.kt +++ b/app/src/main/java/org/obd/graphs/ui/graph/TripDetailsViewAdapter.kt @@ -26,8 +26,8 @@ import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import org.obd.graphs.R -import org.obd.graphs.bl.collector.toNumber import org.obd.graphs.bl.datalogger.dataLogger +import org.obd.graphs.bl.query.format import org.obd.graphs.bl.trip.SensorData import org.obd.graphs.ui.common.COLOR_PHILIPPINE_GREEN import org.obd.graphs.ui.common.setText @@ -58,24 +58,22 @@ class TripDetailsViewAdapter internal constructor( holder.metricName.setText(pid.description, COLOR_PHILIPPINE_GREEN, 1.0f) metric.run { holder.metricMaxValue.setText( - "${toNumber(pid, max)}", + max.format(pid), Color.GRAY, 1.0f ) holder.metricMinValue.setText( - "${toNumber(pid, min)}", + min.format(pid), Color.GRAY, 1.0f ) holder.metricMeanValue.setText( - "${toNumber(pid, mean)}", + mean.format(pid), Color.GRAY, 1.0f ) } } - - } override fun getItemCount(): Int { diff --git a/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt index 343758c1..94af5c3c 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/screen/iot/IotTemplateCarScreen.kt @@ -39,6 +39,7 @@ import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.* import org.obd.graphs.bl.query.Query import org.obd.graphs.bl.query.QueryStrategyType +import org.obd.graphs.bl.query.format import org.obd.graphs.profile.PROFILE_CHANGED_EVENT import org.obd.graphs.renderer.DynamicSelectorMode @@ -231,7 +232,7 @@ internal class IotTemplateCarScreen( metricsCollector.getMetrics().forEach { paneBuilder.addRow( Row.Builder() - .setImage(valueDrawable.draw(it.valueToString(),settings.getColorTheme().progressColor), + .setImage(valueDrawable.draw(it.source.format(castToInt = false),settings.getColorTheme().progressColor), Row.IMAGE_TYPE_LARGE ) .setMetadata(Metadata.Builder().build()) @@ -258,7 +259,8 @@ internal class IotTemplateCarScreen( val title = StringBuilder() title.append(metric.source.command.pid.description.replace("\n","")) title.append("\n") - title.append("· min:${metric.toNumber(metric.min)} avg: ${metric.toNumber(metric.mean)} max: ${metric.toNumber(metric.max)}") + val pid = metric.pid() + title.append("· min:${metric.min.format(pid)} avg: ${metric.mean.format(pid)} max: ${metric.max.format(pid)}") return SpannableString(title) } diff --git a/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt b/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt index 75ece8fc..d9bc0d8b 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/collector/InMemoryCarMetricsCollector.kt @@ -50,10 +50,10 @@ internal class InMemoryCarMetricsCollector : MetricsCollector { Log.d(LOG_KEY, "Rebuilding metrics configuration for: $enabled != ${metrics.keys}") } metricBuilder.buildFor(enabled).forEach { - val key = it.source.command.pid.id + val key = it.pid().id if (metrics.keys.indexOf(key) ==-1) { - Log.i(LOG_KEY, "Adding PID($key = ${it.source.command.pid.description}) to metrics map.") + Log.i(LOG_KEY, "Adding PID($key = ${it.pid().description}) to metrics map.") metrics[key] = it } } diff --git a/datalogger/src/main/java/org/obd/graphs/bl/collector/Metric.kt b/datalogger/src/main/java/org/obd/graphs/bl/collector/Metric.kt index 77dce00d..d512c0cf 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/collector/Metric.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/collector/Metric.kt @@ -18,12 +18,9 @@ **/ package org.obd.graphs.bl.collector -import org.obd.graphs.round import org.obd.metrics.api.model.ObdMetric import org.obd.metrics.pid.PidDefinition -import org.obd.metrics.pid.ValueType -private const val NO_DATA = "----" data class Metric( var source: ObdMetric, @@ -39,33 +36,9 @@ data class Metric( Metric(source, value = value, min = min, max = max, mean = mean, enabled = true, rate = 0.0) } - fun toNumber(value: Double?, doublePrecision: Int = 2): String { - return toNumber(source.command.pid, value, doublePrecision = doublePrecision).toString() - } - fun isInAlert(): Boolean = source.isAlert - fun valueToString(): String = - if (source.value == null) { - NO_DATA - } else { - if (source.value is Number) { - toNumber(source.valueToDouble()) - } else { - source.value.toString() - } - } - - fun valueToFloat(): Float = - if (source.value == null) { - if (source.command.pid.min == null) 0f else source.command.pid.min.toFloat() - } else { - if (source.value is Number) { - source.valueToDouble().toFloat() - }else { - 0f - } - } + fun pid(): PidDefinition = source.command.pid override fun equals(other: Any?): Boolean { if (this === other) return true @@ -80,24 +53,3 @@ data class Metric( return this.source.hashCode() } } - -fun toNumber(pid: PidDefinition, input: Number?, doublePrecision: Int = 2): Number { - - if (input == null) { - return Double.NaN - } - - val value = input.toDouble() - if (value.isNaN()) { - return 0.0 - } - return if (pid.type == null) value.round(doublePrecision) else - pid.type.let { - return when (pid.type) { - ValueType.DOUBLE -> value.round(doublePrecision) - ValueType.INT -> value.toInt() - ValueType.SHORT -> value.toInt() - else -> value.round(1) - } - } -} \ No newline at end of file diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/Formatter.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/Formatter.kt new file mode 100644 index 00000000..34b5d0ae --- /dev/null +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/Formatter.kt @@ -0,0 +1,79 @@ +package org.obd.graphs.bl.query + +import org.obd.graphs.round +import org.obd.metrics.api.model.ObdMetric +import org.obd.metrics.pid.PidDefinition +import org.obd.metrics.pid.ValueType + +private const val NO_DATA = "No data" + +fun ObdMetric.format(castToInt: Boolean = false, precision: Int = 2): String = format( + input = this.value, + pid = null, precision = precision, castToInt = castToInt +) + +fun ObdMetric.valueToFloat(): Float = + if (this.value == null) { + if (this.command.pid.min == null) 0f else this.command.pid.min.toFloat() + } else { + if (this.value is Number) { + this.valueToDouble().toFloat() + } else { + 0f + } + } + +fun ObdMetric.valueToNumber(): Number? = + if (this.value == null) { + null + } else { + if (value is Number) { + value as Number + } else { + null + } + } + + +fun Number.format(pid: PidDefinition, precision: Int = 2, castToInt: Boolean = false): String = format( + input = this, + pid = pid, precision = precision, castToInt = castToInt +) + + +private fun format(input: Any?, pid: PidDefinition? = null, precision: Int = 2, castToInt: Boolean = false): String = + + if (input == null) { + NO_DATA + } else { + if (input is Number) { + val value = input.toDouble() + + if (value.isNaN()) { + NO_DATA + } + + val number = if (pid == null || pid.type == null) { + if (value is Number) { + if (castToInt) (value as Number).toInt().toString() + else if (value is Double) (value as Number).toDouble().round(precision).toString() + else value.toString() + } else { + value.toString() + } + } else { + pid.type.let { + when (pid.type) { + ValueType.DOUBLE -> value.round(precision) + ValueType.INT -> value.toInt() + ValueType.SHORT -> value.toInt() + else -> value.round(1) + } + } + } + + number.toString() + } else { + input.toString() + } + } \ No newline at end of file diff --git a/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt b/datalogger/src/main/java/org/obd/graphs/bl/query/PIDsNamesRegistry.kt similarity index 84% rename from datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt rename to datalogger/src/main/java/org/obd/graphs/bl/query/PIDsNamesRegistry.kt index 99763785..0818de52 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/query/ObdMetricExt.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/query/PIDsNamesRegistry.kt @@ -1,37 +1,10 @@ package org.obd.graphs.bl.query import org.obd.graphs.preferences.Prefs -import org.obd.graphs.round import org.obd.metrics.api.model.ObdMetric fun isGMEExtensionsEnabled() = Prefs.getBoolean(PREF_PROFILE_2_0_GME_EXTENSION_ENABLED, false) - -fun ObdMetric.valueToString(castToInt: Boolean = false, precision: Int = 2): String = - if (this.value == null) { - "No data" - } else { - if (value is Number) { - if (castToInt) (value as Number).toInt().toString() - else if (this.value is Double) (value as Number).toDouble().round(precision).toString() - else this.value.toString() - } else { - "No data" - } - } - -fun ObdMetric.valueToNumber(): Number? = - if (this.value == null) { - null - } else { - if (value is Number) { - value as Number - } else { - null - } - } - - fun ObdMetric.isAtmPressure(): Boolean = command.pid.id == namesRegistry.getAtmPressurePID() fun ObdMetric.isAmbientTemp(): Boolean = command.pid.id == namesRegistry.getAmbientTempPID() diff --git a/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt b/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt index 001445e5..77b71dac 100644 --- a/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt +++ b/dragracing/src/main/java/org/obd/graphs/bl/drag/DragRacingMetricsProcessor.kt @@ -72,10 +72,13 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult } registry.enableShiftLights(obdMetric.valueToNumber()!!.toInt() > registry.getShiftLightsRevThreshold()) } else if (obdMetric.isAtmPressure()) { - atmosphericPressure = obdMetric.valueToNumber()!!.toInt() + obdMetric.valueToNumber()?.let { + atmosphericPressure = it.toInt() + } } else if (obdMetric.isAmbientTemp()) { - ambientTemperature = obdMetric.valueToNumber()!!.toInt() - + obdMetric.valueToNumber()?.let { + ambientTemperature = it.toInt() + } } else if (obdMetric.isVehicleSpeed()) { processVehicleSpeedData(obdMetric) diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractDrawer.kt index 4d64415d..151fe1a5 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/AbstractDrawer.kt @@ -26,6 +26,7 @@ import org.obd.graphs.bl.collector.MetricsCollector import org.obd.graphs.bl.datalogger.WorkflowStatus import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.bl.query.namesRegistry +import org.obd.graphs.bl.query.format import org.obd.graphs.commons.R import org.obd.graphs.profile.profile import org.obd.graphs.renderer.drag.MARGIN_END @@ -245,7 +246,7 @@ internal abstract class AbstractDrawer(context: Context, protected val settings: marginLeft += getTextWidth(text, statusPaint) + 4F drawText( canvas, - "${it.valueToString()}${it.source.command.pid.units}", + "${it.source.format(castToInt = false)}${it.pid().units}", marginLeft, top, Color.WHITE, @@ -270,7 +271,7 @@ internal abstract class AbstractDrawer(context: Context, protected val settings: marginLeft += getTextWidth(text, statusPaint) + 4F drawText( canvas, - "${it.valueToString()}${it.source.command.pid.units}", + "${it.source.format(castToInt = false)}${it.pid().units}", marginLeft, top, Color.WHITE, diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt index d790453e..d33d2c54 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/drag/DragRacingDrawer.kt @@ -24,6 +24,7 @@ import org.obd.graphs.bl.collector.Metric import org.obd.graphs.bl.drag.DragRacingEntry import org.obd.graphs.bl.drag.DragRacingResults import org.obd.graphs.bl.drag.VALUE_NOT_SET +import org.obd.graphs.bl.query.format import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings @@ -194,7 +195,7 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab if (settings.isStatisticsEnabled()) { val tt = textSizeBase * 0.6f var left1 = left - if (metric.source.command.pid.historgam.isMinEnabled) { + if (metric.pid().historgam.isMinEnabled) { left1 = drawText( canvas, "avg", @@ -206,7 +207,7 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab ) left1 = drawText( canvas, - metric.toNumber(metric.mean), + metric.mean.format(pid = metric.pid()), left1, top1, Color.LTGRAY, @@ -214,7 +215,7 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab valuePaint ) } - if (metric.source.command.pid.historgam.isMaxEnabled) { + if (metric.pid().historgam.isMaxEnabled) { left1 = drawText( canvas, "max", @@ -226,7 +227,7 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab ) drawText( canvas, - metric.toNumber(metric.max), + metric.max.format(pid = metric.pid()), left1, top1, Color.LTGRAY, @@ -281,9 +282,10 @@ internal class DragRacingDrawer(context: Context, settings: ScreenSettings) : Ab ) { paint.color = color + val pid = it.pid() val progress = valueConverter.scaleToNewRange( - it.source.valueToNumber()?.toFloat() ?: it.source.command.pid.min.toFloat(), - it.source.command.pid.min.toFloat(), it.source.command.pid.max.toFloat(), left, left + width - MARGIN_END + it.source.valueToNumber()?.toFloat() ?: pid.min.toFloat(), + pid.min.toFloat(), pid.max.toFloat(), left, left + width - MARGIN_END ) canvas.drawRect( diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt index 91f3021d..4058a904 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/gauge/GaugeDrawer.kt @@ -21,6 +21,7 @@ package org.obd.graphs.renderer.gauge import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric +import org.obd.graphs.bl.query.format import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.commons.R import org.obd.graphs.renderer.AbstractDrawer @@ -256,7 +257,7 @@ internal class GaugeDrawer( val userScaleRatio = userScaleRatio(fontSize) - val value = metric.valueToString() + val value = metric.source.format(castToInt = false) val scaleRatio = scaleRationBasedOnScreenSize(area) * userScaleRatio valuePaint.textSize = drawerSettings.valueTextSize * scaleRatio valuePaint.setShadowLayer(radius / 4, 0f, 0f, Color.WHITE) @@ -274,7 +275,8 @@ internal class GaugeDrawer( valuePaint.color = color(R.color.gray) val unitRect = Rect() - val unitTxt = metric.source.command.pid.units + val pid = metric.pid() + val unitTxt = pid.units valuePaint.getTextBounds(unitTxt, 0, unitTxt.length, unitRect) val unitY = centerY - valueHeight canvas.drawText(unitTxt, area.centerX() + textRect.width() / 2 + 4, unitY, valuePaint) @@ -285,7 +287,7 @@ internal class GaugeDrawer( var labelY = 0f - val text = metric.source.command.pid.description.split("\n") + val text = pid.description.split("\n") if (settings.isBreakLabelTextEnabled() && text.size > 1) { labelPaint.textSize *= 0.95f text.forEachIndexed { i, it -> @@ -300,7 +302,7 @@ internal class GaugeDrawer( ) } } else { - val label = metric.source.command.pid.description + val label = pid.description val labelRect = Rect() labelPaint.getTextBounds(label, 0, label.length, labelRect) @@ -310,10 +312,11 @@ internal class GaugeDrawer( } if (settings.isStatisticsEnabled()) { + val hists = - "${if(metric.source.command.pid.historgam.isMinEnabled) metric.toNumber(metric.min) else ""} " + - "${if(metric.source.command.pid.historgam.isAvgEnabled) metric.toNumber(metric.mean) else ""} " + - "${if(metric.source.command.pid.historgam.isMaxEnabled) metric.toNumber(metric.max) else ""}" + "${if(pid.historgam.isMinEnabled) metric.min.format(pid) else ""} " + + "${if(pid.historgam.isAvgEnabled) metric.mean.format(pid) else ""} " + + "${if(pid.historgam.isMaxEnabled) metric.max.format(pid) else ""}" histogramPaint.textSize = 18f * scaleRationBasedOnScreenSize(area) * userScaleRatio val histsRect = Rect() histogramPaint.getTextBounds(hists, 0, hists.length, histsRect) diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt index 5b22ec89..27b8e27d 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/giulia/GiuliaDrawer.kt @@ -21,6 +21,7 @@ package org.obd.graphs.renderer.giulia import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric +import org.obd.graphs.bl.query.format import org.obd.graphs.bl.query.valueToNumber import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings @@ -75,7 +76,7 @@ internal class GiuliaDrawer(context: Context, settings: ScreenSettings): Abstrac ) left1 = drawText( canvas, - metric.toNumber(metric.min), + metric.min.format(pid = metric.pid()), left1, top1, Color.LTGRAY, @@ -93,7 +94,7 @@ internal class GiuliaDrawer(context: Context, settings: ScreenSettings): Abstrac ) left1 = drawText( canvas, - metric.toNumber(metric.max), + metric.max.format(pid = metric.pid()), left1, top1, Color.LTGRAY, @@ -113,7 +114,7 @@ internal class GiuliaDrawer(context: Context, settings: ScreenSettings): Abstrac left1 = drawText( canvas, - metric.toNumber(metric.mean), + metric.mean.format(pid = metric.pid()), left1, top1, Color.LTGRAY, diff --git a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt index 46b1e1ba..600f093b 100644 --- a/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt +++ b/screen_renderer/src/main/java/org/obd/graphs/renderer/trip/TripInfoDrawer.kt @@ -22,8 +22,8 @@ import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.Metric import org.obd.graphs.bl.collector.MetricsBuilder +import org.obd.graphs.bl.query.format import org.obd.graphs.bl.query.valueToNumber -import org.obd.graphs.bl.query.valueToString import org.obd.graphs.renderer.AbstractDrawer import org.obd.graphs.renderer.ScreenSettings import org.obd.graphs.renderer.drag.MARGIN_END @@ -166,7 +166,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst ) left1 = drawText( canvas, - metric.toNumber(metric.min), + metric.min.format(pid = metric.pid()), left1, top1, Color.LTGRAY, @@ -186,7 +186,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst ) drawText( canvas, - metric.toNumber(metric.max), + metric.max.format(metric.pid()), left1, top1, Color.LTGRAY, @@ -298,7 +298,7 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst valuePaint.setShadowLayer(80f, 0f, 0f, Color.WHITE) valuePaint.textSize = textSize - val text = metric.source.valueToString(castToInt = castToInt, precision = valueDoublePrecision) + val text = metric.source.format(castToInt = castToInt, precision = valueDoublePrecision) canvas.drawText(text, left, top, valuePaint) var textWidth = getTextWidth(text, valuePaint) + 2 @@ -314,11 +314,12 @@ internal class TripInfoDrawer(context: Context, settings: ScreenSettings) : Abst if (settings.isStatisticsEnabled() && statsEnabled) { valuePaint.color = Color.LTGRAY valuePaint.textSize = (textSize * 0.60).toFloat() - val itemWidth = textWidth + getTextWidth(metric.toNumber(metric.max), valuePaint) + val pid = metric.pid() + val itemWidth = textWidth + getTextWidth(metric.max.format(pid = pid), valuePaint) if (itemWidth <= maxItemWidth(area)) { - val min = metric.toNumber(metric.min, statsDoublePrecision) + val min = metric.min.format(pid = pid, precision = statsDoublePrecision) canvas.drawText(min, (left + textWidth), top, valuePaint) - canvas.drawText(metric.toNumber(metric.max, statsDoublePrecision), (left + textWidth), top - (getTextHeight(min,valuePaint) * 1.1f), valuePaint) + canvas.drawText(metric.max.format( pid = pid, precision = statsDoublePrecision), (left + textWidth), top - (getTextHeight(min,valuePaint) * 1.1f), valuePaint) } } }