maps: visual imoprovements
- Commit
6a99a8f68a2128970322cb41ac131c6781d974b3- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-09 16:31 UTC (2 months ago)
- Parents
bf0f619
Diff
library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationHint.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationHint.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationHint.ktnew file mode 100644index 0000000000..f26f7f71d5--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationHint.kt@@ -0,0 +1,58 @@+package com.vayunmathur.library.ui++import android.hardware.SensorManager+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Surface+import androidx.compose.material3.Text+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.unit.dp+import com.vayunmathur.library.ui.R++/**+ * The quiet form of [CompassCalibrationBanner]: one line in a pill, for screens where the+ * heading is a detail rather than the subject.+ *+ * A low magnetometer reading is a hint, not a fault. Nothing has failed and nothing is+ * waiting on the user — the heading is simply imprecise, and it often fixes itself as they+ * move. On a compass tool that still deserves a card, because the heading *is* the screen;+ * floating over a map it does not, because it is covering the thing the user came to look at+ * to tell them about a needle they may not be using.+ *+ * So this says the one thing worth acting on — how to fix it — and drops the "Low compass+ * accuracy" title, which only names a state the instruction already implies. It sits on+ * `surfaceContainerHigh`, the same container the map's own chips use, so it reads as another+ * piece of map furniture rather than as an alert, and it wraps its content instead of+ * spanning the width.+ *+ * Shares [CompassCalibrationBanner]'s contract of rendering nothing once the sensor reaches+ * high accuracy, so callers can pass the raw accuracy through without guarding the call site.+ */+@Composable+fun CompassCalibrationHint(accuracy: Int, modifier: Modifier = Modifier) {+ if (accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_HIGH) return++ Surface(+ modifier = modifier,+ shape = MaterialTheme.shapes.extraLarge,+ color = MaterialTheme.colorScheme.surfaceContainerHigh,+ contentColor = MaterialTheme.colorScheme.onSurfaceVariant,+ ) {+ Row(+ modifier = Modifier.padding(horizontal = Spacing.md, vertical = Spacing.sm),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ IconCompass(modifier = Modifier.size(16.dp))+ Text(+ text = stringResource(R.string.compass_calibrate_figure_8),+ modifier = Modifier.padding(start = Spacing.sm),+ style = MaterialTheme.typography.labelMedium,+ )+ }+ }+}
library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.ktindex c4825bb67d..5930bafc2b 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FreeHeightBottomSheet.kt@@ -272,11 +272,18 @@ class FreeHeightSheetState(private val initialValue: SheetValue) { private suspend fun animateToHeight(target: () -> Float) { awaitMeasured() hostAnimations++- // Widen the floor so the animation can leave a hidden sheet, then re-arm it- // on the way out — including on cancellation, when the user grabs the handle- // mid-flight and the drag path takes over.- offset.updateBounds(0f, expandedPx) try {+ // Widen the floor so the animation can leave a hidden sheet, then re-arm it+ // on the way out — including on cancellation, when the user grabs the handle+ // mid-flight and the drag path takes over.+ //+ // Inside the `try`, matching [hide]: it is the only statement between the+ // increment above and the animation that could throw, and if it escaped the+ // count would never come back down. Nothing here enforces the invariant that+ // makes it safe — `expandedPx` is coerced non-negative over in [applyBounds] —+ // and the cost of it being wrong is silent, since a stuck count does not crash,+ // it just quietly costs the sheet its peek floor and its fling for good.+ offset.updateBounds(0f, expandedPx) offset.animateTo(target()) } finally { hostAnimations--
library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaCameraState.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaCameraState.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaCameraState.ktnew file mode 100644index 0000000000..7fa22aac95--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaCameraState.kt@@ -0,0 +1,54 @@+package com.vayunmathur.library.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.Stable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue++/**+ * Where [PanoramaSphere]'s camera is currently pointing, so a caller can project+ * its own overlay into the same scene.+ *+ * Strictly one-way: the renderer publishes here and nothing here feeds back. That+ * is what lets a caller draw things "in" the sphere — Street View's navigation+ * arrows do — without the shared renderer knowing anything about them.+ *+ * The values are written from the touch handler, which runs on the main thread,+ * so reads recompose normally.+ */+@Stable+class PanoramaCameraState {++ private var yawState by mutableFloatStateOf(0f)+ private var pitchState by mutableFloatStateOf(0f)+ private var fovState by mutableFloatStateOf(DEFAULT_FOV_DEG)++ /**+ * World azimuth the camera faces, in radians.+ *+ * The mesh puts source-image column `u` at azimuth `-u * 2pi` (see+ * [PanoramaSphere]), so `u == -yaw / 2pi`.+ */+ val yaw: Float get() = yawState++ /** Camera elevation in radians; positive is up, zero is the horizon. */+ val pitch: Float get() = pitchState++ /** Vertical field of view in degrees, as handed to the projection matrix. */+ val fovDeg: Float get() = fovState++ internal fun publish(yaw: Float, pitch: Float, fovDeg: Float) {+ yawState = yaw+ pitchState = pitch+ fovState = fovDeg+ }++ companion object {+ const val DEFAULT_FOV_DEG = 75f+ }+}++@Composable+fun rememberPanoramaCameraState(): PanoramaCameraState = remember { PanoramaCameraState() }
library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphere.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphere.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphere.ktindex 55fb15a1ef..f774d03132 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphere.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphere.kt@@ -72,16 +72,25 @@ data class PanoramaCrop( * * The surface is rebuilt whenever [textureKey] changes, which is what reloads the * texture and resets the look direction for a new panorama.+ *+ * [cameraState], if given, receives the live look direction so a caller can+ * project an overlay into the same scene. [initialYaw] overrides where the view+ * opens, in radians; the default centres the covered band. A caller stepping+ * between panoramas uses it to carry the viewer's facing across the move. */ @Composable fun PanoramaSphere( crop: PanoramaCrop, textureKey: Any, modifier: Modifier = Modifier,+ cameraState: PanoramaCameraState? = null,+ initialYaw: Float? = null, loadTexture: (maxTextureSize: Int) -> Bitmap?, ) { val context = LocalContext.current- val glView = remember(textureKey) { PanoramaSphereGLView(context, crop, loadTexture) }+ val glView = remember(textureKey) {+ PanoramaSphereGLView(context, crop, initialYaw, cameraState, loadTexture)+ } DisposableEffect(glView) { glView.onResume()@@ -94,10 +103,12 @@ fun PanoramaSphere( private class PanoramaSphereGLView( context: Context, crop: PanoramaCrop,+ initialYaw: Float?,+ private val cameraState: PanoramaCameraState?, loadTexture: (Int) -> Bitmap?, ) : GLSurfaceView(context) { - private val renderer = SphereRenderer(crop, loadTexture)+ private val renderer = SphereRenderer(crop, initialYaw, loadTexture) private val scaleDetector: ScaleGestureDetector private var lastX = 0f@@ -112,10 +123,16 @@ private class PanoramaSphereGLView( override fun onScale(detector: ScaleGestureDetector): Boolean { // Pinch out (scaleFactor > 1) zooms in → narrower FOV. renderer.fov = (renderer.fov / detector.scaleFactor).coerceIn(MIN_FOV, MAX_FOV)+ publishCamera() requestRender() return true } })+ publishCamera()+ }++ private fun publishCamera() {+ cameraState?.publish(renderer.yaw, renderer.pitch, renderer.fov) } override fun onTouchEvent(event: MotionEvent): Boolean {@@ -132,10 +149,11 @@ private class PanoramaSphereGLView( // Drag "grabs" the scene: dragging right/down brings the // content that was to the left/above into view. Scale by FOV // so the feel is consistent across zoom levels.- val speed = DRAG_SPEED * (renderer.fov / DEFAULT_FOV)+ val speed = DRAG_SPEED * (renderer.fov / PanoramaCameraState.DEFAULT_FOV_DEG) renderer.addYaw(dx * speed) renderer.addPitch(dy * speed) lastX = event.x; lastY = event.y+ publishCamera() requestRender() } }@@ -147,7 +165,6 @@ private class PanoramaSphereGLView( companion object { // Radians of rotation per pixel of drag at the default FOV. private const val DRAG_SPEED = 0.0015f- private const val DEFAULT_FOV = 75f private const val MIN_FOV = 30f private const val MAX_FOV = 100f }@@ -155,14 +172,17 @@ private class PanoramaSphereGLView( private class SphereRenderer( private val crop: PanoramaCrop,+ initialYaw: Float?, private val loadTexture: (Int) -> Bitmap?, ) : GLSurfaceView.Renderer { - @Volatile var fov = 75f+ @Volatile var fov = PanoramaCameraState.DEFAULT_FOV_DEG // Look direction, radians. Initialized to the center of the covered band.- @Volatile private var yaw = 0f- @Volatile private var pitch = 0f+ @Volatile var yaw = 0f+ private set+ @Volatile var pitch = 0f+ private set fun addYaw(delta: Float) { yaw += delta } fun addPitch(delta: Float) { pitch = (pitch + delta).coerceIn(-MAX_PITCH, MAX_PITCH) }@@ -189,8 +209,8 @@ private class SphereRenderer( val fullH = crop.fullHeight.toFloat().coerceAtLeast(1f) val centerU = (crop.croppedLeft + crop.croppedWidth / 2f) / fullW val centerV = (crop.croppedTop + crop.croppedHeight / 2f) / fullH- // Longitude of the band center; matches the mesh's theta = u * 2π.- yaw = (centerU * 2.0 * Math.PI).toFloat()+ // Negated to match the mesh, where texture u sits at azimuth -u*2pi.+ yaw = initialYaw ?: (-centerU * 2.0 * Math.PI).toFloat() // Latitude of the band center; matches the mesh's phi = π/2 - v * π. pitch = ((Math.PI / 2.0 - centerV * Math.PI).toFloat()).coerceIn(-MAX_PITCH, MAX_PITCH) }@@ -261,7 +281,12 @@ private class SphereRenderer( for (slice in 0..SLICES) { val uFull = slice.toFloat() / SLICES val theta = uFull * 2.0 * Math.PI- val x = (cosPhi * sin(theta)).toFloat()+ // x is NEGATED so the texture runs the correct way round when the+ // sphere is viewed from the INSIDE. The camera's screen-right is+ // f x up, which decreases azimuth, so mapping u straight to +theta+ // renders the panorama horizontally mirrored (text reads backwards).+ // Placing u at -theta cancels that. Vertical is unaffected.+ val x = (-cosPhi * sin(theta)).toFloat() val y = sinPhi.toFloat() val z = (cosPhi * cos(theta)).toFloat() positions.add(x); positions.add(y); positions.add(z)
library/ui/src/main/java/com/vayunmathur/library/ui/TopAppBarOverlay.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/TopAppBarOverlay.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/TopAppBarOverlay.ktindex ca54b725f1..dd5254281f 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/TopAppBarOverlay.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/TopAppBarOverlay.kt@@ -2,6 +2,7 @@ package com.vayunmathur.library.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -24,8 +25,7 @@ data class OverlayAction( ) /**- * A title-less top bar that overlays full-bleed content rather than occupying- * scaffold height.+ * A top bar that overlays full-bleed content rather than occupying scaffold height. * * Several apps that show a map, photo, or canvas full-bleed need only a back * affordance and a few actions floating over the content. Each had hand-rolled@@ -38,9 +38,12 @@ data class OverlayAction( * `Box { content(); TopAppBarOverlay(Modifier.align(Alignment.TopCenter)) }`). * Every button — the leading back button and each trailing action — is drawn * with an opaque circular background via [FilledTonalIconButton] so icons stay- * legible over any content. The row insets for the status bar- * ([Modifier.statusBarsPadding]), fills the width, and applies horizontal- * [Spacing.lg] and top [Spacing.sm].+ * legible over any content.+ *+ * **The bar itself never draws a container.** That is the whole point of it: the+ * content behind shows straight through, and only the buttons are opaque. A+ * [title] is subject to the same rule — whatever goes in there has to carry its+ * own background if it needs one, exactly as the buttons do. * * Intended for apps that use ONLY this overlay bar (no full [TopAppBar]s * elsewhere on the same screen).@@ -51,32 +54,55 @@ data class OverlayAction( * start. * @param actions trailing actions shown at the end as opaque circular icon * buttons.+ * @param title optional content between the back button and the actions, taking+ * whatever width they leave. It is given no horizontal inset of its own — the+ * screen margin is applied to the button groups instead — so a scrolling title+ * can run to the edge of the window and manage its own content padding rather+ * than being clipped against a margin. Absent by default, which is the shape+ * every caller had before there was one. */ @Composable fun TopAppBarOverlay( modifier: Modifier = Modifier, onNavigateBack: (() -> Unit)? = null, actions: List<OverlayAction> = emptyList(),+ title: (@Composable RowScope.() -> Unit)? = null, ) { Row(+ // The screen margin lives on the two button groups rather than on this row, so a title+ // can span the full width. With no title the result is identical: a full-width row padded+ // by Spacing.lg puts its first and last child in exactly the same place. modifier = modifier .statusBarsPadding() .fillMaxWidth()- .padding(horizontal = Spacing.lg) .padding(top = Spacing.sm), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, ) { if (onNavigateBack != null) {- FilledTonalIconButton(onClick = onNavigateBack) {- IconBack()+ Row(modifier = Modifier.padding(start = Spacing.lg)) {+ FilledTonalIconButton(onClick = onNavigateBack) {+ IconBack()+ } }- } else {- // Keep trailing actions right-aligned when there is no back button.+ }++ if (title != null) {+ // Weighted, so the actions keep their intrinsic width and stay pinned to the end no+ // matter how wide the title wants to be. A title that overflows has to scroll or+ // ellipsize inside this slot; it can never push a button off the screen.+ Row(+ modifier = Modifier.weight(1f),+ verticalAlignment = Alignment.CenterVertically,+ content = title,+ )+ } else if (onNavigateBack == null) {+ // Keep trailing actions right-aligned when there is neither a back button nor a title. Spacer(modifier = Modifier.weight(1f)) } Row(+ modifier = Modifier.padding(end = Spacing.lg), horizontalArrangement = Arrangement.spacedBy(Spacing.sm), verticalAlignment = Alignment.CenterVertically, ) {
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 8b876d2b01..f337430bc0 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -4,6 +4,7 @@ import androidx.activity.compose.BackHandler import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding@@ -23,6 +24,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.CompassCalibrationHint import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.FreeHeightBottomSheetScaffold import com.vayunmathur.library.ui.IconSettings@@ -40,7 +42,6 @@ import com.vayunmathur.maps.Route import com.vayunmathur.maps.data.SavedPlace import com.vayunmathur.maps.data.SpecificFeature import com.vayunmathur.maps.ui.map.LayerToggles-import com.vayunmathur.maps.ui.map.MapBrowseHeader import com.vayunmathur.maps.ui.map.MapFabStack import com.vayunmathur.maps.ui.map.MapOverlay import com.vayunmathur.maps.ui.map.MapOverlays@@ -245,6 +246,19 @@ fun MapPage( // that path owns the pane — see the `pendingFocus` effect above. var searchWasOpen by remember { mutableStateOf(false) } + // Rebuilt only when the label changes: `TopAppBarOverlay` takes a list, so an inline one+ // would be a fresh instance every recomposition of the map.+ val settingsLabel = stringResource(MapsR.string.settings_title)+ val settingsAction = remember(settingsLabel, backStack) {+ listOf(+ OverlayAction(+ icon = { IconSettings() },+ contentDescription = settingsLabel,+ onClick = { backStack.add(Route.SettingsPage) },+ )+ )+ }+ // The two sheets take turns: search covers the place pane while it is up, and hands it back // on the way out. The selection is read off the ViewModel rather than the collected state // because picking a result sets it and closes search in the same breath, and the flow has not@@ -437,21 +451,44 @@ fun MapPage( // The chrome's inset, in one place. `windowInsetsPadding` *consumes* what it // applies, so the pieces below that inset themselves — the FAB stack, the scale- // bar, the navigation overlay — become no-ops rather than insetting twice, and- // the ones that never did, the category chips and the waypoint list, pick up the- // status bar they used to get from the app bar.+ // bar, the navigation overlay, the overlay bar — become no-ops rather than+ // insetting twice, and the waypoint list, which never did, picks up the status+ // bar it used to get from the app bar. Box(Modifier.windowInsetsPadding(WindowInsets.systemBars).fillMaxSize()) {- // Stacked, not overlaid: the settings button and the category chips both want- // the top of the screen, and the chips are a full-width scrolling row that- // would run underneath the button.+ val routeFeature =+ (selectedFeature as? SpecificFeature.Route) ?: inactiveNavigation Column(Modifier.align(Alignment.TopCenter)) { // Turn-by-turn puts its maneuver banner in this exact slot, so the bar // stands down for the duration rather than floating over it. if (!isNavigating) {- TopAppBarOverlay(actions = settingsAction)+ TopAppBarOverlay(+ actions = settingsAction,+ // The chips ride in the bar's title rather than in a row of their+ // own below it. They bring their own filled containers, which is+ // what keeps them readable over the map; the bar itself stays+ // transparent, so the map runs straight through behind them.+ title = {+ // Dropped while a route is up: the waypoint list takes that+ // space and filtering POIs is not what you are doing then —+ // the same rule the chips followed before they moved. The+ // slot stays, so the settings button does not shift.+ if (routeFeature == null) {+ CategoryChips(+ onCategory = { chrome.toggleCategory(it) },+ selected = chrome.selectedCategory,+ // Inside the scroll, never as a margin: the chips have+ // to slide past the screen inset rather than clip+ // against it. The bar gives its title no inset of its+ // own precisely so this can be the only one.+ contentPadding = PaddingValues(+ start = Spacing.lg,+ end = Spacing.sm,+ ),+ )+ }+ },+ ) }- val routeFeature =- (selectedFeature as? SpecificFeature.Route) ?: inactiveNavigation if (routeFeature != null) { WaypointList( route = routeFeature,@@ -459,10 +496,13 @@ fun MapPage( onEditWaypoint = { index -> openSearch(waypointIndex = index) }, ) } else {- MapBrowseHeader(- selectedCategory = chrome.selectedCategory,- onCategory = { chrome.toggleCategory(it) },- headingAccuracy = userHeadingAccuracy,+ // The quiet variant: a hint over the map, not a card. See+ // [CompassCalibrationHint].+ CompassCalibrationHint(+ accuracy = userHeadingAccuracy,+ modifier = Modifier+ .align(Alignment.CenterHorizontally)+ .padding(top = Spacing.sm), ) } }@@ -604,4 +644,22 @@ fun MapPage( chrome.dismissOverlay() coroutineScope.launch { sheetState.partialExpand() } },- onParkingNoteChange = { parkingViewModel.u\ No newline at end of file+ onParkingNoteChange = { parkingViewModel.updateNote(it) },+ selectedStop = selectedTransitStop,+ departures = departuresState,+ onCloseStop = { transitViewModel.closeStop() },+ onRefreshDepartures = { transitViewModel.refresh() },+ )+ }+ }+ }+ }+}++/** End the session and stop the foreground service that outlives this screen. */+private fun stopNavigation(context: android.content.Context) {+ NavigationSessionManager.stop()+ context.stopService(+ android.content.Intent(context, com.vayunmathur.maps.util.NavigationService::class.java)+ )+}
maps/src/main/java/com/vayunmathur/maps/ui/map/MapChrome.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChrome.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChrome.ktindex 8bbdb78cd8..699660c562 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChrome.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChrome.kt@@ -1,13 +1,8 @@ package com.vayunmathur.maps.ui.map import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues 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.runtime.Composable@@ -20,12 +15,8 @@ import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text-import com.vayunmathur.maps.ui.CategoryChips-import com.vayunmathur.library.ui.CompassCalibrationBanner import com.vayunmathur.maps.ui.ContactAddressButton-import com.vayunmathur.maps.ui.MapCategory import com.vayunmathur.maps.ui.VoiceSearchButton-import com.vayunmathur.maps.ui.theme.MapChromeMetrics import com.vayunmathur.maps.R as MapsR /**@@ -65,34 +56,3 @@ fun MapSearchBar( } } }--/**- * The browse-mode row over the map: category chips, plus a compass hint when the heading is bad.- *- * Tapping a chip FILTERS the on-map POIs to that category's OSM types rather than running a text- * search; tapping the active chip clears it.- */-@Composable-fun MapBrowseHeader(- selectedCategory: MapCategory?,- onCategory: (MapCategory) -> Unit,- headingAccuracy: Int,- modifier: Modifier = Modifier,-) {- Column(modifier.padding(vertical = MapChromeMetrics.chromeMargin).fillMaxWidth()) {- CategoryChips(- onCategory = onCategory,- selected = selectedCategory,- modifier = Modifier.fillMaxWidth(),- contentPadding = PaddingValues(horizontal = MapChromeMetrics.chromeMargin),- )- Spacer(Modifier.height(Spacing.sm))- // Only nag when the heading is genuinely unreliable; MEDIUM is good enough to draw a- // puck with, and a banner that is always up is a banner nobody reads.- if (headingAccuracy <= android.hardware.SensorManager.SENSOR_STATUS_ACCURACY_LOW) {- Box(Modifier.padding(horizontal = MapChromeMetrics.chromeMargin)) {- CompassCalibrationBanner(headingAccuracy)- }- }- }-}
maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewArrows.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewArrows.kt b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewArrows.ktnew file mode 100644index 0000000000..8549e59f3d--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewArrows.kt@@ -0,0 +1,198 @@+package com.vayunmathur.maps.ui.streetview++import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxScope+import androidx.compose.foundation.layout.BoxWithConstraints+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.offset+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.key+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.IconStraight+import com.vayunmathur.library.ui.PanoramaCameraState+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.maps.R+import com.vayunmathur.maps.data.google.StreetViewLink+import com.vayunmathur.maps.data.google.StreetViewPano+import kotlin.math.PI+import kotlin.math.atan2+import kotlin.math.cos+import kotlin.math.sin+import kotlin.math.tan++/** Eye height above the road, metres — how far below the horizon arrows sit. */+private const val EYE_HEIGHT_M = 2.5f++/** Ground distance the arrow is drawn at, and the point it aims toward. */+private const val ANCHOR_M = 8f+private const val TIP_M = 14f++private val ARROW_SIZE = 56.dp++/**+ * Navigation arrows drawn into the panorama: one per walkable neighbour, lying on+ * the ground plane pointing down its road, tappable to travel there.+ *+ * Each arrow is pinned to a compass bearing rather than to the screen, so it stays+ * glued to its road while the user looks around. That is the whole point of the+ * control, and it is why this reads [PanoramaCameraState] and re-projects rather+ * than laying out against the viewport.+ *+ * Drawn in Compose over the GL surface, not as scene geometry, so the shared+ * renderer stays free of any navigation concept — it only publishes where the+ * camera points. Hit testing then comes for free: each arrow is a real composable+ * at a projected position, so Compose resolves the tap and everything outside an+ * arrow falls through to the surface underneath and still pans the view.+ */+@Composable+fun BoxScope.StreetViewArrows(+ pano: StreetViewPano,+ camera: PanoramaCameraState,+ modifier: Modifier = Modifier,+ onTravel: (StreetViewLink) -> Unit,+) {+ BoxWithConstraints(modifier.matchParentSize()) {+ val width = constraints.maxWidth.toFloat()+ val height = constraints.maxHeight.toFloat()+ if (width <= 0f || height <= 0f) return@BoxWithConstraints++ val yaw = camera.yaw+ val pitch = camera.pitch+ val fov = camera.fovDeg+ val half = with(LocalDensity.current) { (ARROW_SIZE / 2).toPx() }++ for (link in pano.neighbors) {+ val azimuth = panoYawForBearing(pano.headingDeg, link.bearingDeg)+ val anchor = project(azimuth, groundElevation(ANCHOR_M), yaw, pitch, fov, width, height)+ ?: continue+ val tip = project(azimuth, groundElevation(TIP_M), yaw, pitch, fov, width, height)+ ?: continue+ // Past the frustum edge the projection diverges, so drop anything that+ // lands well outside rather than placing a composable at ±10000 px.+ if (anchor.x < -width || anchor.x > width * 2f) continue++ key(link.panoId) {+ ArrowGlyph(+ offset = IntOffset((anchor.x - half).toInt(), (anchor.y - half).toInt()),+ // IconStraight points up the screen, which is atan2(-1, 0) = -90°.+ rotationDeg = Math.toDegrees(+ atan2(tip.y - anchor.y, tip.x - anchor.x).toDouble()+ ).toFloat() + 90f,+ label = stringResource(R.string.street_view_move, compassPoint(link.bearingDeg)),+ onClick = { onTravel(link) },+ )+ }+ }+ }+}++@Composable+private fun ArrowGlyph(+ offset: IntOffset,+ rotationDeg: Float,+ label: String,+ onClick: () -> Unit,+) {+ Surface(+ onClick = onClick,+ modifier = Modifier+ .offset { offset }+ .size(ARROW_SIZE)+ .semantics { contentDescription = label },+ shape = CircleShape,+ color = Color.White.copy(alpha = 0.85f),+ ) {+ Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ IconStraight(+ Modifier.graphicsLayer { rotationZ = rotationDeg },+ tint = Color.Black.copy(alpha = 0.75f),+ )+ }+ }+}++/**+ * Sphere yaw (radians) that faces true-north [bearingDeg] in a pano captured at+ * [headingDeg].+ *+ * Two steps, both established by measurement against real captures — see+ * `analysis/streetview/FINDINGS.md`. The source equirect puts image column+ * `u = ((bearing - heading + 180) / 360)`, i.e. the capture heading sits at the+ * image centre and `u` increases clockwise. The mesh then places column `u` at+ * azimuth `-u * 2pi`, because the sphere is textured on the inside.+ */+internal fun panoYawForBearing(headingDeg: Double, bearingDeg: Double): Float {+ val u = (((bearingDeg - headingDeg + 180.0) % 360.0) + 360.0) % 360.0 / 360.0+ return (-u * 2.0 * PI).toFloat()+}++/** The inverse: the true-north bearing the viewer faces at [yaw]. */+internal fun panoBearingForYaw(headingDeg: Double, yaw: Float): Double {+ val u = ((-yaw / (2.0 * PI)) % 1.0 + 1.0) % 1.0+ return ((headingDeg - 180.0 + u * 360.0) % 360.0 + 360.0) % 360.0+}++/** Elevation of a point on the road [distanceM] ahead, radians (negative = down). */+private fun groundElevation(distanceM: Float): Float = -atan2(EYE_HEIGHT_M, distanceM)++/**+ * Project a direction onto the viewport, matching the renderer's own camera.+ *+ * Mirrors `setLookAtM` + `perspectiveM`: screen-right is `s = f x up`, and the+ * perspective divide is by the forward depth. Null when the point is behind the+ * camera, which is what culls arrows the user has turned away from.+ */+private fun project(+ azimuth: Float,+ elevation: Float,+ yaw: Float,+ pitch: Float,+ fovDeg: Float,+ width: Float,+ height: Float,+): Offset? {+ val ce = cos(elevation)+ val px = ce * sin(azimuth)+ val py = sin(elevation)+ val pz = ce * cos(azimuth)++ val cp = cos(pitch)+ val fx = cp * sin(yaw)+ val fy = sin(pitch)+ val fz = cp * cos(yaw)++ val forward = fx * px + fy * py + fz * pz+ if (forward <= 0.01f) return null++ val sx = -cos(yaw)+ val sz = sin(yaw)+ val ux = -sin(yaw) * sin(pitch)+ val uz = -cos(yaw) * sin(pitch)++ val xView = sx * px + sz * pz+ val yView = ux * px + cp * py + uz * pz++ val tanHalf = tan(Math.toRadians(fovDeg / 2.0)).toFloat()+ val xNdc = xView / (width / height * tanHalf * forward)+ val yNdc = yView / (tanHalf * forward)++ return Offset((xNdc * 0.5f + 0.5f) * width, (0.5f - yNdc * 0.5f) * height)+}++/** Compass point (8-wind) for a bearing in degrees. */+internal fun compassPoint(bearingDeg: Double): String {+ val dirs = listOf("N", "NE", "E", "SE", "S", "SW", "W", "NW")+ return dirs[(((bearingDeg % 360 + 360) % 360) / 45.0).toInt() % 8]+}
maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.ktindex 09b1fefe1d..ee3c19fbf4 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/streetview/StreetViewScreen.kt@@ -2,17 +2,11 @@ package com.vayunmathur.maps.ui.streetview import android.graphics.Bitmap import androidx.compose.foundation.background-import androidx.compose.foundation.horizontalScroll-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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.rememberScrollState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue@@ -24,19 +18,17 @@ 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.unit.dp+import androidx.compose.ui.text.style.TextAlign import com.vayunmathur.library.ui.CircularProgressIndicator-import com.vayunmathur.library.ui.FilledTonalButton-import com.vayunmathur.library.ui.IconDirectionsWalk import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.PanoramaCrop import com.vayunmathur.library.ui.PanoramaSphere import com.vayunmathur.library.ui.Spacing import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TopAppBarOverlay+import com.vayunmathur.library.ui.rememberPanoramaCameraState import com.vayunmathur.maps.R import com.vayunmathur.maps.data.google.StreetViewDataSource-import com.vayunmathur.maps.data.google.StreetViewLink import com.vayunmathur.maps.data.google.StreetViewPano import kotlinx.coroutines.launch @@ -48,14 +40,21 @@ import kotlinx.coroutines.launch * photos app uses for 360 photos, lifted into `:library:ui`. Dragging looks around * and pinching changes the field of view; there is no flat image to pan. *- * Tapping a neighbour steps to the adjacent pano ([StreetViewPano.neighbors]),- * refetched by id, and the new panorama reloads its own texture.+ * NAVIGATION: arrows drawn into the scene by [StreetViewArrows], one per walkable+ * neighbour, pinned to their compass bearings. Tapping one travels there. */ @Composable fun StreetViewScreen(initialPano: StreetViewPano, onClose: () -> Unit) { var pano by remember { mutableStateOf(initialPano) } var image by remember { mutableStateOf<Bitmap?>(null) } var loading by remember { mutableStateOf(true) }+ // Where to open the next panorama, so a step keeps the viewer facing the way+ // they were already going. Null for the first pano, which opens at the+ // capture heading.+ var carriedYaw by remember { mutableStateOf<Float?>(null) }++ val camera = rememberPanoramaCameraState()+ val scope = rememberCoroutineScope() // Load (and reload on pano change) the stitched equirect off the main thread. LaunchedEffect(pano.panoId) {@@ -68,11 +67,26 @@ fun StreetViewScreen(initialPano: StreetViewPano, onClose: () -> Unit) { Box(Modifier.fillMaxSize().background(Color.Black)) { val current = image when {- current != null -> PanoramaSphere(- crop = PanoramaCrop.full(current.width, current.height),- textureKey = pano.panoId,- modifier = Modifier.fillMaxSize(),- ) { current }+ current != null -> {+ PanoramaSphere(+ crop = PanoramaCrop.full(current.width, current.height),+ textureKey = pano.panoId,+ modifier = Modifier.fillMaxSize(),+ cameraState = camera,+ initialYaw = carriedYaw,+ ) { current }++ StreetViewArrows(pano = pano, camera = camera) { link ->+ // Resolve first, then swap: a failed lookup leaves the viewer+ // where it is rather than blanking the screen.+ val facing = panoBearingForYaw(pano.headingDeg, camera.yaw)+ scope.launch {+ val next = StreetViewDataSource.byPano(link.panoId) ?: return@launch+ carriedYaw = panoYawForBearing(next.headingDeg, facing)+ pano = next+ }+ }+ } loading -> CircularProgressIndicator(Modifier.align(Alignment.Center), color = Color.White) else -> Text( stringResource(R.string.street_view_unavailable),@@ -83,49 +97,19 @@ fun StreetViewScreen(initialPano: StreetViewPano, onClose: () -> Unit) { TopAppBarOverlay(Modifier.align(Alignment.TopStart), onNavigateBack = onClose) - Column(+ Attribution(+ pano = pano, modifier = Modifier .align(Alignment.BottomCenter) .fillMaxWidth() .navigationBarsPadding() .padding(Spacing.md),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(Spacing.sm),- ) {- if (pano.neighbors.isNotEmpty()) {- NeighborSteps(pano.neighbors) { link -> stepTo(link) { pano = it } }- }- Attribution(pano)- }+ ) } } -/** Load a neighbour pano and, if it resolves, swap to it (else keep the current). */-private suspend fun stepTo(link: StreetViewLink, onResolved: (StreetViewPano) -> Unit) {- StreetViewDataSource.byPano(link.panoId)?.let(onResolved)-}- @Composable-private fun NeighborSteps(neighbors: List<StreetViewLink>, onStep: suspend (StreetViewLink) -> Unit) {- val scope = rememberCoroutineScope()- Row(- Modifier.horizontalScroll(rememberScrollState()),- horizontalArrangement = Arrangement.spacedBy(Spacing.sm),- ) {- neighbors.forEach { link ->- FilledTonalButton(onClick = { scope.launch { onStep(link) } }) {- IconDirectionsWalk(Modifier.size(18.dp))- Text(- " ${compass(link.bearingDeg)} · ${link.distanceM.toInt()} m",- style = MaterialTheme.typography.labelMedium,- )- }- }- }-}--@Composable-private fun Attribution(pano: StreetViewPano) {+private fun Attribution(pano: StreetViewPano, modifier: Modifier = Modifier) { val date = if (pano.captureYear != null && pano.captureMonth != null) { " · ${pano.captureYear}-${pano.captureMonth.toString().padStart(2, '0')}" } else {@@ -135,11 +119,7 @@ private fun Attribution(pano: StreetViewPano) { (pano.copyright ?: "\u00A9 Google") + date, color = Color.White.copy(alpha = 0.7f), style = MaterialTheme.typography.labelSmall,+ textAlign = TextAlign.Center,+ modifier = modifier, ) }--/** Compass point (8-wind) for a bearing in degrees. */-private fun compass(bearingDeg: Double): String {- val dirs = listOf("N", "NE", "E", "SE", "S", "SW", "W", "NW")- return dirs[(((bearingDeg % 360 + 360) % 360) / 45.0).toInt() % 8]-}
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 07ebdb355d..14bad8b05d 100644--- a/maps/src/main/res/values/strings.xml+++ b/maps/src/main/res/values/strings.xml@@ -115,6 +115,10 @@ <string name="street_view_loading">Loading Street View…</string> <!-- Street View viewer: shown when no panorama could be loaded for this place. --> <string name="street_view_unavailable">Street View is not available here</string>+ <!-- Street View: content description of a navigation arrow lying on the road in the+ panorama. %1$s = 8-wind compass point such as "NE". Tapping it moves to the+ adjacent panorama in that direction. -->+ <string name="street_view_move">Move <xliff:g id="direction" example="NE">%1$s</xliff:g></string> <!-- MapPage: content description of the peg you drag off the map controls and drop on a point to open Street View there. --> <string name="street_view_peg">Drag onto the map to open Street View</string>