ListenableWatchFaceControlClient

public class ListenableWatchFaceControlClient implements WatchFaceControlClient


ListenableFuture-based compatibility wrapper around WatchFaceControlClient's suspending methods. This class is open to allow mocking.

Summary

Public constructors

Public methods

void
@Nullable HeadlessWatchFaceClient
createHeadlessWatchFaceClient(
    @NonNull ComponentName watchFaceName,
    @NonNull DeviceConfig deviceConfig,
    int surfaceWidth,
    int surfaceHeight
)

Creates a HeadlessWatchFaceClient with the specified DeviceConfig.

@NonNull Map<@NonNull Integer, @NonNull DefaultComplicationDataSourcePolicyAndType>

Returns a map of androidx.wear.watchface.ComplicationSlot id to the DefaultComplicationDataSourcePolicyAndType for each androidx.wear.watchface.ComplicationSlot in the watchface corresponding to watchFaceName.

@NonNull EditorServiceClient
@Nullable InteractiveWatchFaceClient

Returns the InteractiveWatchFaceClient for the given instance id, or null if no such instance exists.

@NonNull InteractiveWatchFaceClient
getOrCreateInteractiveWatchFaceClient(
    @NonNull String id,
    @NonNull DeviceConfig deviceConfig,
    @NonNull WatchUiState watchUiState,
    @Nullable UserStyleData userStyle,
    @Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

Requests either an existing InteractiveWatchFaceClient with the specified id or schedules creation of an InteractiveWatchFaceClient for the next time the WallpaperService creates an engine.

@NonNull ListenableFuture<@NonNull InteractiveWatchFaceClient>
listenableGetOrCreateInteractiveWatchFaceClient(
    @NonNull String id,
    @NonNull DeviceConfig deviceConfig,
    @NonNull WatchUiState watchUiState,
    @Nullable UserStyleData userStyle,
    @Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

ListenableFuture wrapper around WatchFaceControlClient.getOrCreateInteractiveWatchFaceClient.

Public constructors

ListenableWatchFaceControlClient

public final ListenableWatchFaceControlClient(
    @NonNull WatchFaceControlClient watchFaceControlClient
)

Public methods

close

@NonNull
public void close()

createHeadlessWatchFaceClient

@Nullable
public HeadlessWatchFaceClient createHeadlessWatchFaceClient(
    @NonNull ComponentName watchFaceName,
    @NonNull DeviceConfig deviceConfig,
    int surfaceWidth,
    int surfaceHeight
)

Creates a HeadlessWatchFaceClient with the specified DeviceConfig. Screenshots made with HeadlessWatchFaceClient.renderWatchFaceToBitmap will be surfaceWidth x surfaceHeight in size.

When finished call HeadlessWatchFaceClient.close to release resources.

Parameters
@NonNull ComponentName watchFaceName

The ComponentName of the watch face to create a headless instance for must be in the same APK the WatchFaceControlClient is connected to. NB a single apk can contain multiple watch faces.

@NonNull DeviceConfig deviceConfig

The hardware DeviceConfig

int surfaceWidth

The width of screen shots taken by the HeadlessWatchFaceClient

int surfaceHeight

The height of screen shots taken by the HeadlessWatchFaceClient

Returns
HeadlessWatchFaceClient

The HeadlessWatchFaceClient or null if watchFaceName is unrecognized.

getDefaultComplicationDataSourcePoliciesAndType

@NonNull
public Map<@NonNull Integer, @NonNull DefaultComplicationDataSourcePolicyAndTypegetDefaultComplicationDataSourcePoliciesAndType(
    @NonNull ComponentName watchFaceName
)

Returns a map of androidx.wear.watchface.ComplicationSlot id to the DefaultComplicationDataSourcePolicyAndType for each androidx.wear.watchface.ComplicationSlot in the watchface corresponding to watchFaceName. Where possible a fast path is used that doesn't need to fully construct the corresponding watch face.

Parameters
@NonNull ComponentName watchFaceName

The ComponentName of the watch face to obtain the map of DefaultComplicationDataSourcePolicyAndTypes for. It must be in the same APK the WatchFaceControlClient is connected to. NB a single apk can contain multiple watch faces.

getEditorServiceClient

@NonNull
public EditorServiceClient getEditorServiceClient()

getInteractiveWatchFaceClientInstance

@Nullable
public InteractiveWatchFaceClient getInteractiveWatchFaceClientInstance(@NonNull String instanceId)

Returns the InteractiveWatchFaceClient for the given instance id, or null if no such instance exists.

When finished call InteractiveWatchFaceClient.close to release resources.

Parameters
@NonNull String instanceId

The name of the interactive watch face instance to retrieve

Returns
InteractiveWatchFaceClient

The InteractiveWatchFaceClient or null if instanceId is unrecognized, or ServiceNotBoundException if the WatchFaceControlService is not bound.

getOrCreateInteractiveWatchFaceClient

@NonNull
public InteractiveWatchFaceClient getOrCreateInteractiveWatchFaceClient(
    @NonNull String id,
    @NonNull DeviceConfig deviceConfig,
    @NonNull WatchUiState watchUiState,
    @Nullable UserStyleData userStyle,
    @Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

Requests either an existing InteractiveWatchFaceClient with the specified id or schedules creation of an InteractiveWatchFaceClient for the next time the WallpaperService creates an engine.

NOTE that currently only one InteractiveWatchFaceClient per process can exist at a time.

Parameters
@NonNull String id

The ID for the requested InteractiveWatchFaceClient.

@NonNull DeviceConfig deviceConfig

The DeviceConfig for the wearable.

@NonNull WatchUiState watchUiState

The initial WatchUiState for the wearable.

@Nullable UserStyleData userStyle

Optional UserStyleData to apply to the instance (whether or not it's created). If null then the pre-existing user style is preserved (if the instance is created this will be the androidx.wear.watchface.style.UserStyleSchema's default).

@Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData

The initial androidx.wear.watchface.ComplicationSlot data, or null if unavailable.

Returns
InteractiveWatchFaceClient

The InteractiveWatchFaceClient, this should be closed when finished.

Throws
ServiceStartFailureException

if the watchface dies during startup.

listenableGetOrCreateInteractiveWatchFaceClient

@NonNull
public ListenableFuture<@NonNull InteractiveWatchFaceClientlistenableGetOrCreateInteractiveWatchFaceClient(
    @NonNull String id,
    @NonNull DeviceConfig deviceConfig,
    @NonNull WatchUiState watchUiState,
    @Nullable UserStyleData userStyle,
    @Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

ListenableFuture wrapper around WatchFaceControlClient.getOrCreateInteractiveWatchFaceClient. This is open to allow mocking.

Parameters
@NonNull String id

The Id of the interactive instance to get or create.

@NonNull DeviceConfig deviceConfig

The DeviceConfig of the interactive instance (only used when creating)

@NonNull WatchUiState watchUiState

The initial WatchUiState for the wearable.

@Nullable UserStyleData userStyle

Optional UserStyleData to apply to the instance (whether or not it's created). If null then the pre-existing user style is preserved (if the instance is created this will be the androidx.wear.watchface.style.UserStyleSchema's default).

@Nullable Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData

The initial androidx.wear.watchface.ComplicationSlot data, or null if unavailable.