-
public final class AmbientAwareTimeKt
-
-
Method Summary
Modifier and Type Method Description final static UnitAmbientAwareTime(AmbientState stateUpdate, Long updatePeriodMillis, Function2<ZonedDateTime, Boolean, Unit> block)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). -
-
Method Detail
-
AmbientAwareTime
@Composable() final static Unit AmbientAwareTime(AmbientState stateUpdate, Long updatePeriodMillis, Function2<ZonedDateTime, Boolean, Unit> block)
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 AmbientAwareupdatePeriodMillis- The update period, whilst in interactive modeblock- The developer-supplied composable for rendering the date and time.
-
-
-
-