# StrokePaintAnimationClock

Artifact: [androidx.ink:ink-strokes](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/strokes/StrokePaintAnimationClock.kt+class:androidx.ink.strokes.StrokePaintAnimationClock) Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

*** ** * ** ***


```
public fun interface StrokePaintAnimationClock
```

<br />

*** ** * ** ***

Controls animated paint textures for rendered strokes. Typically a single `https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock` object is used for all strokes in a document.

## Summary

| ### Public fields |
|---|---|
| `default static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock` | `https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock#STOPPED_CLOCK()` An animation clock whose clock state never changes. |

| ### Public methods |
|---|---|
| `default static final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock#calculateBasePaintAnimationPhaseForNewStroke(kotlin.Long,kotlin.Long)( long clockStateMillis, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 16777216) long brushFamilyLoopDurationMillis )` Given a whole-stroke animation duration, calculates the \[0, 1) base paint animation phase value for the stroke. |
| `default static final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock#calculateCurrentAnimationPhaseForBrushPaint(kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Float)( long clockStateMillis, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 16777216) long brushFamilyLoopDurationMillis, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 16777216) long brushPaintLoopDurationMillis, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) float strokeBasePaintAnimationPhase )` Given a stroke's base paint animation phase, and its `BrushFamily`'s paint animation loop duration, and the paint animation loop duration for a particular `BrushPaint` in that family, returns the \[0, 1) phase value that `BrushPaint` should have at the given clock state. |
| `abstract long` | `@https://developer.android.com/reference/androidx/annotation/AnyThread https://developer.android.com/reference/androidx/ink/strokes/StrokePaintAnimationClock#getClockStateMillis()()` Returns the number of subjective milliseconds that have elapsed since this clock's zero state. |

## Public fields

### STOPPED_CLOCK

```
default static final @NonNull StrokePaintAnimationClock STOPPED_CLOCK
```

An animation clock whose clock state never changes.

## Public methods

### calculateBasePaintAnimationPhaseForNewStroke

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

```
default static final @FloatRange(from = 0.0, to = 1.0, toInclusive = false) float calculateBasePaintAnimationPhaseForNewStroke(
    long clockStateMillis,
    @IntRange(from = 0, to = 16777216) long brushFamilyLoopDurationMillis
)
```

Given a whole-stroke animation duration, calculates the \[0, 1) base paint animation phase value for the stroke. This is the paint animation progress value that the stroke would use if the paint animation clock state were zero, such that the stroke is at the start of its animation at the current clock state.

If `brushFamilyLoopDurationMillis` is zero, indicating that the stroke's `BrushFamily` contains no animated `BrushPaint`s, then this method returns zero.

### calculateCurrentAnimationPhaseForBrushPaint

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

```
default static final @FloatRange(from = 0.0, to = 1.0, toInclusive = false) float calculateCurrentAnimationPhaseForBrushPaint(
    long clockStateMillis,
    @IntRange(from = 0, to = 16777216) long brushFamilyLoopDurationMillis,
    @IntRange(from = 0, to = 16777216) long brushPaintLoopDurationMillis,
    @FloatRange(from = 0.0, to = 1.0, toInclusive = false) float strokeBasePaintAnimationPhase
)
```

Given a stroke's base paint animation phase, and its `BrushFamily`'s paint animation loop duration, and the paint animation loop duration for a particular `BrushPaint` in that family, returns the \[0, 1) phase value that `BrushPaint` should have at the given clock state.

If `brushPaintLoopDurationMillis` is zero, indicating that the `BrushPaint` is not animated, then this method returns zero. Otherwise, `brushFamilyLoopDurationMillis` must be a multiple of `brushPaintLoopDurationMillis`.

### getClockStateMillis

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

```
@AnyThread
abstract long getClockStateMillis()
```

Returns the number of subjective milliseconds that have elapsed since this clock's zero state. Depending on the implementation, this value may update only once per frame, and it may change at a different speed than real time.

This method must be safe to call from any thread.