watch: add workout type mapping and tile control trampoline
- Commit
04ff8d9148980dd417d4a80ee17156b30eb13534- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-06 17:46 UTC (5 months ago)
- Parents
5d12bf8
Diff
watch/watch/src/main/java/com/vayunmathur/watch/watch/data/ExerciseTypes.kt
diff --git a/watch/watch/src/main/java/com/vayunmathur/watch/watch/data/ExerciseTypes.kt b/watch/watch/src/main/java/com/vayunmathur/watch/watch/data/ExerciseTypes.ktnew file mode 100644index 0000000000..e783a90ddc--- /dev/null+++ b/watch/watch/src/main/java/com/vayunmathur/watch/watch/data/ExerciseTypes.kt@@ -0,0 +1,47 @@+package com.vayunmathur.watch.watch.data++import androidx.health.services.client.data.ExerciseType++/**+ * Explicit table linking the workout picker to the two distinct enum systems:+ * Health Services [ExerciseType] (what the watch tracks) and Health Connect's+ * `ExerciseSessionRecord.EXERCISE_TYPE_*` int (what the phone writes). The two+ * do not share names or ids, so the mapping is spelled out rather than inferred.+ *+ * The Health Connect int is duplicated as a literal here (the watch module has no+ * connect-client dependency); the values match+ * `androidx.health.connect.client.records.ExerciseSessionRecord`.+ */+enum class WorkoutType(+ val label: String,+ val healthServicesType: ExerciseType,+ val healthConnectType: Int,+ // GPS-backed outdoor activity: request LOCATION + enable GPS for a route.+ val isGpsBased: Boolean = false,+ // Pool swimming: request SWIMMING_LAP_COUNT.+ val isSwimming: Boolean = false,+ // Strength/generic: request REP_COUNT.+ val isRepBased: Boolean = false,+) {+ Walking("Walking", ExerciseType.WALKING, HC_WALKING, isGpsBased = true),+ Running("Running", ExerciseType.RUNNING, HC_RUNNING, isGpsBased = true),+ Biking("Biking", ExerciseType.BIKING, HC_BIKING, isGpsBased = true),+ Hiking("Hiking", ExerciseType.HIKING, HC_HIKING, isGpsBased = true),+ PoolSwimming("Pool Swimming", ExerciseType.SWIMMING_POOL, HC_SWIMMING_POOL, isSwimming = true),+ StrengthTraining("Strength", ExerciseType.STRENGTH_TRAINING, HC_STRENGTH_TRAINING, isRepBased = true),+ Workout("Workout", ExerciseType.WORKOUT, HC_OTHER_WORKOUT, isRepBased = true);++ companion object {+ fun fromHealthServicesName(name: String): WorkoutType? =+ entries.firstOrNull { it.healthServicesType.name == name }+ }+}++// Mirror of ExerciseSessionRecord.EXERCISE_TYPE_* (connect-client 1.2.0-alpha04).+private const val HC_OTHER_WORKOUT = 0+private const val HC_BIKING = 8+private const val HC_HIKING = 37+private const val HC_RUNNING = 56+private const val HC_STRENGTH_TRAINING = 70+private const val HC_SWIMMING_POOL = 74+private const val HC_WALKING = 79
watch/watch/src/main/java/com/vayunmathur/watch/watch/ui/ExerciseControlActivity.kt
diff --git a/watch/watch/src/main/java/com/vayunmathur/watch/watch/ui/ExerciseControlActivity.kt b/watch/watch/src/main/java/com/vayunmathur/watch/watch/ui/ExerciseControlActivity.ktnew file mode 100644index 0000000000..05bfaf8c44--- /dev/null+++ b/watch/watch/src/main/java/com/vayunmathur/watch/watch/ui/ExerciseControlActivity.kt@@ -0,0 +1,31 @@+package com.vayunmathur.watch.watch.ui++import android.app.Activity+import android.os.Bundle+import com.vayunmathur.watch.watch.service.ExerciseService++/**+ * Transparent (Theme.NoDisplay) trampoline that lets the Tile drive the exercise+ * session: Tiles can only fire a [android.content.Intent] (LaunchAction), not+ * call a Service, so PAUSE/RESUME/STOP buttons launch this activity, which+ * forwards to [ExerciseService] and immediately finishes.+ */+class ExerciseControlActivity : Activity() {++ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ when (intent?.getStringExtra(EXTRA_ACTION)) {+ ACTION_PAUSE -> ExerciseService.pause(this)+ ACTION_RESUME -> ExerciseService.resume(this)+ ACTION_STOP -> ExerciseService.stop(this)+ }+ finish()+ }++ companion object {+ const val EXTRA_ACTION = "action"+ const val ACTION_PAUSE = "PAUSE"+ const val ACTION_RESUME = "RESUME"+ const val ACTION_STOP = "STOP"+ }+}