ComplicationSlot
public final class ComplicationSlot
Represents the slot an individual complication on the screen may go in. The number of ComplicationSlots is fixed (see ComplicationSlotsManager) but ComplicationSlots can be enabled or disabled via UserStyleSetting.ComplicationSlotsUserStyleSetting.
Taps on the watch are tested first against each ComplicationSlot's ComplicationSlotBounds.perComplicationTypeBounds for the relevant ComplicationType. Its assumed that ComplicationSlotBounds.perComplicationTypeBounds don't overlap. If no intersection was found then taps are checked against ComplicationSlotBounds.perComplicationTypeBounds expanded by ComplicationSlotBounds.perComplicationTypeMargins. Expanded bounds can overlap so the ComplicationSlot with the lowest id that intersects the coordinates, if any, is selected.
use Watch Face Format instead
Summary
Nested types |
|---|
public final class ComplicationSlot.BuilderThis class is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public methods |
|
|---|---|
final @NonNull Rect |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
static final @NonNull ComplicationSlot.Builder |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
static final @NonNull ComplicationSlot.Builder |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
static final @NonNull ComplicationSlot.Builder |
@ComplicationExperimentalThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
static final @NonNull ComplicationSlot.Builder |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
boolean |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final int |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final int |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull CanvasComplicationFactory |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull StateFlow<@NonNull ComplicationData> |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull ComplicationSlotBounds |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull Bundle |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull DefaultComplicationDataSourcePolicy |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull ComplicationType |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final int |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final Integer |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull CanvasComplication |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final Integer |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull List<@NonNull ComplicationType> |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final @NonNull ComplicationTapFilter |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
int |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final boolean |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final boolean |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final boolean |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final boolean |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
@UiThreadThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
@UiThreadThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public methods
computeBounds
public final @NonNull RectcomputeBounds(@NonNull Rect screen, boolean applyMargins)
Computes the bounds of the complication by converting the unitSquareBounds of the current complication type to pixels based on the screen's dimensions.
createBackgroundComplicationSlotBuilder
public static final @NonNull ComplicationSlot.BuildercreateBackgroundComplicationSlotBuilder(
int id,
@NonNull CanvasComplicationFactory canvasComplicationFactory,
@NonNull List<@NonNull ComplicationType> supportedTypes,
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy
)
Constructs a Builder for a complication with bound type ComplicationSlotBoundsType.BACKGROUND whose bounds cover the entire screen. A background complication is for watch faces that wish to have a full screen user selectable backdrop. This sort of complication isn't clickable and at most one may be present in the list of complicationSlots.
| Parameters | |
|---|---|
int id |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
@NonNull CanvasComplicationFactory canvasComplicationFactory |
The |
@NonNull List<@NonNull ComplicationType> supportedTypes |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy |
The |
createEdgeComplicationSlotBuilder
public static final @NonNull ComplicationSlot.BuildercreateEdgeComplicationSlotBuilder(
int id,
@NonNull CanvasComplicationFactory canvasComplicationFactory,
@NonNull List<@NonNull ComplicationType> supportedTypes,
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy,
@NonNull ComplicationSlotBounds bounds,
@NonNull ComplicationTapFilter complicationTapFilter
)
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.EDGE.
An edge complication is drawn around the border of the display and has custom hit test logic (see complicationTapFilter). When tapped the associated intent is dispatched. Edge complicationSlots should have a custom renderer with CanvasComplication.drawHighlight overridden.
Note hit detection in an editor for ComplicationSlots created with this method is not supported.
| Parameters | |
|---|---|
int id |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
@NonNull CanvasComplicationFactory canvasComplicationFactory |
The |
@NonNull List<@NonNull ComplicationType> supportedTypes |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy |
The |
@NonNull ComplicationSlotBounds bounds |
The complication's |
@NonNull ComplicationTapFilter complicationTapFilter |
The |
createEdgeComplicationSlotBuilder
@ComplicationExperimental
public static final @NonNull ComplicationSlot.BuildercreateEdgeComplicationSlotBuilder(
int id,
@NonNull CanvasComplicationFactory canvasComplicationFactory,
@NonNull List<@NonNull ComplicationType> supportedTypes,
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy,
@NonNull ComplicationSlotBounds bounds,
@NonNull BoundingArc boundingArc,
@NonNull ComplicationTapFilter complicationTapFilter
)
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.EDGE, whose contents are contained within boundingArc.
| Parameters | |
|---|---|
int id |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
@NonNull CanvasComplicationFactory canvasComplicationFactory |
The |
@NonNull List<@NonNull ComplicationType> supportedTypes |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy |
The |
@NonNull ComplicationSlotBounds bounds |
The complication's |
@NonNull BoundingArc boundingArc |
The |
@NonNull ComplicationTapFilter complicationTapFilter |
The |
createRoundRectComplicationSlotBuilder
public static final @NonNull ComplicationSlot.BuildercreateRoundRectComplicationSlotBuilder(
int id,
@NonNull CanvasComplicationFactory canvasComplicationFactory,
@NonNull List<@NonNull ComplicationType> supportedTypes,
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy,
@NonNull ComplicationSlotBounds bounds
)
Constructs a Builder for a complication with bounds type ComplicationSlotBoundsType.ROUND_RECT. This is the most common type of complication. These can be tapped by the user to trigger the associated intent.
| Parameters | |
|---|---|
int id |
The watch face's ID for this complication. Can be any integer but should be unique within the watch face. |
@NonNull CanvasComplicationFactory canvasComplicationFactory |
The |
@NonNull List<@NonNull ComplicationType> supportedTypes |
The types of complication supported by this ComplicationSlot. Used during complication, this list should be non-empty. |
@NonNull DefaultComplicationDataSourcePolicy defaultDataSourcePolicy |
The |
@NonNull ComplicationSlotBounds bounds |
The complication's |
getAccessibilityTraversalIndex
@UiThread
public final intgetAccessibilityTraversalIndex()
This is used to determine the order in which accessibility labels for the watch face are read to the user. Accessibility labels are automatically generated for the time and complicationSlots. See also Renderer.additionalContentDescriptionLabels.
getBoundsType
public final int getBoundsType()The ComplicationSlotBoundsTypeIntDef of the complication slot.
getCanvasComplicationFactory
public final @NonNull CanvasComplicationFactorygetCanvasComplicationFactory()
The CanvasComplicationFactory used to generate a CanvasComplication for rendering the complication. The factory allows us to decouple ComplicationSlot from potentially expensive asset loading.
getComplicationData
public final @NonNull StateFlow<@NonNull ComplicationData>getComplicationData()
The androidx.wear.watchface.complications.data.ComplicationData associated with the ComplicationSlot. This defaults to NoDataComplicationData.
getComplicationSlotBounds
@UiThread
public final @NonNull ComplicationSlotBoundsgetComplicationSlotBounds()
The complication's ComplicationSlotBounds which are converted to pixels during rendering.
Note it's not allowed to change the bounds of a background complication because they are assumed to always cover the entire screen.
getConfigExtras
public final @NonNull BundlegetConfigExtras()
Extras to be merged into the Intent sent when invoking the complication data source chooser activity.
getDefaultDataSourcePolicy
@UiThread
public final @NonNull DefaultComplicationDataSourcePolicygetDefaultDataSourcePolicy()
The DefaultComplicationDataSourcePolicy which defines the default complicationSlots providers selected when the user hasn't yet made a choice. See also defaultDataSourceType.
@UiThread
public final @NonNull ComplicationTypegetDefaultDataSourceType()
The default ComplicationType to use alongside defaultDataSourcePolicy.
getId
public final int getId()The Watch Face's ID for the complication slot.
getNameResourceId
@UiThread
public final IntegergetNameResourceId()
The optional ID of string resource (or null if absent) to identify the complication slot on screen in an editor. These strings should be short (perhaps 10 characters max) E.g. complication slots named 'left' and 'right' might be shown by the editor in a list from which the user selects a complication slot for editing.
getRenderer
public final @NonNull CanvasComplicationgetRenderer()
The CanvasComplication used to render the complication. This can't be used until after WatchFaceService.createWatchFace has completed.
getScreenReaderNameResourceId
@UiThread
public final IntegergetScreenReaderNameResourceId()
The optional ID of a string resource (or null if absent) for use by a watch face editor to identify the complication slot in a screen reader. While similar to nameResourceId this string can be longer and should be more descriptive. E.g. saying 'left complication' rather than just 'left'.
getSupportedTypes
public final @NonNull List<@NonNull ComplicationType>getSupportedTypes()
getTapFilter
public final @NonNull ComplicationTapFiltergetTapFilter()
The ComplicationTapFilter used to determine whether or not a tap hit the complication slot.
isActiveAt
public final booleanisActiveAt(@NonNull Instant instant)
Whether or not the complication should be considered active and should be rendered at the specified time.
isEnabled
@UiThread
public final booleanisEnabled()
Whether or not the complication should be drawn and accept taps.
isFixedComplicationDataSource
public final boolean isFixedComplicationDataSource()Whether or not the complication data source is fixed (i.e. can't be changed by the user). This is useful for watch faces built around specific complications.
isInitiallyEnabled
public final boolean isInitiallyEnabled()At creation a complication slot is either enabled or disabled. This can be overridden by a ComplicationSlotsUserStyleSetting (see ComplicationSlotOverlay.enabled). Editors need to know the initial state of a complication slot to predict the effects of making a style change.
render
@UiThread
public final voidrender(
@NonNull Canvas canvas,
@NonNull ZonedDateTime zonedDateTime,
@NonNull RenderParameters renderParameters
)
Watch faces should use this method to render a complication. Note the system may call this.
| Parameters | |
|---|---|
@NonNull Canvas canvas |
The |
@NonNull ZonedDateTime zonedDateTime |
The |
@NonNull RenderParameters renderParameters |
The current |
renderHighlightLayer
@UiThread
public final voidrenderHighlightLayer(
@NonNull Canvas canvas,
@NonNull ZonedDateTime zonedDateTime,
@NonNull RenderParameters renderParameters
)
Watch faces should use this method to render non-fixed complicationSlots for any highlight layer pass. Note the system may call this.
| Parameters | |
|---|---|
@NonNull Canvas canvas |
The |
@NonNull ZonedDateTime zonedDateTime |
The |
@NonNull RenderParameters renderParameters |
The current |
setConfigExtras
public final voidsetConfigExtras(@NonNull Bundle value)
Extras to be merged into the Intent sent when invoking the complication data source chooser activity.