WatchFace


public final class WatchFace


The return value of WatchFaceService.createWatchFace which brings together rendering, styling, complicationSlots and state observers.

Summary

Nested types

Legacy Wear 2.0 watch face styling.

public final class WatchFace.OverlayStyle

This class is deprecated. OverlayStyle will be removed in a future release.

public interface WatchFace.TapListener

Listens for taps on the watchface.

Public constructors

WatchFace(int watchFaceType, @NonNull Renderer renderer)

Public methods

final @NonNull WatchFace.LegacyWatchFaceOverlayStyle

The legacy LegacyWatchFaceOverlayStyle which only affects Wear 2.0 devices.

final @NonNull WatchFace.OverlayStyle

The OverlayStyle.

final Instant

The Instant to use for preview rendering, or null if not set in which case the system chooses the Instant to use.

final @NonNull Renderer

The Renderer for this WatchFace.

final int

The type of watch face, whether it's digital or analog.

static final boolean

Returns whether LegacyWatchFaceOverlayStyle is supported on this device.

final @NonNull WatchFace
setComplicationDeniedDialogIntent(
    Intent complicationDeniedDialogIntent
)

Sets the Intent to launch an activity which explains the watch face needs permission to display complications.

final @NonNull WatchFace
setComplicationRationaleDialogIntent(
    Intent complicationRationaleDialogIntent
)

Sets the Intent to launch an activity that explains the rational for the requesting the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATApermission prior to requesting it, if [Activity.shouldShowRequestPermissionRationale] returns true`.

final @NonNull WatchFace

Sets the legacy LegacyWatchFaceOverlayStyle which only affects Wear 2.0 devices.

final @NonNull WatchFace

This method is deprecated. OverlayStyle will be removed in a future release.

final @NonNull WatchFace
setOverridePreviewReferenceInstant(
    @NonNull Instant previewReferenceTimeMillis
)

Overrides the reference time for editor preview images.

final @NonNull WatchFace

Sets an optional TapListener which if not null gets called on the ui thread whenever the user taps on the watchface.

final @NonNull WatchFace
setUpdateScreenshotOnConfigurationChange(
    boolean updateScreenshotOnConfigurationChange
)

If updateScreenshotOnConfigurationChange is true then whenever WatchFaceService.onConfigurationChanged gets called while this watch face is active then a request will be made for the system to update the watch's screenshot displayed in the picker.

final void
setWatchFaceType(int watchFaceType)

Public constructors

WatchFace

Added in 1.0.0
public WatchFace(int watchFaceType, @NonNull Renderer renderer)
Parameters
int watchFaceType

The type of watch face, whether it's digital or analog. Used to determine the default time for editor preview screenshots.

@NonNull Renderer renderer

The Renderer for this WatchFace.

Public methods

getLegacyWatchFaceStyle

Added in 1.0.0
public final @NonNull WatchFace.LegacyWatchFaceOverlayStyle getLegacyWatchFaceStyle()

The legacy LegacyWatchFaceOverlayStyle which only affects Wear 2.0 devices.

getOverlayStyle

Added in 1.1.0
Deprecated in 1.2.0
public final @NonNull WatchFace.OverlayStyle getOverlayStyle()

The OverlayStyle. This feature is unimplemented on any platform, and will be removed.

getOverridePreviewReferenceInstant

Added in 1.0.0
public final Instant getOverridePreviewReferenceInstant()

The Instant to use for preview rendering, or null if not set in which case the system chooses the Instant to use.

getRenderer

Added in 1.0.0
public final @NonNull Renderer getRenderer()

The Renderer for this WatchFace.

getWatchFaceType

Added in 1.0.0
public final int getWatchFaceType()

The type of watch face, whether it's digital or analog. Used to determine the default time for editor preview screenshots.

isLegacyWatchFaceOverlayStyleSupported

Added in 1.0.0
public static final boolean isLegacyWatchFaceOverlayStyleSupported()

Returns whether LegacyWatchFaceOverlayStyle is supported on this device.

setComplicationDeniedDialogIntent

Added in 1.1.0
public final @NonNull WatchFace setComplicationDeniedDialogIntent(
    Intent complicationDeniedDialogIntent
)

Sets the Intent to launch an activity which explains the watch face needs permission to display complications. It is recommended the activity have a button which launches an intent with Settings.ACTION_APPLICATION_DETAILS_SETTINGS to allow the user to grant permissions if they wish.

This complicationDeniedDialogIntent is launched when the user tries to configure a complication slot when the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA permission has been denied. If the intent is not set or is null then no dialog will be displayed.

setComplicationRationaleDialogIntent

Added in 1.1.0
public final @NonNull WatchFace setComplicationRationaleDialogIntent(
    Intent complicationRationaleDialogIntent
)

Sets the Intent to launch an activity that explains the rational for the requesting the com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATApermission prior to requesting it, if [Activity.shouldShowRequestPermissionRationale] returns true`.

If the intent is not set or is null then no dialog will be displayed.

setLegacyWatchFaceStyle

Added in 1.0.0
public final @NonNull WatchFace setLegacyWatchFaceStyle(
    @NonNull WatchFace.LegacyWatchFaceOverlayStyle legacyWatchFaceStyle
)

Sets the legacy LegacyWatchFaceOverlayStyle which only affects Wear 2.0 devices.

setOverlayStyle

Added in 1.1.0
Deprecated in 1.2.0
public final @NonNull WatchFace setOverlayStyle(@NonNull WatchFace.OverlayStyle watchFaceOverlayStyle)

Sets the OverlayStyle which is ignored because this feature is unimplemented on any platform, and will be removed.

setOverridePreviewReferenceInstant

Added in 1.0.0
public final @NonNull WatchFace setOverridePreviewReferenceInstant(
    @NonNull Instant previewReferenceTimeMillis
)

Overrides the reference time for editor preview images.

Parameters
@NonNull Instant previewReferenceTimeMillis

The UTC preview time in milliseconds since the epoch

setTapListener

Added in 1.0.0
public final @NonNull WatchFace setTapListener(WatchFace.TapListener tapListener)

Sets an optional TapListener which if not null gets called on the ui thread whenever the user taps on the watchface.

setUpdateScreenshotOnConfigurationChange

Added in 1.3.0-alpha04
public final @NonNull WatchFace setUpdateScreenshotOnConfigurationChange(
    boolean updateScreenshotOnConfigurationChange
)

If updateScreenshotOnConfigurationChange is true then whenever WatchFaceService.onConfigurationChanged gets called while this watch face is active then a request will be made for the system to update the watch's screenshot displayed in the picker.

By default this is off.

Note if WatchFaceService.onConfigurationChanged or Renderer.sendPreviewImageNeedsUpdateRequest get called very frequently then the system may throttle the rate at which screenshots are taken.

setWatchFaceType

Added in 1.0.0
public final void setWatchFaceType(int watchFaceType)
Parameters
int watchFaceType

The type of watch face, whether it's digital or analog. Used to determine the default time for editor preview screenshots.