ComplicationSlotsManager

public final class ComplicationSlotsManager


The ComplicationSlots associated with the WatchFace. Dynamic creation of ComplicationSlots isn't supported, however complicationSlots can be enabled and disabled by ComplicationSlotsUserStyleSetting.

Summary

Nested types

ComplicationSlotsManager.TapCallback

Interface used to report user taps on the ComplicationSlot.

Public fields

final @NonNull Map<@NonNull Integer, @NonNull ComplicationSlot>

A map of complication IDs to complicationSlots.

final @NonNull Map<@NonNull Integer, @NonNull TapEvent>

Map of ComplicationSlot id to the latest TapType.DOWN that the ComplicationSlot received, if any.

Public constructors

ComplicationSlotsManager(
    @NonNull Collection<@NonNull ComplicationSlot> complicationSlotCollection,
    @NonNull CurrentUserStyleRepository currentUserStyleRepository
)

Public methods

final @UiThread void

Adds a TapCallback which is called whenever the user interacts with a complication slot.

final @Nullable ComplicationSlot
get(int id)

Returns the ComplicationSlot corresponding to id, if there is one, or null.

final @Nullable ComplicationSlot

Returns the background ComplicationSlot if there is one or null otherwise.

final @Nullable ComplicationSlot
getComplicationSlotAt(@Px int x, @Px int y)

Returns the id of the complication slot at coordinates x, y or null if there isn't one.

final @UiThread void

Removes a TapCallback previously added by addTapListener.

Public fields

complicationSlots

@NonNull
public final @NonNull Map<@NonNull Integer, @NonNull ComplicationSlotcomplicationSlots

A map of complication IDs to complicationSlots.

lastComplicationTapDownEvents

@NonNull
public final @NonNull Map<@NonNull Integer, @NonNull TapEventlastComplicationTapDownEvents

Map of ComplicationSlot id to the latest TapType.DOWN that the ComplicationSlot received, if any.

Public constructors

ComplicationSlotsManager

public final ComplicationSlotsManager(
    @NonNull Collection<@NonNull ComplicationSlot> complicationSlotCollection,
    @NonNull CurrentUserStyleRepository currentUserStyleRepository
)
Parameters
@NonNull Collection<@NonNull ComplicationSlot> complicationSlotCollection

The ComplicationSlots associated with the watch face, may be empty.

@NonNull CurrentUserStyleRepository currentUserStyleRepository

The CurrentUserStyleRepository used to listen for ComplicationSlotsUserStyleSetting changes and apply them.

Public methods

addTapListener

@UiThread
@NonNull
public final @UiThread void addTapListener(
    @NonNull ComplicationSlotsManager.TapCallback tapCallback
)

Adds a TapCallback which is called whenever the user interacts with a complication slot.

get

@Nullable
public final ComplicationSlot get(int id)

Returns the ComplicationSlot corresponding to id, if there is one, or null.

getBackgroundComplicationSlot

@Nullable
public final ComplicationSlot getBackgroundComplicationSlot()

Returns the background ComplicationSlot if there is one or null otherwise.

Returns
ComplicationSlot

The background ComplicationSlot if there is one or null otherwise

getComplicationSlotAt

@Nullable
public final ComplicationSlot getComplicationSlotAt(@Px int x, @Px int y)

Returns the id of the complication slot at coordinates x, y or null if there isn't one.

Parameters
@Px int x

The x coordinate of the point to perform a hit test

@Px int y

The y coordinate of the point to perform a hit test

Returns
ComplicationSlot

The ComplicationSlot at coordinates x, y or {@code null} if there isn't one

removeTapListener

@UiThread
@NonNull
public final @UiThread void removeTapListener(
    @NonNull ComplicationSlotsManager.TapCallback tapCallback
)

Removes a TapCallback previously added by addTapListener.