UserStyle

public final class UserStyle


An immutable representation of user style choices that maps each UserStyleSetting to UserStyleSetting.Option.

This is intended for use by the WatchFace and entries are the same as the ones specified in the UserStyleSchema. This means you can't serialize a UserStyle directly, instead you need to use a UserStyleData (see toUserStyleData).

To modify the user style, you should call toMutableUserStyle and construct a new UserStyle instance with MutableUserStyle.toUserStyle.

Summary

Public constructors

Constructs a copy of the UserStyle.

Constructs a UserStyle with the given selected options for each setting.

UserStyle(
    @NonNull UserStyleData userStyle,
    @NonNull UserStyleSchema styleSchema
)

Constructs a UserStyle from a UserStyleData and the UserStyleSchema.

Public methods

boolean
boolean
boolean
@Nullable UserStyleSetting.Option

Returns the UserStyleSetting.Option for key if there is one or null otherwise.

final @Nullable UserStyleSetting.Option

Returns the UserStyleSetting.Option for settingId if there is one or null otherwise.

int
boolean
final @NonNull MutableUserStyle

Returns a mutable instance initialized with the same mapping.

@NonNull String
final @NonNull UserStyleData

Returns the style as a UserStyleData.

Public fields

size

@NonNull
public int size

The number of entries in the style.

Public constructors

UserStyle

public final UserStyle(@NonNull UserStyle userStyle)

Constructs a copy of the UserStyle. It is backed by the same map.

UserStyle

public final UserStyle(
    @NonNull Map<@NonNull UserStyleSetting, @NonNull UserStyleSetting.Option> selectedOptions
)

Constructs a UserStyle with the given selected options for each setting.

A copy of the selectedOptions map will be created, so that changed to the map will not be reflected by this object.

UserStyle

public final UserStyle(
    @NonNull UserStyleData userStyle,
    @NonNull UserStyleSchema styleSchema
)

Constructs a UserStyle from a UserStyleData and the UserStyleSchema. Unrecognized style settings will be ignored. Unlisted style settings will be initialized with that setting's default option.

Parameters
@NonNull UserStyleData userStyle

The UserStyle represented as a UserStyleData.

@NonNull UserStyleSchema styleSchema

The UserStyleSchema for this UserStyle, describes how we interpret userStyle.

Public methods

containsKey

@NonNull
public boolean containsKey(@NonNull UserStyleSetting key)

containsValue

@NonNull
public boolean containsValue(@NonNull UserStyleSetting.Option value)

equals

@NonNull
public boolean equals(@Nullable Object other)

get

@Nullable
public UserStyleSetting.Option get(@NonNull UserStyleSetting key)

Returns the UserStyleSetting.Option for key if there is one or null otherwise.

get

@Nullable
public final UserStyleSetting.Option get(@NonNull UserStyleSetting.Id settingId)

Returns the UserStyleSetting.Option for settingId if there is one or null otherwise. Note this is an O(n) operation.

hashCode

@NonNull
public int hashCode()

isEmpty

@NonNull
public boolean isEmpty()

toMutableUserStyle

@NonNull
public final MutableUserStyle toMutableUserStyle()

Returns a mutable instance initialized with the same mapping.

toString

@NonNull
public String toString()

toUserStyleData

@NonNull
public final UserStyleData toUserStyleData()

Returns the style as a UserStyleData.