AmbientAwareTime

@RequiresApi(value = 26)
fun AmbientAwareTime(stateUpdate: AmbientStateUpdate, updatePeriodMillis: Long = 1000, block: @Composable (dateTime: ZonedDateTime, isAmbient: Boolean) -> Unit)

An example of using AmbientAware: Provides the time, at the specified update frequency, whilst in interactive mode, or when ambient-generated updates occur (typically every 1 min).

Example usage:

AmbientAware { stateUpdate -> Box( contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize() ) { AmbientAwareTime(stateUpdate) { dateTime, isAmbient -> // Basic example of AmbientAwareTime usage val ambientFmt = remember { DateTimeFormatter.ofPattern("HH:mm") } val interactiveFmt = remember { DateTimeFormatter.ofPattern("HH:mm:ss") } val dateTimeStr = if (isAmbient) { ambientFmt.format(ZonedDateTime.now()) } else { interactiveFmt.format(ZonedDateTime.now()) } Text(dateTimeStr) } } }

Parameters

stateUpdate

The state update from AmbientAware

updatePeriodMillis

The update period, whilst in interactive mode

block

The developer-supplied composable for rendering the date and time.