car toasts: match the message popup and stay up longer

A driver only glances at the screen, so short toasts now last 4 seconds and long
ones 7. The card uses the popup's colours, which read better over a map.
This commit is contained in:
Seb3thehacker committed 2026-10-09 14:24:32 -07:00
1 parent 006823232d
commit 179a51ea25
3 files changed
+10 -8

No files matched your search

@@ -4,6 +4,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -39,15 +40,15 @@ internal fun CarToastOverlay(modifier: Modifier = Modifier) {
modifier modifier
.padding(horizontal = 24.dp, vertical = 16.dp) .padding(horizontal = 24.dp, vertical = 16.dp)
.widthIn(max = 560.dp) .widthIn(max = 560.dp)
.clip(MaterialTheme.shapes.medium) .clip(RoundedCornerShape(20.dp))
.background(MaterialTheme.colorScheme.inverseSurface) .background(MaterialTheme.colorScheme.surfaceContainerHigh)
.semantics { liveRegion = LiveRegionMode.Polite }, .semantics { liveRegion = LiveRegionMode.Polite },
) { ) {
Text( Text(
message.text, message.text,
modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp), modifier = Modifier.padding(horizontal = 20.dp, vertical = 12.dp),
color = MaterialTheme.colorScheme.inverseOnSurface, color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodyLarge, style = MaterialTheme.typography.titleMedium,
maxLines = 3, maxLines = 3,
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
) )
@@ -17,7 +17,8 @@ internal object CarToasts {
fun show(owner: Any, text: String, duration: Int) { fun show(owner: Any, text: String, duration: Int) {
if (text.isBlank()) return if (text.isBlank()) return
val durationMs = if (duration == CarToast.LENGTH_LONG) 3_500L else 2_000L // Longer than a phone toast: the driver only glances at the screen now and then.
val durationMs = if (duration == CarToast.LENGTH_LONG) 7_000L else 4_000L
current.value = Message(owner, text, durationMs) current.value = Message(owner, text, durationMs)
} }
@@ -71,10 +71,10 @@ class CarToastsTest {
fun unknownDurationsFallBackToShortRatherThanStayingVisible() { fun unknownDurationsFallBackToShortRatherThanStayingVisible() {
val owner = Any() val owner = Any()
CarToasts.show(owner, "Short", CarToast.LENGTH_SHORT) CarToasts.show(owner, "Short", CarToast.LENGTH_SHORT)
assertEquals(2_000L, CarToasts.message.value?.durationMs) assertEquals(4_000L, CarToasts.message.value?.durationMs)
CarToasts.show(owner, "Long", CarToast.LENGTH_LONG) CarToasts.show(owner, "Long", CarToast.LENGTH_LONG)
assertEquals(3_500L, CarToasts.message.value?.durationMs) assertEquals(7_000L, CarToasts.message.value?.durationMs)
CarToasts.show(owner, "Unknown", Int.MAX_VALUE) CarToasts.show(owner, "Unknown", Int.MAX_VALUE)
assertEquals(2_000L, CarToasts.message.value?.durationMs) assertEquals(4_000L, CarToasts.message.value?.durationMs)
} }
} }