auto: render car views via library:carhost
- Commit
1ef345d9d35c7f30810cf35713f7797013dad116- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-20 02:01 UTC (2 months ago)
- Parents
fdafc75
Diff
auto/build.gradle.kts
diff --git a/auto/build.gradle.kts b/auto/build.gradle.ktsindex 30c2868856..d0703aa254 100644--- a/auto/build.gradle.kts+++ b/auto/build.gradle.kts@@ -14,6 +14,10 @@ dependencies { // The GAL wire format. Nothing in the app re-implements it, and keeping it out of here is // what lets the handshake be tested on the JVM. implementation(project(":auto:protocol"))+ // Car template rendering (HostTemplate model + parsers + Compose renderers) lives in+ // :library:carhost so apps can render their own car views in screenshot tests without+ // depending on this app. This module supplies the real TextureView map island.+ implementation(project(":library:carhost")) // Media3 controller for the Phase 4 now-playing feed from the on-device media session. implementation(libs.androidx.media3.session) // Car App Library host: CarAppHost binds the :maps car-app service and
auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt b/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.ktindex 1a7c43936c..b501b5dfd1 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt@@ -16,6 +16,7 @@ import androidx.lifecycle.setViewTreeViewModelStoreOwner import androidx.savedstate.setViewTreeSavedStateRegistryOwner import com.vayunmathur.auto.BuildConfig import com.vayunmathur.auto.protocol.NavSnapshot+import com.vayunmathur.library.carhost.HostNavState import java.util.concurrent.ExecutionException import java.util.concurrent.FutureTask
auto/src/main/java/com/vayunmathur/auto/platform/CarLauncherState.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/CarLauncherState.kt b/auto/src/main/java/com/vayunmathur/auto/platform/CarLauncherState.ktindex 33447c9a70..49b06c1baa 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/CarLauncherState.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/CarLauncherState.kt@@ -1,6 +1,8 @@ package com.vayunmathur.auto.platform import android.view.Surface+import com.vayunmathur.library.carhost.HostNavState+import com.vayunmathur.library.carhost.HostTemplate import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow
auto/src/main/java/com/vayunmathur/auto/platform/CarPresentation.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/CarPresentation.kt b/auto/src/main/java/com/vayunmathur/auto/platform/CarPresentation.ktindex 9c7d3c6059..3bd8b92d9c 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/CarPresentation.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/CarPresentation.kt@@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import com.vayunmathur.auto.ui.LauncherRoot+import com.vayunmathur.library.carhost.HostNavState import com.vayunmathur.library.ui.DynamicTheme /**
auto/src/main/java/com/vayunmathur/auto/platform/HostManager.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/HostManager.kt b/auto/src/main/java/com/vayunmathur/auto/platform/HostManager.ktindex b97f1dc4e5..fdbb56814f 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/HostManager.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/HostManager.kt@@ -4,6 +4,9 @@ import android.content.ComponentName import android.content.Context import android.util.Log import android.view.Surface+import com.vayunmathur.library.carhost.HostAction+import com.vayunmathur.library.carhost.HostNavState+import com.vayunmathur.library.carhost.HostTemplate import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow
auto/src/main/java/com/vayunmathur/auto/platform/HostSession.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/HostSession.kt b/auto/src/main/java/com/vayunmathur/auto/platform/HostSession.ktindex 4137895bfb..1dbf4f92bd 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/HostSession.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/HostSession.kt@@ -26,6 +26,8 @@ import androidx.car.app.SurfaceContainer import androidx.car.app.constraints.IConstraintHost import androidx.car.app.navigation.INavigationHost import androidx.car.app.serialization.Bundleable+import com.vayunmathur.library.carhost.HostTemplate+import com.vayunmathur.library.carhost.HostTemplateParsers import java.security.InvalidParameterException import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit
auto/src/main/java/com/vayunmathur/auto/platform/HostTemplateState.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/HostTemplateState.kt b/auto/src/main/java/com/vayunmathur/auto/platform/HostTemplateState.ktdeleted file mode 100644index 036695178b..0000000000--- a/auto/src/main/java/com/vayunmathur/auto/platform/HostTemplateState.kt+++ /dev/null@@ -1,728 +0,0 @@-package com.vayunmathur.auto.platform--import android.util.Log-import androidx.car.app.OnDoneCallback-import androidx.car.app.model.Action-import androidx.car.app.model.ActionStrip-import androidx.car.app.model.CarText-import androidx.car.app.model.Distance-import androidx.car.app.model.GridItem-import androidx.car.app.model.GridTemplate-import androidx.car.app.model.Header-import androidx.car.app.model.ItemList-import androidx.car.app.model.ListTemplate-import androidx.car.app.model.LongMessageTemplate-import androidx.car.app.model.MessageTemplate-import androidx.car.app.model.Pane-import androidx.car.app.model.PaneTemplate-import androidx.car.app.model.PlaceListMapTemplate-import androidx.car.app.model.Row-import androidx.car.app.model.SearchTemplate-import androidx.car.app.model.SectionedItemList-import androidx.car.app.model.TemplateWrapper-import androidx.car.app.navigation.model.LaneDirection-import androidx.car.app.navigation.model.NavigationTemplate-import androidx.car.app.navigation.model.RoutingInfo-import androidx.car.app.navigation.model.TravelEstimate-import java.util.concurrent.CountDownLatch-import java.util.concurrent.TimeUnit-import java.util.concurrent.atomic.AtomicReference-import kotlin.concurrent.thread--/** One template action: title plus the app's own click delegate. */-data class HostUiAction(- val title: String,- val onClick: () -> Unit,-)--/** One browsable row: title, subtitle lines, and the app's own click. */-data class HostUiRow(- val title: String,- val texts: List<String> = emptyList(),- val browse: Boolean = false,- val onClick: (() -> Unit)? = null,-)--/** One grid cell: title, subtitle, and the app's own click. */-data class HostUiGridItem(- val title: String,- val text: String? = null,- val loading: Boolean = false,- val onClick: (() -> Unit)? = null,-)--/** Header: title plus its start/end actions. */-data class HostUiHeader(- val title: String? = null,- val startAction: HostUiAction? = null,- val endActions: List<HostUiAction> = emptyList(),-)--/**- * What a hosted car app is currently publishing, parsed from its template.- *- * One parser per template kind below extends the old NavigationTemplate-only- * parse from `CarAppHost`. Unhandled template kinds log and fall back to- * [Pane] carrying the template's class name, so the renderer never blanks.- */-sealed interface HostTemplate {- /** Legacy Maps-only state, kept until the nav renderer reads [Navigation]. */- data class LegacyNav(val state: HostNavState) : HostTemplate-- /** A navigation template: cue/road banner, distance, lanes, ETA, actions. */- data class Navigation(- val navigating: Boolean = false,- val loading: Boolean = false,- val cue: String? = null,- val road: String? = null,- val distanceText: String? = null,- val etaText: String? = null,- val lanesText: String? = null,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A place list (POI): rows with a browsable flag, plus header/actions. */- data class PlaceList(- val title: String? = null,- val rows: List<HostUiRow> = emptyList(),- val loading: Boolean = false,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A generic list (or sectioned lists flattened with headers). */- data class TemplateList(- val title: String? = null,- val sections: List<HostUiSection> = emptyList(),- val loading: Boolean = false,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A grid of cells. */- data class Grid(- val title: String? = null,- val items: List<HostUiGridItem> = emptyList(),- val loading: Boolean = false,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A pane of rows plus a free action row. */- data class Pane(- val title: String? = null,- val rows: List<HostUiRow> = emptyList(),- val loading: Boolean = false,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A search box plus its result list. */- data class Search(- val hint: String? = null,- val initialText: String = "",- val rows: List<HostUiRow> = emptyList(),- val loading: Boolean = false,- val showKeyboardByDefault: Boolean = false,- val onSearchTextChanged: ((String) -> Unit)? = null,- val onSearchSubmitted: ((String) -> Unit)? = null,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A message with optional icon and actions. */- data class Message(- val title: String? = null,- val message: String? = null,- val loading: Boolean = false,- val header: HostUiHeader? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** A tabbed view: 2-4 tabs over one active content template. */- data class Tabs(- val tabs: List<HostUiTab> = emptyList(),- val activeContentId: String? = null,- val content: HostTemplate? = null,- val loading: Boolean = false,- val onTabSelected: ((String) -> Unit)? = null,- ) : HostTemplate-- /** Media now-playing: host renders transport from the session token. */- data class MediaPlayback(- val title: String? = null,- val loading: Boolean = false,- ) : HostTemplate-- /** Parked-only sign-in / permissions / long text. */- data class SignIn(- val title: String? = null,- val message: String? = null,- val loading: Boolean = false,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** In-call controls (experimental dialer). */- data class InCall(- val title: String? = null,- val texts: List<String> = emptyList(),- val loading: Boolean = false,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-- /** Telephone dialpad (experimental dialer). */- data class Keypad(- val title: String? = null,- val phoneNumber: String = "",- val onNumberChanged: ((String) -> Unit)? = null,- val onPrimaryAction: (() -> Unit)? = null,- val primaryTitle: String? = null,- ) : HostTemplate-- /** App map + overlay content (replaces deprecated map templates). */- data class MapWithContent(- val content: HostTemplate? = null,- val actions: List<HostUiAction> = emptyList(),- ) : HostTemplate-}--/** One tab inside [HostTemplate.Tabs]. */-data class HostUiTab(- val title: String? = null,- val contentId: String,-)--/** One named section inside [HostTemplate.TemplateList]. */-data class HostUiSection(- val header: String? = null,- val rows: List<HostUiRow> = emptyList(),-)--/** Parses template wrappers into [HostTemplate]. Pure functions, any thread. */-object HostTemplateParsers {- /** Parses one fetched wrapper; null wrapper means "connected, empty". */- fun parse(wrapper: TemplateWrapper?): HostTemplate {- val template = runCatching { wrapper?.template }.getOrNull()- ?: return HostTemplate.Pane(loading = true)- return when (template) {- is NavigationTemplate -> parseNavigation(template)- is PlaceListMapTemplate -> parsePlaceList(template)- is ListTemplate -> parseList(template)- is GridTemplate -> parseGrid(template)- is PaneTemplate -> parsePane(template)- is SearchTemplate -> parseSearch(template)- is MessageTemplate -> parseMessage(template)- is LongMessageTemplate -> parseLongMessage(template)- is androidx.car.app.model.SectionedItemTemplate -> parseSectionedItem(template)- is androidx.car.app.model.TabTemplate -> parseTab(template)- is androidx.car.app.media.model.MediaPlaybackTemplate -> parseMediaPlayback(template)- is androidx.car.app.model.signin.SignInTemplate -> parseSignIn(template)- is androidx.car.app.dialer.InCallTemplate -> parseInCall(template)- is androidx.car.app.dialer.TelephoneKeypadTemplate -> parseKeypad(template)- is androidx.car.app.navigation.model.MapWithContentTemplate -> parseMapWithContent(template)- // Deprecated map templates: route through the same content parsers.- is androidx.car.app.navigation.model.MapTemplate ->- runCatching { template.pane } .getOrNull()?.let { parsePane(PaneTemplate.Builder(it).build()) }- ?: runCatching { template.itemList }.getOrNull()?.let {- parseList(ListTemplate.Builder().setSingleList(it).build())- }- ?: HostTemplate.Pane(title = "Map")- is androidx.car.app.navigation.model.PlaceListNavigationTemplate ->- HostTemplate.PlaceList(- rows = itemListRows(runCatching { template.itemList }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- is androidx.car.app.navigation.model.RoutePreviewNavigationTemplate ->- HostTemplate.PlaceList(- rows = itemListRows(runCatching { template.itemList }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- else -> {- Log.w(TAG, "unhandled template ${template.javaClass.simpleName}; pane fallback")- HostTemplate.Pane(title = template.javaClass.simpleName)- }- }- }-- private fun parseSectionedItem(template: androidx.car.app.model.SectionedItemTemplate): HostTemplate.TemplateList {- val sections = mutableListOf<HostUiSection>()- runCatching { template.sections }.getOrNull().orEmpty().forEach { section ->- val items = fetchSectionItems(section)- val rows = items.mapNotNull { item ->- when (item) {- is Row -> parseRow(item)- is androidx.car.app.messaging.model.ConversationItem -> parseConversation(item)- is androidx.car.app.model.GridItem ->- HostUiRow(- title = carText(runCatching { item.title }.getOrNull()) ?: return@mapNotNull null,- texts = listOfNotNull(carText(runCatching { item.text }.getOrNull())),- browse = false,- onClick = runCatching { item.onClickDelegate }.getOrNull()?.let { d ->- {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- }- }- },- )- is androidx.car.app.model.CondensedItem ->- HostUiRow(- title = carText(runCatching { item.title }.getOrNull()) ?: return@mapNotNull null,- texts = emptyList(),- browse = false,- onClick = runCatching { item.onClickDelegate }.getOrNull()?.let { d ->- {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- }- }- },- )- is androidx.car.app.model.Chip ->- HostUiRow(- title = carText(runCatching { item.title }.getOrNull()) ?: return@mapNotNull null,- texts = emptyList(),- browse = false,- onClick = runCatching { item.onClickDelegate }.getOrNull()?.let { d ->- {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- }- }- },- )- else -> null // Banner/BannerElement: visual only, no host row- }- }- val header = carText(runCatching { section.title }.getOrNull())- ?: carText(runCatching { section.sectionHeader }.getOrNull()?.title)- ?: section.javaClass.simpleName.removeSuffix("Section")- sections += HostUiSection(header = header, rows = rows)- }- return HostTemplate.TemplateList(- title = carText(runCatching { template.header }.getOrNull()?.title),- sections = sections,- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()),- )- }-- /** Synchronously fetches a section's items via its range delegate (5s cap). */- private fun fetchSectionItems(section: androidx.car.app.model.Section<*>): List<androidx.car.app.model.Item> {- val delegate = runCatching { section.itemsDelegate }.getOrNull() ?: return emptyList()- val size = runCatching { delegate.size }.getOrDefault(0)- if (size <= 0) return emptyList()- val ref = AtomicReference<List<androidx.car.app.model.Item>?>(null)- val latch = CountDownLatch(1)- val cb = object : OnDoneCallback {- override fun onSuccess(response: androidx.car.app.serialization.Bundleable?) {- ref.set(runCatching { response?.get() as? List<*> }.getOrNull()?.filterIsInstance<androidx.car.app.model.Item>())- latch.countDown()- }- }- runCatching { delegate.requestItemRange(0, size - 1, cb) }- .onFailure { Log.w(TAG, "section range fetch failed", it); return emptyList() }- latch.await(5, TimeUnit.SECONDS)- return ref.get().orEmpty()- }-- private fun parseConversation(item: androidx.car.app.messaging.model.ConversationItem): HostUiRow? {- val title = carText(runCatching { item.title }.getOrNull()) ?: return null- val lastBody = runCatching { item.messages }.getOrNull()?.lastOrNull()?.let { msg ->- carText(runCatching { msg.body }.getOrNull())- }- val delegate = runCatching { item.conversationCallbackDelegate }.getOrNull()- return HostUiRow(- title = title,- texts = listOfNotNull(lastBody),- browse = true,- onClick = delegate?.let { d ->- {- thread(name = "ma-auto-carhost-read", isDaemon = true) {- runCatching { d.sendMarkAsRead(HostClickCallback) }- }- }- },- )- }-- private fun parseTab(template: androidx.car.app.model.TabTemplate): HostTemplate.Tabs {- val delegate = runCatching { template.tabCallbackDelegate }.getOrNull()- val tabs = runCatching { template.tabs }.getOrNull().orEmpty().map { tab ->- HostUiTab(- title = carText(runCatching { tab.title }.getOrNull()),- contentId = runCatching { tab.contentId }.getOrNull().orEmpty(),- )- }- val activeId = runCatching { template.activeTabContentId }.getOrNull()- val content = runCatching { template.tabContents }.getOrNull()?.let { contents ->- runCatching { contents.template }.getOrNull()?.let { inner ->- runCatching { parseInner(inner) }.getOrNull()- }- }- return HostTemplate.Tabs(- tabs = tabs,- activeContentId = activeId,- content = content,- loading = runCatching { template.isLoading }.getOrDefault(false),- onTabSelected = delegate?.let { d ->- { contentId ->- thread(name = "ma-auto-carhost-tab", isDaemon = true) {- runCatching { d.sendTabSelected(contentId, HostClickCallback) }- .onFailure { Log.w(TAG, "tab select failed", it) }- }- }- },- )- }-- private fun parseInner(template: androidx.car.app.model.Template): HostTemplate =- when (template) {- is ListTemplate -> parseList(template)- is GridTemplate -> parseGrid(template)- is PaneTemplate -> parsePane(template)- is MessageTemplate -> parseMessage(template)- is SearchTemplate -> parseSearch(template)- is androidx.car.app.model.SectionedItemTemplate -> parseSectionedItem(template)- is NavigationTemplate -> parseNavigation(template)- else -> HostTemplate.Pane(title = template.javaClass.simpleName)- }-- private fun parseMediaPlayback(template: androidx.car.app.media.model.MediaPlaybackTemplate): HostTemplate.MediaPlayback =- HostTemplate.MediaPlayback(- title = carText(runCatching { template.header }.getOrNull()?.title),- )-- private fun parseSignIn(template: androidx.car.app.model.signin.SignInTemplate): HostTemplate.SignIn =- HostTemplate.SignIn(- title = carText(runCatching { template.title }.getOrNull()),- message = carText(runCatching { template.instructions }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- @OptIn(androidx.car.app.annotations.ExperimentalCarApi::class)- private fun parseInCall(template: androidx.car.app.dialer.InCallTemplate): HostTemplate.InCall =- HostTemplate.InCall(- title = carText(runCatching { template.title }.getOrNull()),- texts = runCatching { template.texts }.getOrNull().orEmpty().mapNotNull { carText(it) },- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()),- )-- @OptIn(androidx.car.app.annotations.ExperimentalCarApi::class)- private fun parseKeypad(template: androidx.car.app.dialer.TelephoneKeypadTemplate): HostTemplate.Keypad {- val primary = runCatching { template.primaryAction }.getOrNull()- val primaryDelegate = primary?.let { runCatching { it.onClickDelegate }.getOrNull() }- return HostTemplate.Keypad(- title = carText(runCatching { template.header }.getOrNull()?.title),- phoneNumber = runCatching { template.phoneNumber }.getOrNull().orEmpty(),- onPrimaryAction = primaryDelegate?.let { d ->- {- thread(name = "ma-auto-carhost-dial", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- }- }- },- primaryTitle = carText(primary?.let { runCatching { it.title }.getOrNull() }),- )- }-- private fun parseMapWithContent(template: androidx.car.app.navigation.model.MapWithContentTemplate): HostTemplate.MapWithContent =- HostTemplate.MapWithContent(- content = runCatching { template.contentTemplate }.getOrNull()- ?.let { runCatching { parseInner(it) }.getOrNull() },- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- fun parseNavigation(template: NavigationTemplate): HostTemplate.Navigation {- val routing = runCatching { template.navigationInfo }.getOrNull() as? RoutingInfo- val step = routing?.currentStep- val loading = routing?.isLoading == true- val navigating = routing != null && !loading- val lanesText = step?.lanes- ?.takeIf { it.isNotEmpty() }- ?.joinToString(" ") { lane -> laneArrows(lane.directions) }- ?.takeIf { it.isNotBlank() }- return HostTemplate.Navigation(- navigating = navigating,- loading = loading,- cue = carText(step?.cue),- road = carText(step?.road),- distanceText = routing?.currentDistance?.let { formatDistance(it.displayDistance, it.displayUnit) },- etaText = runCatching { template.destinationTravelEstimate }.getOrNull()?.let { formatEstimate(it) },- lanesText = lanesText,- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- }-- private fun parsePlaceList(template: PlaceListMapTemplate): HostTemplate.PlaceList =- HostTemplate.PlaceList(- title = carText(runCatching { template.title }.getOrNull()),- rows = itemListRows(runCatching { template.itemList }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- private fun parseList(template: ListTemplate): HostTemplate.TemplateList {- val sections = mutableListOf<HostUiSection>()- runCatching { template.singleList }.getOrNull()?.let { list ->- sections += HostUiSection(rows = itemListRows(list))- }- runCatching { template.sectionedLists }.getOrNull().orEmpty().forEach { section ->- sections += parseSection(section)- }- return HostTemplate.TemplateList(- title = carText(runCatching { template.title }.getOrNull()),- sections = sections,- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- }-- private fun parseSection(section: SectionedItemList): HostUiSection =- HostUiSection(- header = carText(runCatching { section.header }.getOrNull()),- rows = itemListRows(runCatching { section.itemList }.getOrNull()),- )-- private fun parseGrid(template: GridTemplate): HostTemplate.Grid =- HostTemplate.Grid(- title = carText(runCatching { template.title }.getOrNull()),- items = gridItems(runCatching { template.singleList }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- private fun parsePane(template: PaneTemplate): HostTemplate.Pane {- val pane = runCatching { template.pane }.getOrNull()- return HostTemplate.Pane(- title = carText(runCatching { template.title }.getOrNull()),- rows = paneRows(pane),- loading = runCatching { pane?.isLoading }.getOrDefault(false) == true,- actions = paneActions(pane) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- }-- private fun parseSearch(template: SearchTemplate): HostTemplate.Search {- val delegate = runCatching { template.searchCallbackDelegate }.getOrNull()- return HostTemplate.Search(- hint = runCatching { template.searchHint }.getOrNull(),- initialText = runCatching { template.initialSearchText }.getOrNull().orEmpty(),- rows = itemListRows(runCatching { template.itemList }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- showKeyboardByDefault = runCatching { template.isShowKeyboardByDefault }.getOrDefault(false),- onSearchTextChanged = delegate?.let { d ->- { text ->- thread(name = "ma-auto-carhost-search", isDaemon = true) {- runCatching {- d.sendSearchTextChanged(text, HostClickCallback)- }.onFailure { Log.w(TAG, "search text change failed", it) }- }- }- },- onSearchSubmitted = delegate?.let { d ->- { text ->- thread(name = "ma-auto-carhost-search", isDaemon = true) {- runCatching {- d.sendSearchSubmitted(text, HostClickCallback)- }.onFailure { Log.w(TAG, "search submit failed", it) }- }- }- },- actions = actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )- }-- private fun parseMessage(template: MessageTemplate): HostTemplate.Message =- HostTemplate.Message(- title = carText(runCatching { template.title }.getOrNull()),- message = carText(runCatching { template.message }.getOrNull()),- loading = runCatching { template.isLoading }.getOrDefault(false),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- private fun parseLongMessage(template: LongMessageTemplate): HostTemplate.Message =- HostTemplate.Message(- title = carText(runCatching { template.title }.getOrNull()),- message = carText(runCatching { template.message }.getOrNull()),- actions = listActions(runCatching { template.actions }.getOrNull().orEmpty()) +- actionStripActions(runCatching { template.actionStrip }.getOrNull()),- )-- private fun itemListRows(list: ItemList?): List<HostUiRow> {- val items = runCatching { list?.items }.getOrNull().orEmpty()- return items.mapNotNull { item ->- val row = item as? Row ?: return@mapNotNull null- parseRow(row)- }- }-- private fun parseRow(row: Row): HostUiRow? {- val title = carText(runCatching { row.title }.getOrNull()) ?: return null- val texts = runCatching { row.texts }.getOrNull().orEmpty().mapNotNull { carText(it) }- val delegate = runCatching { row.onClickDelegate }.getOrNull()- return HostUiRow(- title = title,- texts = texts,- browse = runCatching { row.isBrowsable }.getOrDefault(false),- onClick = delegate?.let { d ->- {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- .onFailure { Log.w(TAG, "row click failed: $title", it) }- }- }- },- )- }-- private fun gridItems(list: ItemList?): List<HostUiGridItem> {- val items = runCatching { list?.items }.getOrNull().orEmpty()- return items.mapNotNull { item ->- val grid = item as? GridItem ?: return@mapNotNull null- val title = carText(runCatching { grid.title }.getOrNull()) ?: return@mapNotNull null- val delegate = runCatching { grid.onClickDelegate }.getOrNull()- HostUiGridItem(- title = title,- text = carText(runCatching { grid.text }.getOrNull()),- loading = runCatching { grid.isLoading }.getOrDefault(false),- onClick = delegate?.let { d ->- {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { d.sendClick(HostClickCallback) }- .onFailure { Log.w(TAG, "grid click failed: $title", it) }- }- }- },- )- }- }-- private fun paneRows(pane: Pane?): List<HostUiRow> =- runCatching { pane?.rows }.getOrNull().orEmpty().mapNotNull { parseRow(it) }-- private fun paneActions(pane: Pane?): List<HostUiAction> =- listActions(runCatching { pane?.actions }.getOrNull().orEmpty())-- private fun listActions(actions: List<Action>): List<HostUiAction> =- actions.mapNotNull { parseAction(it) }-- private fun actionStripActions(strip: ActionStrip?): List<HostUiAction> =- runCatching { strip?.actions }.getOrNull().orEmpty().mapNotNull { parseAction(it) }-- private fun parseAction(action: Action): HostUiAction? {- val title = carText(runCatching { action.title }.getOrNull()) ?: return null- val delegate = runCatching { action.onClickDelegate }.getOrNull() ?: return null- return HostUiAction(title) {- thread(name = "ma-auto-carhost-click", isDaemon = true) {- runCatching { delegate.sendClick(HostClickCallback) }- .onFailure { Log.w(TAG, "action click failed: $title", it) }- }- }- }-- @Suppress("unused")- private fun parseHeader(header: Header?): HostUiHeader? {- if (header == null) return null- return HostUiHeader(- title = carText(runCatching { header.title }.getOrNull()),- startAction = runCatching { header.startHeaderAction }.getOrNull()?.let { parseAction(it) },- endActions = runCatching { header.endHeaderActions }.getOrNull().orEmpty().mapNotNull { parseAction(it) },- )- }-- private fun carText(text: CarText?): String? = runCatching {- text?.toCharSequence()?.toString()?.takeIf { it.isNotBlank() }- }.getOrNull()-- private fun laneArrows(directions: List<LaneDirection>): String = directions.joinToString("") { dir ->- when (runCatching { dir.shape }.getOrNull()) {- LaneDirection.SHAPE_STRAIGHT -> STRAIGHT_ARROW- LaneDirection.SHAPE_SLIGHT_LEFT -> SLIGHT_LEFT_ARROW- LaneDirection.SHAPE_SLIGHT_RIGHT -> SLIGHT_RIGHT_ARROW- LaneDirection.SHAPE_NORMAL_LEFT -> LEFT_ARROW- LaneDirection.SHAPE_NORMAL_RIGHT -> RIGHT_ARROW- LaneDirection.SHAPE_SHARP_LEFT -> SHARP_LEFT_ARROW- LaneDirection.SHAPE_SHARP_RIGHT -> SHARP_RIGHT_ARROW- LaneDirection.SHAPE_U_TURN_LEFT -> UTURN_LEFT_ARROW- LaneDirection.SHAPE_U_TURN_RIGHT -> UTURN_RIGHT_ARROW- else -> UNKNOWN_ARROW- }- }-- private fun formatDistance(display: Double, unit: Int): String = when (unit) {- Distance.UNIT_METERS -> "${display.toInt()} m"- Distance.UNIT_KILOMETERS,- Distance.UNIT_KILOMETERS_P1,- -> "${((display * 10).toInt() / 10.0)} km"- Distance.UNIT_MILES,- Distance.UNIT_MILES_P1,- -> "${((display * 10).toInt() / 10.0)} mi"- Distance.UNIT_FEET -> "${display.toInt()} ft"- else -> "${display.toInt()} m"- }-- private fun formatEstimate(estimate: TravelEstimate): String? {- val remaining = runCatching { estimate.remainingTimeSeconds }.getOrNull() ?: return null- if (remaining <= 0 || remaining == Long.MAX_VALUE) return null- val minutes = (remaining / 60).toInt()- return if (minutes < 60) "$minutes min" else "${minutes / 60} h ${minutes % 60} min"- }-- private const val TAG = "MaAuto.HostTemplates"-- private const val STRAIGHT_ARROW = "↑"- private const val SLIGHT_LEFT_ARROW = "⬉"- private const val SLIGHT_RIGHT_ARROW = "⬊"- private const val LEFT_ARROW = "←"- private const val RIGHT_ARROW = "→"- private const val SHARP_LEFT_ARROW = "↰"- private const val SHARP_RIGHT_ARROW = "↱"- private const val UTURN_LEFT_ARROW = "↩"- private const val UTURN_RIGHT_ARROW = "↪"- private const val UNKNOWN_ARROW = "•"-}--/**- * App-side click callback: the delegate reports back into the app's own- * dispatch, never the host binder one. Shared because every click site needs- * the same no-op — matching the old `CarAppHost.parseTemplate` behavior.- */-private object HostClickCallback : OnDoneCallback--/** One template action (Search, End navigation): title plus the app's own click. */-data class HostAction(- val title: String,- val onClick: () -> Unit,-)--/**- * Legacy Maps-only template state, kept until the nav renderer reads the- * generic [HostTemplate.Navigation] directly.- *- * `mapsPresent=false` means the service itself is missing (empty tile);- * `connected=false` means the bind/handshake failed (tile until the next- * session). Otherwise the card shows the app's map surface plus these fields.- * Actions ride the app's own `OnClickDelegate`.- */-data class HostNavState(- val mapsPresent: Boolean = true,- val connected: Boolean = true,- val navigating: Boolean = false,- val loading: Boolean = false,- val cue: String? = null,- val road: String? = null,- val distanceText: String? = null,- val etaText: String? = null,- val lanesText: String? = null,- val actions: List<HostAction> = emptyList(),-)
auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt b/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.ktindex 237a5b55b5..9d07927af3 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt@@ -4,6 +4,7 @@ import android.content.Context import android.media.MediaCodec import android.os.Handler import android.os.Looper+import com.vayunmathur.library.carhost.HostNavState import android.os.SystemClock import android.util.Log import android.view.Choreographer
auto/src/main/java/com/vayunmathur/auto/service/CarAppHostSession.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/service/CarAppHostSession.kt b/auto/src/main/java/com/vayunmathur/auto/service/CarAppHostSession.ktindex a1f8117de6..18d3c832d6 100644--- a/auto/src/main/java/com/vayunmathur/auto/service/CarAppHostSession.kt+++ b/auto/src/main/java/com/vayunmathur/auto/service/CarAppHostSession.kt@@ -7,10 +7,10 @@ import com.vayunmathur.auto.platform.CarAppDiscovery import com.vayunmathur.auto.platform.CarLauncherState import com.vayunmathur.auto.platform.DiscoveredApp import com.vayunmathur.auto.platform.HostManager-import com.vayunmathur.auto.platform.HostNavState-import com.vayunmathur.auto.platform.HostTemplate import com.vayunmathur.auto.platform.HostTemplateBus import com.vayunmathur.auto.platform.VideoSinkChannel+import com.vayunmathur.library.carhost.HostNavState+import com.vayunmathur.library.carhost.HostTemplate /** * Session-scoped owner for the multi-app host ([HostManager]).
auto/src/main/java/com/vayunmathur/auto/ui/AppScreen.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/ui/AppScreen.kt b/auto/src/main/java/com/vayunmathur/auto/ui/AppScreen.ktindex 7abc625521..d36c33b595 100644--- a/auto/src/main/java/com/vayunmathur/auto/ui/AppScreen.kt+++ b/auto/src/main/java/com/vayunmathur/auto/ui/AppScreen.kt@@ -3,409 +3,32 @@ package com.vayunmathur.auto.ui import android.graphics.SurfaceTexture import android.view.Surface import android.view.TextureView-import androidx.compose.foundation.layout.Arrangement-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.padding-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.text.KeyboardActions-import androidx.compose.foundation.text.KeyboardOptions 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.text.input.ImeAction-import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.auto.platform.CarLauncherState-import com.vayunmathur.auto.platform.HostTemplate-import com.vayunmathur.auto.platform.HostUiAction-import com.vayunmathur.auto.platform.HostUiGridItem-import com.vayunmathur.auto.platform.HostUiRow-import com.vayunmathur.auto.platform.HostUiSection-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.CircularProgressIndicator-import com.vayunmathur.library.ui.ListItem-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.carhost.CarTemplateView /** * One hosted app's screen: renders its latest parsed template full-bleed. *- * No title header: the app is identified by its highlighted dock icon (see- * [LauncherBottomBar]), so the template keeps every pixel. Each template- * kind gets its own renderer below; unhandled kinds already fell back to- * [HostTemplate.Pane] text in the parsers, so the screen never blanks. The- * navigation renderer keeps the `TextureView` interop island for the app's- * own map `Surface` — Compose cannot host a third-party map surface- * otherwise.+ * The Template→Compose rendering lives in `:library:carhost` ([CarTemplateView])+ * so apps can render the same views in screenshot tests. This wrapper supplies+ * the two things only the head unit owns: the template source+ * ([CarLauncherState.templates]) and the real map [Surface] via [MapSurfaceIsland]. */ @Composable fun AppScreen(appId: String, modifier: Modifier = Modifier) {- HostedTemplateBody(appId = appId, modifier = modifier.fillMaxSize())-}--@Composable-private fun HostedTemplateBody(appId: String, modifier: Modifier = Modifier) { val templates by CarLauncherState.templates.collectAsStateWithLifecycle()- val template = templates[appId]- when (template) {- is HostTemplate.Navigation -> NavigationRenderer(template, modifier)- is HostTemplate.PlaceList -> PlaceListRenderer(template, modifier)- is HostTemplate.TemplateList -> ListRenderer(template, modifier)- is HostTemplate.Grid -> GridRenderer(template, modifier)- is HostTemplate.Pane -> PaneRenderer(template, modifier)- is HostTemplate.Search -> SearchRenderer(template, modifier)- is HostTemplate.Message -> MessageRenderer(template, modifier)- is HostTemplate.Tabs -> TabsRenderer(template, modifier)- is HostTemplate.MediaPlayback -> MediaPlaybackRenderer(template, modifier)- is HostTemplate.SignIn -> SignInRenderer(template, modifier)- is HostTemplate.InCall -> InCallRenderer(template, modifier)- is HostTemplate.Keypad -> KeypadRenderer(template, modifier)- is HostTemplate.MapWithContent -> MapWithContentRenderer(template, modifier)- is HostTemplate.LegacyNav -> LegacyNavRenderer(template, modifier)- null -> LoadingRenderer(modifier)- }-}--@Composable-private fun NavigationRenderer(template: HostTemplate.Navigation, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- val banner = listOfNotNull(template.cue, template.road).joinToString(" · ").takeIf { it.isNotBlank() }- if (banner != null) {- Text(text = banner, style = MaterialTheme.typography.headlineSmall)- }- Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {- template.distanceText?.let { Text(text = it, style = MaterialTheme.typography.bodyLarge) }- template.etaText?.let { Text(text = it, style = MaterialTheme.typography.bodyLarge) }- }- template.lanesText?.let { Text(text = it, style = MaterialTheme.typography.bodyMedium) }- MapSurfaceIsland(modifier = Modifier.fillMaxWidth().weight(1f))- if (template.loading) CircularProgressIndicator()- ActionRow(actions = template.actions)- }-}--@Composable-private fun PlaceListRenderer(template: HostTemplate.PlaceList, modifier: Modifier = Modifier) {- TemplateListBody(- title = template.title,- sections = listOf(HostUiSection(rows = template.rows)),- loading = template.loading,- actions = template.actions,- modifier = modifier,- )-}--@Composable-private fun ListRenderer(template: HostTemplate.TemplateList, modifier: Modifier = Modifier) {- TemplateListBody(- title = template.title,- sections = template.sections,- loading = template.loading,- actions = template.actions,- modifier = modifier,- )-}--@Composable-private fun GridRenderer(template: HostTemplate.Grid, modifier: Modifier = Modifier) {- LazyColumn(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(4.dp)) {- template.title?.let {- item { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- }- items(template.items, key = { it.title }) { item ->- GridItemRow(item = item)- }- if (template.loading) {- item { CircularProgressIndicator() }- }- if (template.actions.isNotEmpty()) {- item { ActionRow(actions = template.actions) }- }- }-}--@Composable-private fun PaneRenderer(template: HostTemplate.Pane, modifier: Modifier = Modifier) {- TemplateListBody(- title = template.title,- sections = listOf(HostUiSection(rows = template.rows)),- loading = template.loading,- actions = template.actions,+ CarTemplateView(+ template = templates[appId], modifier = modifier,+ mapContent = { MapSurfaceIsland(it) }, ) } -@Composable-private fun SearchRenderer(template: HostTemplate.Search, modifier: Modifier = Modifier) {- var text by remember(template.initialText) { mutableStateOf(template.initialText) }- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- OutlinedTextField(- value = text,- onValueChange = {- text = it- template.onSearchTextChanged?.invoke(it)- },- label = { Text(template.hint ?: "Search") },- singleLine = true,- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),- keyboardActions = KeyboardActions(onSearch = { template.onSearchSubmitted?.invoke(text) }),- modifier = Modifier.fillMaxWidth(),- )- TemplateListBody(- title = null,- sections = listOf(HostUiSection(rows = template.rows)),- loading = template.loading,- actions = template.actions,- modifier = Modifier.weight(1f),- )- }-}--@Composable-private fun MessageRenderer(template: HostTemplate.Message, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Card(Modifier.fillMaxWidth()) {- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {- template.title?.let { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- template.message?.let { Text(text = it, style = MaterialTheme.typography.bodyLarge) }- if (template.loading) CircularProgressIndicator()- }- }- ActionRow(actions = template.actions)- }-}--@Composable-private fun TabsRenderer(template: HostTemplate.Tabs, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {- for (tab in template.tabs) {- val selected = tab.contentId == template.activeContentId- if (selected) {- Button(onClick = {}) { Text(tab.title ?: tab.contentId) }- } else {- TextButton(onClick = { template.onTabSelected?.invoke(tab.contentId) }) {- Text(tab.title ?: tab.contentId)- }- }- }- }- val content = template.content- if (content != null) {- when (content) {- is HostTemplate.TemplateList -> ListRenderer(content, Modifier.weight(1f))- is HostTemplate.Grid -> GridRenderer(content, Modifier.weight(1f))- is HostTemplate.Pane -> PaneRenderer(content, Modifier.weight(1f))- is HostTemplate.Message -> MessageRenderer(content, Modifier.weight(1f))- is HostTemplate.Search -> SearchRenderer(content, Modifier.weight(1f))- is HostTemplate.Navigation -> NavigationRenderer(content, Modifier.weight(1f))- else -> TemplateListBody(null, emptyList(), false, emptyList(), Modifier.weight(1f))- }- } else if (template.loading) {- CircularProgressIndicator()- }- }-}--@Composable-private fun MediaPlaybackRenderer(template: HostTemplate.MediaPlayback, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Card(Modifier.fillMaxWidth()) {- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Text(text = template.title ?: "Now playing", style = MaterialTheme.typography.headlineSmall)- Text(- text = "Transport renders from the media session token.",- style = MaterialTheme.typography.bodyMedium,- )- }- }- }-}--@Composable-private fun SignInRenderer(template: HostTemplate.SignIn, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Card(Modifier.fillMaxWidth()) {- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {- template.title?.let { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- template.message?.let { Text(text = it, style = MaterialTheme.typography.bodyLarge) }- if (template.loading) CircularProgressIndicator()- }- }- ActionRow(actions = template.actions)- }-}--@Composable-private fun InCallRenderer(template: HostTemplate.InCall, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- Card(Modifier.fillMaxWidth()) {- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {- template.title?.let { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- for (line in template.texts) {- Text(text = line, style = MaterialTheme.typography.bodyLarge)- }- if (template.loading) CircularProgressIndicator()- }- }- ActionRow(actions = template.actions)- }-}--@Composable-private fun KeypadRenderer(template: HostTemplate.Keypad, modifier: Modifier = Modifier) {- var text by remember(template.phoneNumber) { mutableStateOf(template.phoneNumber) }- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- template.title?.let { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- OutlinedTextField(- value = text,- onValueChange = {- text = it- template.onNumberChanged?.invoke(it)- },- label = { Text("Number") },- singleLine = true,- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),- modifier = Modifier.fillMaxWidth(),- )- template.onPrimaryAction?.let { primary ->- Button(onClick = primary) { Text(template.primaryTitle ?: "Call") }- }- }-}--@Composable-private fun MapWithContentRenderer(template: HostTemplate.MapWithContent, modifier: Modifier = Modifier) {- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- MapSurfaceIsland(modifier = Modifier.fillMaxWidth().weight(1f))- val content = template.content- if (content != null) {- when (content) {- is HostTemplate.TemplateList -> ListRenderer(content, Modifier.weight(1f))- is HostTemplate.Grid -> GridRenderer(content, Modifier.weight(1f))- is HostTemplate.Pane -> PaneRenderer(content, Modifier.weight(1f))- is HostTemplate.Message -> MessageRenderer(content, Modifier.weight(1f))- is HostTemplate.Search -> SearchRenderer(content, Modifier.weight(1f))- else -> Unit- }- }- ActionRow(actions = template.actions)- }-}--@Composable-private fun LegacyNavRenderer(template: HostTemplate.LegacyNav, modifier: Modifier = Modifier) {- val state = template.state- Column(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(8.dp)) {- val banner = listOfNotNull(state.cue, state.road).joinToString(" · ").takeIf { it.isNotBlank() }- banner?.let { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- state.distanceText?.let { Text(text = it, style = MaterialTheme.typography.bodyLarge) }- state.lanesText?.let { Text(text = it, style = MaterialTheme.typography.bodyMedium) }- state.etaText?.let { Text(text = it, style = MaterialTheme.typography.bodyMedium) }- MapSurfaceIsland(modifier = Modifier.fillMaxWidth().weight(1f))- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- for (action in state.actions) {- TextButton(onClick = action.onClick) { Text(action.title) }- }- }- }-}--@Composable-private fun LoadingRenderer(modifier: Modifier = Modifier) {- Column(- modifier.fillMaxSize(),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.Center,- ) {- CircularProgressIndicator()- }-}--@Composable-private fun TemplateListBody(- title: String?,- sections: List<HostUiSection>,- loading: Boolean,- actions: List<HostUiAction>,- modifier: Modifier = Modifier,-) {- LazyColumn(modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(4.dp)) {- title?.let {- item { Text(text = it, style = MaterialTheme.typography.headlineSmall) }- }- for (section in sections) {- section.header?.let { header ->- item { Text(text = header, style = MaterialTheme.typography.titleMedium) }- }- items(section.rows, key = { it.title }) { row ->- TemplateRow(row = row)- }- }- if (loading) {- item { CircularProgressIndicator() }- }- if (actions.isNotEmpty()) {- item { ActionRow(actions = actions) }- }- }-}--@Composable-private fun TemplateRow(row: HostUiRow) {- val click = row.onClick- ListItem(- headlineContent = { Text(row.title) },- supportingContent = {- if (row.texts.isNotEmpty()) Text(row.texts.joinToString("\n"))- },- trailingContent = {- if (click != null) {- TextButton(onClick = click) { Text(if (row.browse) "›" else "Open") }- }- },- )-}--@Composable-private fun GridItemRow(item: HostUiGridItem) {- val click = item.onClick- ListItem(- headlineContent = { Text(item.title) },- supportingContent = {- item.text?.let { Text(it) }- },- trailingContent = {- if (item.loading) CircularProgressIndicator()- else if (click != null) {- TextButton(onClick = click) { Text("Open") }- }- },- )-}--@Composable-private fun ActionRow(actions: List<HostUiAction>) {- if (actions.isEmpty()) return- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- for (action in actions) {- Button(onClick = action.onClick) { Text(action.title) }- }- }-}- /** * The hosted map `Surface` as a `TextureView` interop island. *