maps P5c: Vela-style driving nav UI
- Commit
ab076db282d4409328b940f4cb063ef256d4fdd8- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 23:36 UTC (3 months ago)
- Parents
3be8d49
Diff
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex d9a81dc9e8..93b404d682 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -213,6 +213,11 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, val navState by com.vayunmathur.maps.util.NavigationSessionManager.state.collectAsState() val isNavigating = navState !is com.vayunmathur.maps.util.NavigationSessionManager.NavState.Idle var autoFollow by remember { mutableStateOf(true) }+ // North-up vs heading-up during navigation (Vela onCompassTap idea).+ var navNorthUp by remember { mutableStateOf(false) }+ // Posted speed limit under the puck (P5b maxspeed overlay; null when the+ // tileset is unhosted or the road has no limit).+ var postedLimit by remember { mutableStateOf<com.vayunmathur.maps.data.PostedLimit?>(null) } var lastProgrammaticMoveMs by remember { mutableStateOf(0L) } val activeRoute = com.vayunmathur.maps.util.NavigationSessionManager.currentRoute val navProgress = (navState as? com.vayunmathur.maps.util.NavigationSessionManager.NavState.Navigating)?.progress@@ -309,21 +314,33 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, // Camera follow: animate to snapped position / bearing whenever we get // a new progress sample AND the user hasn't panned away.- LaunchedEffect(navProgress, autoFollow) {+ LaunchedEffect(navProgress, autoFollow, navNorthUp) { val p = navProgress ?: return@LaunchedEffect if (!autoFollow) return@LaunchedEffect lastProgrammaticMoveMs = System.currentTimeMillis() camera.animateTo( camera.position.copy( target = p.snappedPosition,- bearing = p.courseOverGround.toDouble(),- tilt = 60.0,+ bearing = if (navNorthUp) 0.0 else p.courseOverGround.toDouble(),+ tilt = if (navNorthUp) 0.0 else 60.0, zoom = 17.0, ), kotlin.time.Duration.parse("800ms"), ) } + // Poll the posted speed limit under the puck from the maxspeed overlay+ // (P5b). Inert (always null) until the maxspeed tileset is hosted.+ LaunchedEffect(navProgress) {+ val p = navProgress+ val projection = camera.projection+ postedLimit = if (p != null && projection != null) {+ queryPostedLimit(projection, p.snappedPosition)+ } else {+ null+ }+ }+ // Detect user-initiated camera moves: if isCameraMoving becomes true // outside the ~1.2s window after our own animateTo, treat it as a pan // and disable auto-follow until the user taps Recenter.@@ -628,11 +645,16 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, com.vayunmathur.maps.util.NavigationSessionManager.stop() context.stopService(android.content.Intent(context, com.vayunmathur.maps.util.NavigationService::class.java)) autoFollow = true+ navNorthUp = false }, onDismissArrival = { com.vayunmathur.maps.util.NavigationSessionManager.stop() context.stopService(android.content.Intent(context, com.vayunmathur.maps.util.NavigationService::class.java)) },+ postedLimit = postedLimit,+ northUp = navNorthUp,+ onToggleNorthUp = { navNorthUp = !navNorthUp },+ destinationName = com.vayunmathur.maps.util.NavigationSessionManager.destinationName, ) } }
maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt b/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.ktindex fae44d8117..3835f183cf 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/NavigationOverlay.kt@@ -1,6 +1,5 @@ package com.vayunmathur.maps.ui -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -11,48 +10,57 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.statusBars import androidx.compose.foundation.layout.systemBars-import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.ButtonDefaults import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults import com.vayunmathur.library.ui.ExtendedFloatingActionButton import com.vayunmathur.library.ui.FilledTonalButton+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconCompass+import com.vayunmathur.library.ui.IconList import com.vayunmathur.library.ui.IconLocationOn import com.vayunmathur.library.ui.LinearProgressIndicator import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.SmallFloatingActionButton import com.vayunmathur.library.ui.Text-import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.shadow-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.unit.dp-import androidx.compose.ui.unit.sp import com.vayunmathur.maps.R+import com.vayunmathur.maps.data.PostedLimit+import com.vayunmathur.maps.ui.nav.ArrivalSummary+import com.vayunmathur.maps.ui.nav.ManeuverBanner+import com.vayunmathur.maps.ui.nav.SpeedWidget+import com.vayunmathur.maps.ui.nav.StepsSheet import com.vayunmathur.maps.util.NavigationProgress import com.vayunmathur.maps.util.NavigationSessionManager import com.vayunmathur.maps.util.RouteService import com.vayunmathur.maps.util.formatDistance import com.vayunmathur.maps.util.formatEta-import kotlin.math.roundToInt /** * Full-screen overlay drawn on top of [MaplibreMap] while navigation is- * active. Renders the Google-Maps-style top maneuver card, bottom ETA strip,- * a recenter FAB when the user has panned away from the snapped position,- * and an arrival/failure card for terminal states.+ * active. Renders the Vela-style rich driving UI on top of MA's existing nav+ * session: a maneuver banner (with lane guidance + route shields), a+ * speedometer with posted-limit badge, an expandable step list, the bottom ETA+ * strip, nav controls (recenter + north-up compass toggle), and an+ * arrival/failure card for terminal states. *- * Hidden when state is [NavigationSessionManager.NavState.Idle] — caller is- * responsible for only rendering this composable inside a `Box` overlay.+ * Hidden when state is [NavigationSessionManager.NavState.Idle]. */ @Composable fun NavigationOverlay(@@ -62,20 +70,26 @@ fun NavigationOverlay( onRecenter: () -> Unit, onEndTrip: () -> Unit, onDismissArrival: () -> Unit,+ postedLimit: PostedLimit? = null,+ northUp: Boolean = false,+ onToggleNorthUp: () -> Unit = {},+ destinationName: String? = null, ) { if (navState is NavigationSessionManager.NavState.Idle) return + var showSteps by remember { mutableStateOf(false) }+ Box(Modifier.fillMaxSize()) {- // ---- Top maneuver card ----+ // ---- Top maneuver banner / status ---- when (navState) { is NavigationSessionManager.NavState.Navigating -> {- ManeuverCard(+ ManeuverBanner( progress = navState.progress, steps = steps, modifier = Modifier .align(Alignment.TopCenter) .windowInsetsPadding(WindowInsets.statusBars)- .padding(horizontal = 12.dp, vertical = 8.dp)+ .padding(horizontal = 12.dp, vertical = 8.dp), ) } NavigationSessionManager.NavState.Starting -> {@@ -85,7 +99,7 @@ fun NavigationOverlay( modifier = Modifier .align(Alignment.TopCenter) .windowInsetsPadding(WindowInsets.statusBars)- .padding(horizontal = 12.dp, vertical = 8.dp)+ .padding(horizontal = 12.dp, vertical = 8.dp), ) } NavigationSessionManager.NavState.Recalculating -> {@@ -95,7 +109,7 @@ fun NavigationOverlay( modifier = Modifier .align(Alignment.TopCenter) .windowInsetsPadding(WindowInsets.statusBars)- .padding(horizontal = 12.dp, vertical = 8.dp)+ .padding(horizontal = 12.dp, vertical = 8.dp), ) } is NavigationSessionManager.NavState.Failed -> {@@ -105,23 +119,60 @@ fun NavigationOverlay( modifier = Modifier .align(Alignment.TopCenter) .windowInsetsPadding(WindowInsets.statusBars)- .padding(horizontal = 12.dp, vertical = 8.dp)+ .padding(horizontal = 12.dp, vertical = 8.dp), ) } else -> {} } - // ---- Recenter FAB ----- if (navState is NavigationSessionManager.NavState.Navigating && !autoFollow) {- ExtendedFloatingActionButton(- onClick = onRecenter,+ // ---- Right-edge nav controls (compass north-up toggle + recenter) ----+ if (navState is NavigationSessionManager.NavState.Navigating) {+ Column( modifier = Modifier .align(Alignment.CenterEnd) .padding(16.dp),- icon = {- IconLocationOn()- },- text = { Text(stringResource(R.string.nav_action_recenter)) }+ verticalArrangement = Arrangement.spacedBy(12.dp),+ horizontalAlignment = Alignment.End,+ ) {+ SmallFloatingActionButton(onClick = onToggleNorthUp) {+ IconCompass(+ tint = if (northUp) MaterialTheme.colorScheme.primary+ else MaterialTheme.colorScheme.onSurface,+ )+ }+ if (!autoFollow) {+ ExtendedFloatingActionButton(+ onClick = onRecenter,+ icon = { IconLocationOn() },+ text = { Text(stringResource(R.string.nav_action_recenter)) },+ )+ }+ }+ }++ // ---- Speedometer + posted-limit badge (bottom-left, above ETA) ----+ if (navState is NavigationSessionManager.NavState.Navigating) {+ SpeedWidget(+ speedMps = navState.progress.speedMps,+ postedLimit = postedLimit,+ modifier = Modifier+ .align(Alignment.BottomStart)+ .windowInsetsPadding(WindowInsets.systemBars)+ .padding(start = 16.dp, bottom = 96.dp),+ )+ }++ // ---- Expandable full step list ----+ if (showSteps && navState is NavigationSessionManager.NavState.Navigating) {+ StepsSheet(+ steps = steps,+ currentStepIndex = navState.progress.currentStepIndex,+ onClose = { showSteps = false },+ modifier = Modifier+ .align(Alignment.BottomCenter)+ .fillMaxWidth()+ .padding(bottom = 84.dp)+ .windowInsetsPadding(WindowInsets.systemBars), ) } @@ -131,20 +182,22 @@ fun NavigationOverlay( EtaStrip( progress = navState.progress, onEndTrip = onEndTrip,+ onToggleSteps = { showSteps = !showSteps }, modifier = Modifier .align(Alignment.BottomCenter) .fillMaxWidth()- .windowInsetsPadding(WindowInsets.systemBars)+ .windowInsetsPadding(WindowInsets.systemBars), ) } NavigationSessionManager.NavState.Arrived -> {- ArrivalCard(+ ArrivalSummary( onDismiss = onDismissArrival,+ destinationName = destinationName, modifier = Modifier .align(Alignment.BottomCenter) .fillMaxWidth() .windowInsetsPadding(WindowInsets.systemBars)- .padding(16.dp)+ .padding(16.dp), ) } else -> {}@@ -152,70 +205,6 @@ fun NavigationOverlay( } } -@Composable-private fun ManeuverCard(- progress: NavigationProgress,- steps: List<RouteService.Step>,- modifier: Modifier = Modifier,-) {- val currentStep = steps.getOrNull(progress.currentStepIndex)- val nextStep = steps.getOrNull(progress.currentStepIndex + 1)- // Per plan: we count down to the NEXT step's maneuver. The instruction- // shown is the next maneuver's instruction; the current step's text is- // the "you're currently on" peek line below.- val primary = nextStep ?: currentStep- val primaryInstruction = primary?.navInstruction?.instructions.orEmpty()- val primaryIcon = primary?.navInstruction?.maneuver?.iconContent()- val distanceText = formatDistance(progress.distanceToNextManeuver)-- Card(- modifier = modifier- .fillMaxWidth()- .shadow(8.dp, RoundedCornerShape(16.dp)),- shape = RoundedCornerShape(16.dp),- colors = CardDefaults.cardColors(- containerColor = MaterialTheme.colorScheme.primaryContainer,- contentColor = MaterialTheme.colorScheme.onPrimaryContainer,- ),- ) {- Row(- modifier = Modifier.padding(16.dp),- verticalAlignment = Alignment.CenterVertically,- ) {- if (primaryIcon != null) {- primaryIcon(- Modifier.size(56.dp),- MaterialTheme.colorScheme.onPrimaryContainer,- )- Spacer(Modifier.width(16.dp))- }- Column(Modifier.weight(1f)) {- Text(- distanceText,- fontSize = 28.sp,- fontWeight = FontWeight.Bold,- )- Text(- primaryInstruction,- fontSize = 16.sp,- fontWeight = FontWeight.Medium,- )- if (nextStep != null && currentStep != null && currentStep !== primary) {- val secondary = steps.getOrNull(progress.currentStepIndex + 2)- if (secondary != null) {- Spacer(Modifier.height(4.dp))- Text(- stringResource(R.string.then, secondary.navInstruction.instructions),- fontSize = 12.sp,- color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f),- )- }- }- }- }- }-}- @Composable private fun StatusCard( text: String,@@ -240,6 +229,7 @@ private fun StatusCard( private fun EtaStrip( progress: NavigationProgress, onEndTrip: () -> Unit,+ onToggleSteps: () -> Unit, modifier: Modifier = Modifier, ) { val etaText = formatEta(progress.etaEpochMs)@@ -260,17 +250,15 @@ private fun EtaStrip( verticalAlignment = Alignment.CenterVertically, ) { Column(Modifier.weight(1f)) {- Text(- etaText,- fontSize = 20.sp,- fontWeight = FontWeight.Bold,- )+ Text(etaText, fontSize = 20.sp, fontWeight = FontWeight.Bold) Text( stringResource(R.string.min, remainingMinutes, remainingDistance), fontSize = 14.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, ) }+ IconButton(onClick = onToggleSteps) { IconList() }+ Spacer(Modifier.height(0.dp)) Button( onClick = onEndTrip, colors = ButtonDefaults.buttonColors(@@ -319,34 +307,3 @@ private fun FailureCard( } } }--@Composable-private fun ArrivalCard(- onDismiss: () -> Unit,- modifier: Modifier = Modifier,-) {- Card(- modifier = modifier,- shape = RoundedCornerShape(16.dp),- colors = CardDefaults.cardColors(- containerColor = MaterialTheme.colorScheme.tertiaryContainer,- contentColor = MaterialTheme.colorScheme.onTertiaryContainer,- ),- ) {- Column(- Modifier.padding(20.dp).fillMaxWidth(),- horizontalAlignment = Alignment.CenterHorizontally,- ) {- Text(- stringResource(R.string.nav_arrived_title),- fontSize = 22.sp,- fontWeight = FontWeight.Bold,- textAlign = TextAlign.Center,- )- Spacer(Modifier.height(12.dp))- FilledTonalButton(onClick = onDismiss) {- Text(stringResource(R.string.nav_arrived_dismiss))- }- }- }-}
maps/src/main/java/com/vayunmathur/maps/ui/nav/ArrivalSummary.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/ArrivalSummary.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ArrivalSummary.ktnew file mode 100644index 0000000000..70eb031230--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ArrivalSummary.kt@@ -0,0 +1,71 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.FilledTonalButton+import com.vayunmathur.library.ui.IconCheckCircle+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.maps.R++/**+ * End-of-trip arrival card (Vela's `ArrivalSummary`). Shows a confirmation with+ * the destination name (when known) and a dismiss action that tears down the+ * navigation session.+ */+@Composable+fun ArrivalSummary(+ onDismiss: () -> Unit,+ modifier: Modifier = Modifier,+ destinationName: String? = null,+) {+ Card(+ modifier = modifier,+ shape = RoundedCornerShape(16.dp),+ colors = CardDefaults.cardColors(+ containerColor = MaterialTheme.colorScheme.tertiaryContainer,+ contentColor = MaterialTheme.colorScheme.onTertiaryContainer,+ ),+ ) {+ Column(+ Modifier.padding(20.dp).fillMaxWidth(),+ horizontalAlignment = Alignment.CenterHorizontally,+ ) {+ IconCheckCircle(Modifier.size(40.dp), MaterialTheme.colorScheme.onTertiaryContainer)+ Spacer(Modifier.height(8.dp))+ Text(+ androidx.compose.ui.res.stringResource(R.string.nav_arrived_title),+ fontSize = 22.sp,+ fontWeight = FontWeight.Bold,+ textAlign = TextAlign.Center,+ )+ if (!destinationName.isNullOrBlank()) {+ Spacer(Modifier.height(4.dp))+ Text(+ destinationName,+ fontSize = 14.sp,+ color = MaterialTheme.colorScheme.onTertiaryContainer.copy(alpha = 0.8f),+ textAlign = TextAlign.Center,+ )+ }+ Spacer(Modifier.height(12.dp))+ FilledTonalButton(onClick = onDismiss) {+ Text(androidx.compose.ui.res.stringResource(R.string.nav_arrived_dismiss))+ }+ }+ }+}
maps/src/main/java/com/vayunmathur/maps/ui/nav/LaneGuidance.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/LaneGuidance.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/LaneGuidance.ktnew file mode 100644index 0000000000..f0082f4a38--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/LaneGuidance.kt@@ -0,0 +1,54 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.unit.dp+import com.vayunmathur.maps.ui.iconContent+import com.vayunmathur.maps.util.RouteService++/**+ * Lane-guidance strip (Vela's `LaneDiagram`). Renders one arrow per available+ * turn lane at the upcoming junction, derived by the Rust router (P5a). Lanes+ * that lead onto the taken route are highlighted; the rest are dimmed.+ *+ * Renders nothing when there is no lane data (single continuation, or a router+ * that couldn't resolve the junction).+ */+@Composable+fun LaneGuidance(+ lanes: List<RouteService.API.Lane>,+ modifier: Modifier = Modifier,+ activeColor: Color = Color.White,+ inactiveColor: Color = Color.White.copy(alpha = 0.35f),+) {+ if (lanes.isEmpty()) return+ Box(+ modifier+ .background(Color.Black.copy(alpha = 0.25f), RoundedCornerShape(8.dp))+ .padding(horizontal = 8.dp, vertical = 4.dp),+ ) {+ Row(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically) {+ lanes.forEach { lane ->+ val dir = lane.directions.firstOrNull()+ ?: RouteService.API.Maneuver.STRAIGHT+ val tint = if (lane.active) activeColor else inactiveColor+ val icon = dir.iconContent()+ if (icon != null) {+ icon(Modifier.size(26.dp), tint)+ } else {+ // Fallback glyph for a lane with no drawable maneuver icon.+ Box(Modifier.size(26.dp)) {}+ }+ }+ }+ }+}
maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.ktnew file mode 100644index 0000000000..abbedbb4c3--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/ManeuverBanner.kt@@ -0,0 +1,106 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.shadow+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.maps.R+import com.vayunmathur.maps.ui.iconContent+import com.vayunmathur.maps.util.NavigationProgress+import com.vayunmathur.maps.util.RouteService+import com.vayunmathur.maps.util.formatDistance++/**+ * Rich turn maneuver banner (Vela's `ManeuverBanner`). Shows the upcoming+ * maneuver icon, distance-to-maneuver, the primary instruction (with a route+ * shield when the road carries a ref), a "then" peek at the following+ * maneuver, and a lane-guidance strip from the Rust router's lane data (P5a).+ */+@Composable+fun ManeuverBanner(+ progress: NavigationProgress,+ steps: List<RouteService.Step>,+ modifier: Modifier = Modifier,+) {+ val currentStep = steps.getOrNull(progress.currentStepIndex)+ val nextStep = steps.getOrNull(progress.currentStepIndex + 1)+ // Count down to the NEXT maneuver; the current step is the road we're on.+ val primary = nextStep ?: currentStep+ val primaryInstruction = primary?.navInstruction?.instructions.orEmpty()+ val primaryIcon = primary?.navInstruction?.maneuver?.iconContent()+ val distanceText = formatDistance(progress.distanceToNextManeuver)+ val shield = roadShieldFrom(primaryInstruction)+ // Lanes belong to the upcoming maneuver step.+ val lanes = primary?.lanes.orEmpty()++ Card(+ modifier = modifier+ .fillMaxWidth()+ .shadow(8.dp, RoundedCornerShape(16.dp)),+ shape = RoundedCornerShape(16.dp),+ colors = CardDefaults.cardColors(+ containerColor = MaterialTheme.colorScheme.primaryContainer,+ contentColor = MaterialTheme.colorScheme.onPrimaryContainer,+ ),+ ) {+ Column(Modifier.padding(16.dp)) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ if (primaryIcon != null) {+ primaryIcon(Modifier.size(56.dp), MaterialTheme.colorScheme.onPrimaryContainer)+ Spacer(Modifier.width(16.dp))+ }+ Column(Modifier.weight(1f)) {+ Text(distanceText, fontSize = 28.sp, fontWeight = FontWeight.Bold)+ Row(verticalAlignment = Alignment.CenterVertically) {+ if (shield != null) {+ RouteShield(shield)+ Spacer(Modifier.width(8.dp))+ }+ Text(+ primaryInstruction,+ fontSize = 16.sp,+ fontWeight = FontWeight.Medium,+ modifier = Modifier.weight(1f, fill = false),+ )+ }+ val secondary = steps.getOrNull(progress.currentStepIndex + 2)+ if (nextStep != null && secondary != null) {+ Spacer(Modifier.height(4.dp))+ Text(+ stringResource(R.string.then, secondary.navInstruction.instructions),+ fontSize = 12.sp,+ color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f),+ )+ }+ }+ }+ if (lanes.isNotEmpty()) {+ Spacer(Modifier.height(10.dp))+ LaneGuidance(+ lanes = lanes,+ modifier = Modifier.fillMaxWidth(),+ activeColor = MaterialTheme.colorScheme.onPrimaryContainer,+ inactiveColor = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.3f),+ )+ }+ }+ }+}
maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.ktnew file mode 100644index 0000000000..43ee0255d4--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/RouteShield.kt@@ -0,0 +1,89 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.Text++/** A parsed road shield reference and its rendering style. */+data class RoadShield(val ref: String, val kind: ShieldKind)++enum class ShieldKind { INTERSTATE, US_HIGHWAY, STATE, GENERIC }++/**+ * Derive a US/European route shield from a road name or instruction string+ * (Decision D10 — no dedicated ref field in the graph, so parse it). Matches+ * the common ref forms embedded in the templated instruction text, e.g.+ * "Continue on I-280", "Turn right onto US 101", "Merge onto CA-85", "A4".+ * Returns `null` when no ref token is present (a named local street).+ */+fun roadShieldFrom(text: String?): RoadShield? {+ if (text.isNullOrBlank()) return null++ Regex("""\bI[- ]?(\d{1,3})\b""").find(text)?.let {+ return RoadShield("I-${it.groupValues[1]}", ShieldKind.INTERSTATE)+ }+ Regex("""\bUS[- ]?(\d{1,3})\b""", RegexOption.IGNORE_CASE).find(text)?.let {+ return RoadShield("US ${it.groupValues[1]}", ShieldKind.US_HIGHWAY)+ }+ // State routes like "CA-85", "NY 17", "SR-237".+ Regex("""\b([A-Z]{2})[- ]?(\d{1,3})\b""").find(text)?.let {+ val prefix = it.groupValues[1]+ if (prefix != "US") return RoadShield("$prefix-${it.groupValues[2]}", ShieldKind.STATE)+ }+ // European style motorway/A-road refs: "A4", "M1", "B500".+ Regex("""\b([AMB])(\d{1,4})\b""").find(text)?.let {+ return RoadShield("${it.groupValues[1]}${it.groupValues[2]}", ShieldKind.GENERIC)+ }+ return null+}++/**+ * Render a route shield badge. Colors follow the familiar US conventions+ * (Interstate blue, US-route white, state green) with a neutral fallback.+ * Brand-style colors are intentionally fixed (non-translatable UI chrome).+ */+@Composable+fun RouteShield(shield: RoadShield, modifier: Modifier = Modifier) {+ val bg: Color+ val fg: Color+ val borderColor: Color+ when (shield.kind) {+ ShieldKind.INTERSTATE -> {+ bg = Color(0xFF003F87); fg = Color.White; borderColor = Color.White+ }+ ShieldKind.US_HIGHWAY -> {+ bg = Color.White; fg = Color(0xFF111111); borderColor = Color(0xFF111111)+ }+ ShieldKind.STATE -> {+ bg = Color(0xFF1B5E20); fg = Color.White; borderColor = Color.White+ }+ ShieldKind.GENERIC -> {+ bg = Color(0xFF37474F); fg = Color.White; borderColor = Color(0xFFB0BEC5)+ }+ }+ Box(+ modifier+ .background(bg, RoundedCornerShape(6.dp))+ .border(1.5.dp, borderColor, RoundedCornerShape(6.dp))+ .padding(horizontal = 8.dp, vertical = 3.dp),+ contentAlignment = Alignment.Center,+ ) {+ Text(+ shield.ref,+ color = fg,+ fontSize = 14.sp,+ fontWeight = FontWeight.Bold,+ maxLines = 1,+ )+ }+}
maps/src/main/java/com/vayunmathur/maps/ui/nav/SpeedWidget.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/SpeedWidget.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/SpeedWidget.ktnew file mode 100644index 0000000000..7fb2215afa--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/SpeedWidget.kt@@ -0,0 +1,103 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.shadow+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.maps.data.PostedLimit+import kotlin.math.roundToInt++private const val MPS_TO_KMH = 3.6+private const val MPS_TO_MPH = 2.2369363++/**+ * Speedometer + posted-limit badge (Vela's `SpeedWidget` + `formatSpeedLimit`).+ *+ * Shows the current GPS ground speed in a rounded pill, and — when a posted+ * limit is available from the maxspeed overlay (P5b) — a circular red-ringed+ * limit sign beside it. The display unit follows the posted limit's authored+ * unit when present, otherwise [defaultMph].+ *+ * The current-speed pill tints red when the driver exceeds the posted limit.+ */+@Composable+fun SpeedWidget(+ speedMps: Float,+ postedLimit: PostedLimit?,+ modifier: Modifier = Modifier,+ defaultMph: Boolean = false,+) {+ val useMph = postedLimit?.displayIsMph ?: defaultMph+ val speed = if (useMph) (speedMps * MPS_TO_MPH).roundToInt() else (speedMps * MPS_TO_KMH).roundToInt()+ val limitValue = postedLimit?.let { if (useMph) it.mph else it.kmh }+ val over = limitValue != null && speed > limitValue + 2++ Row(+ modifier,+ horizontalArrangement = Arrangement.spacedBy(8.dp),+ verticalAlignment = Alignment.Bottom,+ ) {+ // Current speed pill.+ Box(+ Modifier+ .shadow(4.dp, CircleShape)+ .background(+ if (over) Color(0xFFD32F2F) else MaterialTheme.colorScheme.surface,+ CircleShape,+ )+ .size(64.dp),+ contentAlignment = Alignment.Center,+ ) {+ Column(horizontalAlignment = Alignment.CenterHorizontally) {+ Text(+ speed.toString().coerceAtMostLength(),+ fontSize = 24.sp,+ fontWeight = FontWeight.Bold,+ color = if (over) Color.White else MaterialTheme.colorScheme.onSurface,+ )+ Text(+ if (useMph) "mph" else "km/h",+ fontSize = 9.sp,+ color = if (over) Color.White else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.7f),+ )+ }+ }++ // Posted-limit sign (only when we have a limit).+ if (limitValue != null) {+ Box(+ Modifier+ .shadow(4.dp, CircleShape)+ .background(Color.White, CircleShape)+ .border(4.dp, Color(0xFFD32F2F), CircleShape)+ .size(56.dp),+ contentAlignment = Alignment.Center,+ ) {+ Text(+ limitValue.toString(),+ fontSize = 20.sp,+ fontWeight = FontWeight.Bold,+ color = Color(0xFF111111),+ )+ }+ }+ }+}++/** Guard against absurd speed readings blowing out the pill width. */+private fun String.coerceAtMostLength(): String = if (length > 3) "999" else this
maps/src/main/java/com/vayunmathur/maps/ui/nav/StepsSheet.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/nav/StepsSheet.kt b/maps/src/main/java/com/vayunmathur/maps/ui/nav/StepsSheet.ktnew file mode 100644index 0000000000..8e31ab7f1e--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/nav/StepsSheet.kt@@ -0,0 +1,96 @@+package com.vayunmathur.maps.ui.nav++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.itemsIndexed+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.HorizontalDivider+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.maps.R+import com.vayunmathur.maps.ui.iconContent+import com.vayunmathur.maps.util.RouteService+import com.vayunmathur.maps.util.formatDistance++/**+ * Full turn-by-turn step list (Vela's `StepsSheet`). Shows every remaining+ * maneuver with its icon, instruction, and distance. Steps already passed are+ * dimmed. Rendered as an overlay card the driver can dismiss.+ */+@Composable+fun StepsSheet(+ steps: List<RouteService.Step>,+ currentStepIndex: Int,+ onClose: () -> Unit,+ modifier: Modifier = Modifier,+) {+ Card(+ modifier = modifier.fillMaxWidth(),+ shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),+ colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surface),+ ) {+ Row(+ Modifier.fillMaxWidth().padding(start = 16.dp, end = 8.dp, top = 8.dp, bottom = 4.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Text(+ stringResource(R.string.nav_steps_title),+ fontSize = 18.sp,+ fontWeight = FontWeight.Bold,+ modifier = Modifier.weight(1f),+ )+ IconButton(onClose) { IconClose() }+ }+ HorizontalDivider()+ LazyColumn(Modifier.fillMaxWidth()) {+ itemsIndexed(steps) { index, step ->+ val dim = index < currentStepIndex+ val alpha = if (dim) 0.4f else 1f+ Row(+ Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 10.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ val icon = step.navInstruction.maneuver.iconContent()+ val tint = MaterialTheme.colorScheme.onSurface.copy(alpha = alpha)+ if (icon != null) {+ icon(Modifier.size(28.dp), tint)+ Spacer(Modifier.width(16.dp))+ } else {+ Spacer(Modifier.width(44.dp))+ }+ Text(+ step.navInstruction.instructions,+ modifier = Modifier.weight(1f),+ color = MaterialTheme.colorScheme.onSurface.copy(alpha = alpha),+ )+ Spacer(Modifier.width(12.dp))+ Text(+ formatDistance(step.distanceMeters),+ color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = alpha),+ fontSize = 13.sp,+ )+ }+ HorizontalDivider(color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.08f))+ }+ item { Spacer(Modifier.size(12.dp)) }+ }+ }+}
maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt b/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.ktindex 62b69fa6c6..c12308c125 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/NavigationSessionManager.kt@@ -278,7 +278,11 @@ object NavigationSessionManager { lastSegmentIndex = snap.segmentIndex val bearing = chooseBearing(location)- val progress = index.deriveProgress(snap, courseOverGround = bearing)+ val progress = index.deriveProgress(+ snap,+ courseOverGround = bearing,+ speedMps = if (location.hasSpeed()) location.speed else 0f,+ ) // Arrival check first — once arrived, stop processing and let the UI // show its end-of-trip card before being torn down.
maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt b/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.ktindex 6ab3055088..0a07e6e639 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PolylineProgress.kt@@ -254,6 +254,8 @@ data class NavigationProgress( val etaEpochMs: Long, val courseOverGround: Float, val distanceOffRoute: Double,+ /** Current GPS ground speed in meters/second (0 when unknown/stationary). */+ val speedMps: Float = 0f, ) /**@@ -265,6 +267,7 @@ fun PolylineIndex.deriveProgress( snap: SnapResult, courseOverGround: Float, nowEpochMs: Long = System.currentTimeMillis(),+ speedMps: Float = 0f, ): NavigationProgress { val currentStepIndex = stepIndexForSegment(snap.segmentIndex) val nextStepStart = if (currentStepIndex + 1 < route.step.size) {@@ -297,5 +300,6 @@ fun PolylineIndex.deriveProgress( etaEpochMs = nowEpochMs + remainingDurationMs, courseOverGround = courseOverGround, distanceOffRoute = snap.distanceOffRoute,+ speedMps = speedMps, ) }
maps/src/main/res/values/strings.xml
diff --git a/maps/src/main/res/values/strings.xml b/maps/src/main/res/values/strings.xmlindex c7e719e452..9d467685c3 100644--- a/maps/src/main/res/values/strings.xml+++ b/maps/src/main/res/values/strings.xml@@ -250,6 +250,8 @@ <string name="nav_action_end">End</string> <!-- Button: Recenter map on user location. Verb. --> <string name="nav_action_recenter">Recenter</string>+ <!-- Header for the full turn-by-turn step list sheet. -->+ <string name="nav_steps_title">Steps</string> <!-- Button: Start navigation for selected mode. Verb. --> <string name="nav_action_start">Start Navigation</string> <!-- Notification content for drive. %1$s=distance/duration, %2$s=ETA time -->