library/ui: add CompassCalibrationBanner (low compass accuracy / figure-8 calibrate)
- Commit
6172d6ed693934ae7724054bc78e775e3eff7547- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 02:12 UTC (3 months ago)
- Parents
293a033
Diff
library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationBanner.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationBanner.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationBanner.ktnew file mode 100644index 0000000000..d19dcd5482--- /dev/null+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/CompassCalibrationBanner.kt@@ -0,0 +1,52 @@+package com.vayunmathur.library.ui++import android.hardware.SensorManager+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.RoundedCornerShape+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++/**+ * Banner shown when the magnetometer reports low accuracy. Renders nothing once the+ * sensor reaches high accuracy, so callers can pass the raw accuracy through without+ * guarding the call site.+ */+@Composable+fun CompassCalibrationBanner(accuracy: Int, modifier: Modifier = Modifier) {+ if (accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_HIGH) return++ Surface(+ modifier = modifier.fillMaxWidth(),+ shape = RoundedCornerShape(16.dp),+ color = MaterialTheme.colorScheme.tertiaryContainer,+ contentColor = MaterialTheme.colorScheme.onTertiaryContainer,+ ) {+ Row(+ modifier = Modifier.padding(16.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ IconCompass(modifier = Modifier.size(28.dp))+ Column(modifier = Modifier.padding(start = 16.dp)) {+ Text(+ text = stringResource(R.string.compass_low_accuracy_title),+ style = MaterialTheme.typography.titleSmall,+ )+ Text(+ text = stringResource(R.string.compass_calibrate_figure_8),+ style = MaterialTheme.typography.bodySmall,+ )+ }+ }+ }+}
library/ui/src/main/res/values/strings.xml
diff --git a/library/ui/src/main/res/values/strings.xml b/library/ui/src/main/res/values/strings.xmlindex 7a28942030..ef7ae20680 100644--- a/library/ui/src/main/res/values/strings.xml+++ b/library/ui/src/main/res/values/strings.xml@@ -82,4 +82,8 @@ <string name="clear">Clear</string> <string name="share">Share</string> <string name="undo">Undo</string>+ <!-- Shared library: UI – CompassCalibrationBanner: Emphasized title line shown when the magnetometer reports low accuracy -->+ <string name="compass_low_accuracy_title">Low compass accuracy</string>+ <!-- Shared library: UI – CompassCalibrationBanner: Instruction line telling the user how to recalibrate the compass -->+ <string name="compass_calibrate_figure_8">Move phone in a figure 8 to calibrate</string> </resources>