# ComplicationData

Artifact: [androidx.wear.watchface:watchface-complications-data](https://developer.android.com/jetpack/androidx/releases/wear-watchface) [View Source](https://cs.android.com/search?q=file:androidx/wear/watchface/complications/data/Data.kt+class:androidx.wear.watchface.complications.data.ComplicationData) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

*** ** * ** ***


```
sealed class ComplicationData
```

<br />

Known direct subclasses [EmptyComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/EmptyComplicationData), [GoalProgressComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/GoalProgressComplicationData), [LongTextComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/LongTextComplicationData), [MonochromaticImageComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/MonochromaticImageComplicationData), [NoDataComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NoDataComplicationData), [NoPermissionComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NoPermissionComplicationData), [NotConfiguredComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NotConfiguredComplicationData), [PhotoImageComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/PhotoImageComplicationData), [RangedValueComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/RangedValueComplicationData), [ShortTextComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ShortTextComplicationData), [SmallImageComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/SmallImageComplicationData), [WeightedElementsComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/WeightedElementsComplicationData)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/EmptyComplicationData` | Type sent when the user has specified that an active complication should have no complication data source, i.e. when the user has chosen "Empty" in the complication data source chooser. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/GoalProgressComplicationData` | Type used for complications which shows the user's progress towards a goal, E.g. you've done 2400 out of your daily target of 10000 steps. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/LongTextComplicationData` | Type used for complications where the primary piece of data is a piece of text. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/MonochromaticImageComplicationData` | Type used for complications which consist only of a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/MonochromaticImage`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NoDataComplicationData` | Type that can be sent by any complication data source, regardless of the configured type, when the complication data source has no data to be displayed. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NoPermissionComplicationData` | Type sent by the system when the watch face does not have permission to receive complication data. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NotConfiguredComplicationData` | Type sent when a complication does not have a complication data source configured. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/PhotoImageComplicationData` | Type used for complications which consist only of an image that is expected to fill a large part of the watch face, large enough to be shown as either a background or as part of a high resolution complication. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/RangedValueComplicationData` | Type used for complications including a numerical value within a range, such as a percentage. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ShortTextComplicationData` | Type used for complications where the primary piece of data is a short piece of text (expected to be no more than seven characters in length). |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/SmallImageComplicationData` | Type used for complications which consist only of a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/SmallImage`. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/WeightedElementsComplicationData` | Type used for complications which want to display the breakdown of something (e.g. nutrition data) perhaps as a pie chart, or as a stacked bar chart etc. |

*** ** * ** ***

Base type for all different types of `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData` types.

Please note to aid unit testing of `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/datasource/ComplicationDataSourceService`, `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#equals(kotlin.Any)`, `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#hashCode()` and `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/to-string.html` have been overridden for all the types of ComplicationData, however due to the embedded `https://developer.android.com/reference/android/graphics/drawable/Icon.html` class we have to fall back to reference equality and hashing below API 28 and also for the `https://developer.android.com/reference/android/graphics/drawable/Icon.html`s that don't use either a resource or a uri (these should be rare but they can exist).

## Evaluation

Some dynamic fields may be evaluated by the platform, and refresh more often than the `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/datasource/ComplicationDataSourceService` provides them. There are interesting use cases that the user of these dynamic fields must consider:

- The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData` can be "invalidated" when the dynamic field cannot be evaluated, e.g. when a data source is not available.

When this happens, the `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#dynamicValueInvalidationFallback()` field is used instead of this `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData`, provided as a `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/NoDataComplicationData#placeholder()`.

- If an incompatible platform doesn't recognize the dynamic field, the dynamic field's fallback companion field will be used instead. An example field is `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/DynamicComplicationText#fallbackValue()`.

Although the dynamic field APIs are annotated with `https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi`, this does not ensure the platform will support the dynamic field at that API level. However, the platform *definitely doesn't* support the dynamic field below that API level.

## Summary

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#ComplicationData(androidx.wear.watchface.complications.data.ComplicationType,android.app.PendingIntent,android.support.wearable.complications.ComplicationData,com.google.wear.services.complications.ComplicationData,androidx.wear.watchface.complications.data.TimeRange,android.content.ComponentName,kotlin.Int,kotlin.Int,androidx.wear.watchface.complications.data.ComplicationData,android.os.PersistableBundle)( type: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationType, tapAction: https://developer.android.com/reference/android/app/PendingIntent.html?, cachedWireComplicationData: https://developer.android.com/reference/android/support/wearable/complications/ComplicationData.html?, cachedWearSdkComplicationData: https://developer.android.com/reference/com/google/wear/services/complications/ComplicationData.html?, validTimeRange: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeRange, dataSource: https://developer.android.com/reference/android/content/ComponentName.html?, persistencePolicy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, displayPolicy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, dynamicValueInvalidationFallback: https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData?, extras: https://developer.android.com/reference/android/os/PersistableBundle.html )` |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#getNextChangeInstant(java.time.Instant)(afterInstant: https://developer.android.com/reference/java/time/Instant.html)` Returns the next `https://developer.android.com/reference/java/time/Instant.html` after `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#getNextChangeInstant(java.time.Instant)` at which any field of the complication may change. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#hasPlaceholderFields()()` Returns `true` if any of the fields of this ComplicationData are placeholders. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#hashCode()()` |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/android/content/ComponentName.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#dataSource()` The `https://developer.android.com/reference/android/content/ComponentName.html` of the `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/datasource/ComplicationDataSourceService` that provided the ComplicationData. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#displayPolicy()` The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationDisplayPolicies` for this complication. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#dynamicValueInvalidationFallback()` Used in case any dynamic value has been invalidated. |
| `https://developer.android.com/reference/android/os/PersistableBundle.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#extras()` A copy of any extras set by a complication provider with the privileged permission `com.google.wear.permission.SET_COMPLICATION_EXTRAS` or `https://developer.android.com/reference/android/os/PersistableBundle.html#EMPTY`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#persistencePolicy()` The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationPersistencePolicies` for this complication. |
| `https://developer.android.com/reference/android/app/PendingIntent.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#tapAction()` The `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the complication is tapped on. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#tapActionLostDueToSerialization()` `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#tapAction()` which is a `https://developer.android.com/reference/android/app/PendingIntent.html` unfortunately can't be serialized. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationType` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#type()` The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationType` of this complication data. |
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeRange` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#validTimeRange()` The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeRange` within which the complication should be displayed. |

## Protected constructors

### ComplicationData

```
protected ComplicationData(
    type: ComplicationType,
    tapAction: PendingIntent?,
    cachedWireComplicationData: ComplicationData? = null,
    cachedWearSdkComplicationData: ComplicationData? = null,
    validTimeRange: TimeRange = TimeRange.ALWAYS,
    dataSource: ComponentName?,
    persistencePolicy: Int,
    displayPolicy: Int,
    dynamicValueInvalidationFallback: ComplicationData?,
    extras: PersistableBundle
)
```

## Public functions

### equals

```
open operator fun equals(other: Any?): Boolean
```

### getNextChangeInstant

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.1.0)

```
open fun getNextChangeInstant(afterInstant: Instant): Instant
```

Returns the next `https://developer.android.com/reference/java/time/Instant.html` after `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#getNextChangeInstant(java.time.Instant)` at which any field of the complication may change. If there's no scheduled changes then `https://developer.android.com/reference/java/time/Instant.html#MAX` will be returned.

See `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationText#getNextChangeTime(java.time.Instant)`

| Parameters |
|---|---|
| `afterInstant: https://developer.android.com/reference/java/time/Instant.html` | The reference `https://developer.android.com/reference/java/time/Instant.html`, after which changes will be reported. |

### hasPlaceholderFields

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.1.0)

