diff --git a/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt b/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt index 29d32c19..f4c57872 100644 --- a/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt +++ b/automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt @@ -118,6 +118,7 @@ internal class CarScreen( } DATA_LOGGER_CONNECTING_EVENT -> { + surfaceController.renderFrame() invalidate() toast.show(carContext, R.string.main_activity_toast_connection_connecting) } @@ -146,6 +147,11 @@ internal class CarScreen( invalidate() } + DATA_LOGGER_STOPPING_EVENT -> { + surfaceController.renderFrame() + invalidate() + } + DATA_LOGGER_ERROR_CONNECT_EVENT -> { invalidate() toast.show(carContext, R.string.main_activity_toast_connection_connect_error) diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLogger.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLogger.kt index fc3609b3..da8e4a52 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLogger.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLogger.kt @@ -9,6 +9,7 @@ import org.obd.metrics.pid.PidDefinitionRegistry interface DataLogger { val eventsReceiver: BroadcastReceiver + fun status(): WorkflowStatus fun observe(lifecycleOwner: LifecycleOwner, observer: (metric: ObdMetric) -> Unit) fun isRunning(): Boolean diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt index dd74b7ee..8b704135 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/DataLoggerService.kt @@ -42,6 +42,8 @@ class DataLoggerService : JobIntentService(), DataLogger { } } + override fun status(): WorkflowStatus = workflowOrchestrator.status() + override fun scheduleStart(delay: Long) { enqueueWork(SCHEDULED_ACTION_START) { it.putExtra(SCHEDULED_START_DELAY, delay) diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowOrchestrator.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowOrchestrator.kt index 3f98702b..39222711 100644 --- a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowOrchestrator.kt +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowOrchestrator.kt @@ -47,11 +47,13 @@ internal class WorkflowOrchestrator internal constructor() { private var lifecycle = object : Lifecycle { override fun onConnecting() { + status = WorkflowStatus.Connecting Log.i(LOGGER_TAG, "Start collecting process") sendBroadcastEvent(DATA_LOGGER_CONNECTING_EVENT) } override fun onRunning(vehicleCapabilities: VehicleCapabilities) { + status = WorkflowStatus.Connected Log.i(LOGGER_TAG, "We are connected to the vehicle: $vehicleCapabilities") vehicleCapabilitiesManager.updateCapabilities(vehicleCapabilities) sendBroadcastEvent(DATA_LOGGER_CONNECTED_EVENT) @@ -73,6 +75,7 @@ internal class WorkflowOrchestrator internal constructor() { } override fun onStopped() { + status = WorkflowStatus.Disconnected Log.i( LOGGER_TAG, "Collecting process is completed." @@ -81,12 +84,14 @@ internal class WorkflowOrchestrator internal constructor() { } override fun onStopping() { + status = WorkflowStatus.Stopping Log.i(LOGGER_TAG, "Stopping collecting process...") sendBroadcastEvent(DATA_LOGGER_STOPPING_EVENT) } } private var workflow: Workflow = workflow() + private var status = WorkflowStatus.Disconnected fun observe(lifecycleOwner: LifecycleOwner, observer: (metric: ObdMetric) -> Unit) = metricsObserver.observe(lifecycleOwner){ @@ -95,6 +100,7 @@ internal class WorkflowOrchestrator internal constructor() { } } + fun status(): WorkflowStatus = status fun isRunning(): Boolean = workflow.isRunning diff --git a/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowStatus.kt b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowStatus.kt new file mode 100644 index 00000000..68f62163 --- /dev/null +++ b/datalogger/src/main/java/org/obd/graphs/bl/datalogger/WorkflowStatus.kt @@ -0,0 +1,5 @@ +package org.obd.graphs.bl.datalogger + +enum class WorkflowStatus { + Connected, Disconnected, Connecting, Stopping +} \ No newline at end of file diff --git a/giulia_renderer/src/main/java/org/obd/graphs/renderer/DrawingManager.kt b/giulia_renderer/src/main/java/org/obd/graphs/renderer/DrawingManager.kt index 3934c2a5..e214b22c 100644 --- a/giulia_renderer/src/main/java/org/obd/graphs/renderer/DrawingManager.kt +++ b/giulia_renderer/src/main/java/org/obd/graphs/renderer/DrawingManager.kt @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.* import org.obd.graphs.bl.collector.CarMetric import org.obd.graphs.ValueScaler +import org.obd.graphs.bl.datalogger.WorkflowStatus import org.obd.graphs.bl.datalogger.dataLogger import org.obd.graphs.commons.R import org.obd.graphs.preferences.Prefs @@ -30,8 +31,6 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet BitmapFactory.decodeResource(context.resources, R.drawable.background) private val statusLabel: String - private val statusConnected: String - private val statusDisconnected: String private val profileLabel: String private val fpsLabel: String @@ -55,8 +54,6 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet profileLabel = context.resources.getString(R.string.status_bar_profile) fpsLabel = context.resources.getString(R.string.status_bar_fps) statusLabel = context.resources.getString(R.string.status_bar_status) - statusConnected = context.resources.getString(R.string.status_bar_connected) - statusDisconnected = context.resources.getString(R.string.status_bar_disconnected) } fun updateCanvas(canvas: Canvas) { @@ -149,7 +146,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet text, horizontalAlignment, statusVerticalPos, - Color.WHITE, + Color.LTGRAY, 12f, statusPaint ) @@ -158,12 +155,16 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet val color: Int val colorTheme = settings.colorTheme() - if (dataLogger.isRunning()) { - text = statusConnected - color = colorTheme.statusConnectedColor - } else { - text = statusDisconnected - color = colorTheme.statusDisconnectedColor + text = dataLogger.status().name.lowercase() + + color = when (dataLogger.status()) { + WorkflowStatus.Disconnected -> colorTheme.statusDisconnectedColor + + WorkflowStatus.Stopping -> colorTheme.statusDisconnectedColor + + WorkflowStatus.Connecting -> colorTheme.statusConnectingColor + + WorkflowStatus.Connected -> colorTheme.statusConnectedColor } drawText( @@ -182,7 +183,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet text, horizontalAlignment, statusVerticalPos, - Color.WHITE, + Color.LTGRAY, 12f, statusPaint ) diff --git a/giulia_renderer/src/main/java/org/obd/graphs/renderer/ScreenSettings.kt b/giulia_renderer/src/main/java/org/obd/graphs/renderer/ScreenSettings.kt index abb90cb4..b025fcb6 100644 --- a/giulia_renderer/src/main/java/org/obd/graphs/renderer/ScreenSettings.kt +++ b/giulia_renderer/src/main/java/org/obd/graphs/renderer/ScreenSettings.kt @@ -10,14 +10,15 @@ enum class DynamicSelectorMode { data class ColorTheme(val dividerColor: Int = Color.WHITE, var progressColor: Int = COLOR_CARDINAL, + val statusConnectingColor: Int = Color.YELLOW, val statusConnectedColor: Int = Color.GREEN, - val statusDisconnectedColor: Int = Color.YELLOW, + val statusDisconnectedColor: Int = COLOR_DYNAMIC_SELECTOR_SPORT, val currentValueColor: Int = Color.WHITE, val currentValueInAlertColor: Int = COLOR_DYNAMIC_SELECTOR_SPORT, - val currentProfileColor: Int = Color.YELLOW, + val currentProfileColor: Int = Color.WHITE, val actionsBtnConnectColor: Int = Color.GREEN, val actionsBtnDisconnectColor: Int = Color.RED, - val actionsBtnVirtualScreensColor: Int = Color.YELLOW) + val actionsBtnVirtualScreensColor: Int = Color.WHITE) interface ScreenSettings { diff --git a/giulia_renderer/src/main/res/values/strings.xml b/giulia_renderer/src/main/res/values/strings.xml index b812f801..0a927b3b 100644 --- a/giulia_renderer/src/main/res/values/strings.xml +++ b/giulia_renderer/src/main/res/values/strings.xml @@ -13,6 +13,4 @@ status: profile: fps: - connected - disconnected \ No newline at end of file