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

Interface used to report user taps on the ComplicationSlot.

Public constructors

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

Public methods

final void

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

boolean
equals(Object other)
final ComplicationSlot
get(int id)

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

final ComplicationSlot

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

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.

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.

int
final void

Removes a TapCallback previously added by addTapListener.

Public constructors

ComplicationSlotsManager

Added in 1.0.0
public 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

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

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

equals

public boolean equals(Object other)

get

Added in 1.0.0
public final ComplicationSlot get(int id)

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

getBackgroundComplicationSlot

Added in 1.0.0
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

Added in 1.0.0
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. Initially checks slots without margins (should be no overlaps) then then if there was no hit it tries again this time with margins (overlaps are possible) reporting the first hit if any.

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

getComplicationSlots

Added in 1.0.0
public final @NonNull Map<@NonNull Integer, @NonNull ComplicationSlotgetComplicationSlots()

A map of complication IDs to complicationSlots.

getLastComplicationTapDownEvents

Added in 1.0.0
public final @NonNull Map<@NonNull Integer, @NonNull TapEventgetLastComplicationTapDownEvents()

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

hashCode

public int hashCode()

removeTapListener

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

Removes a TapCallback previously added by addTapListener.