```
open fun hasPlaceholderFields(): Boolean
```

Returns `true` if any of the fields of this ComplicationData are placeholders. I.e. if any fields are equal to: `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationText#PLACEHOLDER()`, `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/SmallImage#PLACEHOLDER()`, `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/MonochromaticImage#PLACEHOLDER()`, `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/PhotoImageComplicationData#PLACEHOLDER()`, or `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/RangedValueComplicationData#PLACEHOLDER()`.

### hashCode

```
open fun hashCode(): Int
```

## Public properties

### dataSource

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.1.0)

```
val dataSource: ComponentName?
```

The `https://developer.android.com/reference/android/content/ComponentName.html` of the `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/datasource/ComplicationDataSourceService` that provided the ComplicationData. This may be `null` when run on old systems.

### displayPolicy

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.2.0)

```
val displayPolicy: Int
```

The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationDisplayPolicies` for this complication. This requires the watchface to be built with a compatible library to work.

Value is either `0` or a combination of the following:

- `0`
- `1`

<br />

### dynamicValueInvalidationFallback

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.2.0)

```
val dynamicValueInvalidationFallback: ComplicationData?
```

Used in case any dynamic value has been invalidated.

IMPORTANT: This is only used when the system supports dynamic values. See each dynamic field's fallback companion field for the situation where the system does not support dynamic values at all.

### extras

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val extras: PersistableBundle
```

A copy of any extras set by a complication provider with the privileged permission `com.google.wear.permission.SET_COMPLICATION_EXTRAS` or `https://developer.android.com/reference/android/os/PersistableBundle.html#EMPTY`. Extras set by a provider without permission will be stripped. It is assumed that an OEM wrote both the complication provider and the watch face, using fields they defined.

### persistencePolicy

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.2.0)

```
val persistencePolicy: Int
```

The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationPersistencePolicies` for this complication. This requires the watchface to be built with a compatible library to work.

Value is either `0` or a combination of the following:

- `0`
- `1`

<br />

### tapAction

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
val tapAction: PendingIntent?
```

The `https://developer.android.com/reference/android/app/PendingIntent.html` to send when the complication is tapped on.

### tapActionLostDueToSerialization

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.1.0)

```
var tapActionLostDueToSerialization: Boolean
```

`https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData#tapAction()` which is a `https://developer.android.com/reference/android/app/PendingIntent.html` unfortunately can't be serialized. This property is 'true' if tapAction has been lost due to serialization (typically because it has been cached locally). When 'true' the watch face should render the complication differently (e.g. as semi-transparent or grayed out) to signal to the user it can't be tapped. The system will subsequently deliver an updated complication, with a tapAction where applicable.

### type

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
val type: ComplicationType
```

The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationType` of this complication data.

### validTimeRange

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
val validTimeRange: TimeRange
```

The `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeRange` within which the complication should be displayed. Whether the complication is active and should be displayed at the given time should be checked with `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/TimeRange#contains(java.time.Instant)`.