EditorSession
interface EditorSession : AutoCloseable
ListenableEditorSession |
This class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Interface for manipulating watch face state during a watch face editing session. The editor should adjust userStyle and call openComplicationDataSourceChooser to configure the watch face and call close when done. This reports the updated EditorState to the EditorListeners registered via EditorServiceClient.addListener.
For EditorSessions backed by a headless instance (see createHeadlessEditorSession and EditorRequest.headlessDeviceConfig), style changes are not applied to the interactive instance and it's up to the system to apply them. For EditorSessions backed by an interactive instance style changes are applied immediately. Its possible the system might fail to persist the style changes (e.g. to data base write failure or a crash) and if this happens it's the responsibility of the system to revert the style change.
use Watch Face Format instead
Summary
Public companion functions |
|
|---|---|
EditorSession |
@RequiresApi(value = 27)This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
suspend EditorSession |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public companion properties |
|
|---|---|
Instant |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Duration |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public functions |
|
|---|---|
Int? |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
suspend ChosenComplicationDataSource? |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Bitmap |
@UiThreadThis function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
open Unit |
This function is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public properties |
|
|---|---|
Int? |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Boolean |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
StateFlow<Map<Int, ComplicationSlotState>> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
StateFlow<Map<Int, ComplicationDataSourceInfo?>> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
StateFlow<Map<Int, ComplicationData>> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Instant |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
MutableStateFlow<UserStyle> |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
UserStyleSchema |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
ComponentName |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
WatchFaceId |
This property is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Inherited functions |
|---|
Public companion functions
createHeadlessEditorSession
@RequiresApi(value = 27)
@UiThread
funcreateHeadlessEditorSession(
activity: ComponentActivity,
editIntent: Intent,
headlessWatchFaceClient: HeadlessWatchFaceClient
): EditorSession
Constructs an EditorSession for a remote watch face editor.
Caution the remote watchface must have been built with the same version of the watch face libraries.
| Parameters | |
|---|---|
activity: ComponentActivity |
The |
editIntent: Intent |
The |
headlessWatchFaceClient: HeadlessWatchFaceClient |
The |
| Returns | |
|---|---|
EditorSession |
The |
createOnWatchEditorSession
@UiThread
suspend funcreateOnWatchEditorSession(activity: ComponentActivity): EditorSession
Constructs an EditorSession for an on watch face editor. This registers an activity result handler and so it must be called during an Activity or Fragment initialization path. The EditorSession is lifecycle aware and will automatically close when onDestroy is received.
| Parameters | |
|---|---|
activity: ComponentActivity |
The |
| Returns | |
|---|---|
EditorSession |
Deferred |
| Throws | |
|---|---|
kotlinx.coroutines.TimeoutCancellationException |
if it takes longer than |
Public companion properties
DEFAULT_PREVIEW_INSTANT
val DEFAULT_PREVIEW_INSTANT: Instant
If passed renderWatchFaceToBitmap this will signal that the watch face's default preview time should be used.
EDITING_SESSION_TIMEOUT
val EDITING_SESSION_TIMEOUT: Duration
Timeout allowed for waiting for creating the watch face editing session.
Public functions
getComplicationSlotIdAt
@UiThread
fungetComplicationSlotIdAt(x: @Px Int, y: @Px Int): Int?
Returns the ID of the complication at the given coordinates or null if there isn't one. Only androidx.wear.watchface.ComplicationSlots with ComplicationSlotBoundsType.ROUND_RECT are supported by this function.
openComplicationDataSourceChooser
@UiThread
suspend funopenComplicationDataSourceChooser(complicationSlotId: Int): ChosenComplicationDataSource?
Opens the complication data source chooser and returns the chosen complication data source for the specified androidx.wear.watchface.ComplicationSlot.
The result returns null if the operation was cancelled and otherwise returned an instance of ChosenComplicationDataSource that contains information about the chosen data source.
| Parameters | |
|---|---|
complicationSlotId: Int |
The id of the |
| Throws | |
|---|---|
kotlin.IllegalStateException |
if a previous invocation of openComplicationDataSourceChooser is still running when openComplicationDataSourceChooser is called. |
renderWatchFaceToBitmap
@UiThread
funrenderWatchFaceToBitmap(
renderParameters: RenderParameters,
instant: Instant,
slotIdToComplicationData: Map<Int, ComplicationData>?
): Bitmap
Renders the watch face to a Bitmap using the current userStyle.
| Parameters | |
|---|---|
renderParameters: RenderParameters |
The |
instant: Instant |
The |
slotIdToComplicationData: Map<Int, ComplicationData>? |
Override |
setOverrideComplications
open funsetOverrideComplications(
slotIdToComplicationData: Map<Int, ComplicationData>
): Unit
For the duration of the editor session, applies an override to complications rendered via renderWatchFaceToBitmap. If you need to render multiple times with the same slotIdToComplicationData it's more efficient to use this API and call renderWatchFaceToBitmap with null slotIdToComplicationData. When the editor session ends this override will be removed.
Note if after this call updated complications are sent via InteractiveWatchFaceClient.updateComplicationData, they will only be applied once the editor session has ended.
| Parameters | |
|---|---|
slotIdToComplicationData: Map<Int, ComplicationData> |
The complications you wish to set. Any slots not covered by this map will be unchanged. |
Public properties
backgroundComplicationSlotId
val backgroundComplicationSlotId: Int?
The ID of the background complication or null if there isn't one.
commitChangesOnClose
var commitChangesOnClose: Boolean
Whether any changes should be committed when the session is closed (defaults to true).
Note due to SysUI requirements EditorState can't reliably be sent in the activity result because there are circumstances where ComponentActivity.onStop doesn't get called but the UX requires us to commit changes.
Regardless of the value, on completion of the editor session, the original UserStyle is restored. Note we need SysUI's help to revert any complication data source changes. Caveat some complication data sources have their own config (e.g. the world clock has a timezone setting) and that config currently can't be reverted.
complicationSlotsState
val complicationSlotsState: StateFlow<Map<Int, ComplicationSlotState>>
A Flow of a Map of complication slot ids to ComplicationSlotState for each complication slot.
If accessed from java, consider using androidx.lifecycle.FlowLiveDataConversions.asLiveData to observe changes.
complicationsDataSourceInfo
val complicationsDataSourceInfo: StateFlow<Map<Int, ComplicationDataSourceInfo?>>
Returns a flow of maps of androidx.wear.watchface.ComplicationSlot ids to ComplicationDataSourceInfo that represent the information available about the data source for each complication. This data is fetched asynchronously and the map will initially be empty. For watch faces without complications this will always be empty.
Note new data may be pushed as result of running openComplicationDataSourceChooser.
Note a null ComplicationDataSourceInfo will be associated with a complication slot id if the androidx.wear.watchface.ComplicationSlot is configured to show the empty complication data source.
complicationsPreviewData
val complicationsPreviewData: StateFlow<Map<Int, ComplicationData>>
Returns a flow of maps of androidx.wear.watchface.ComplicationSlot ids to preview ComplicationData suitable for use in rendering a preview of the watch face. This data is fetched asynchronously and the map will initially be empty. For watch faces without complications this will always be empty.
Note new data may be pushed as a result of running openComplicationDataSourceChooser.
Note if a slot is configured to be empty then the map will contain an instance of EmptyComplicationData for that slot. Disabled complicationSlots are included in the map.
If accessed from java, consider using androidx.lifecycle.FlowLiveDataConversions.asLiveData to observe changes.
previewReferenceInstant
val previewReferenceInstant: Instant
The reference preview Instant for this watch face to render previews with.
userStyle
val userStyle: MutableStateFlow<UserStyle>
The current UserStyle. Assigning to this will cause the style to update. However, styling changes to the watch face will be reverted upon exit.
If accessed from java, consider using androidx.lifecycle.FlowLiveDataConversions.asLiveData to observe changes.
userStyleSchema
val userStyleSchema: UserStyleSchema
The watch face's UserStyleSchema.
watchFaceComponentName
val watchFaceComponentName: ComponentName
The ComponentName of the watch face being edited.
watchFaceId
val watchFaceId: WatchFaceId
Unique ID for the instance of the watch face being edited. Note each distinct ComponentName can sometimes have multiple instances. See WatchFaceId for more details.