# TimeAnimator

Artifact: [androidx.core:core-animation](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/animation/TimeAnimator.java+class:androidx.core.animation.TimeAnimator) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

*** ** * ** ***


```
public class TimeAnimator extends ValueAnimator
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [androidx.core.animation.Animator](https://developer.android.com/reference/androidx/core/animation/Animator) |||
|   | ↳ | [androidx.core.animation.ValueAnimator](https://developer.android.com/reference/androidx/core/animation/ValueAnimator) ||
|   |   | ↳ | [androidx.core.animation.TimeAnimator](https://developer.android.com/reference/androidx/core/animation/TimeAnimator) |

*** ** * ** ***

This class provides a simple callback mechanism to listeners that is synchronized with all other animators in the system. There is no duration, interpolation, or object value-setting with this Animator. Instead, it is simply started, after which it proceeds to send out events on every animation frame to its TimeListener (if set), with information about this animator, the total elapsed time, and the elapsed time since the previous animation frame.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/core/animation/TimeAnimator.TimeListener` Implementors of this interface can set themselves as update listeners to a `TimeAnimator` instance to receive callbacks on every animation frame to receive the total time since the animator started and the delta time since the last frame. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/animation/TimeAnimator#TimeAnimator()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/core/animation/TimeAnimator#setCurrentPlayTime(long)(long playTime)` Sets the position of the animation to the specified point in time. |
| `void` | `https://developer.android.com/reference/androidx/core/animation/TimeAnimator#setTimeListener(androidx.core.animation.TimeAnimator.TimeListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/animation/TimeAnimator.TimeListener listener)` Sets a listener that is sent update events throughout the life of an animation. |
| `void` | `https://developer.android.com/reference/androidx/core/animation/TimeAnimator#start()()` Starts this animation. |

| ### Inherited Constants |
|---|
| From [androidx.core.animation.Animator](https://developer.android.com/reference/androidx/core/animation/Animator) |---|---| | `static final long` | `https://developer.android.com/reference/androidx/core/animation/Animator#DURATION_INFINITE() = -1` The value used to indicate infinite duration (e.g. when Animators repeat infinitely). | |
| From [androidx.core.animation.ValueAnimator](https://developer.android.com/reference/androidx/core/animation/ValueAnimator) |---|---| | `static final int` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#INFINITE() = -1` This value used used with the `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setRepeatCount(int)` property to repeat the animation indefinitely. | | `static final int` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#RESTART() = 1` When the animation reaches the end and `repeatCount` is INFINITE or a positive value, the animation restarts from the beginning. | | `static final int` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#REVERSE() = 2` When the animation reaches the end and `repeatCount` is INFINITE or a positive value, the animation reverses direction on every iteration. | |

| ### Inherited methods |
|---|
| From [androidx.core.animation.Animator](https://developer.android.com/reference/androidx/core/animation/Animator) |---|---| | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#addListener(androidx.core.animation.Animator.AnimatorListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorListener listener)` Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#addPauseListener(androidx.core.animation.Animator.AnimatorPauseListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorPauseListener listener)` Adds a pause listener to this animator. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#addUpdateListener(androidx.core.animation.Animator.AnimatorUpdateListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorUpdateListener listener)` Adds a listener to the set of listeners that are sent update events through the life of an animation. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator` | `https://developer.android.com/reference/androidx/core/animation/Animator#clone()()` | | `boolean` | `https://developer.android.com/reference/androidx/core/animation/Animator#isPaused()()` Returns whether this animator is currently in a paused state. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#removeAllListeners()()` Removes all `https://developer.android.com/reference/androidx/core/animation/Animator#addListener(androidx.core.animation.Animator.AnimatorListener)` and `https://developer.android.com/reference/androidx/core/animation/Animator#addPauseListener(androidx.core.animation.Animator.AnimatorPauseListener)` from this object. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#removeAllUpdateListeners()()` Removes all listeners from the set listening to frame updates for this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#removeListener(androidx.core.animation.Animator.AnimatorListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorListener listener)` Removes a listener from the set listening to this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#removePauseListener(androidx.core.animation.Animator.AnimatorPauseListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorPauseListener listener)` Removes a pause listener from the set listening to this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#removeUpdateListener(androidx.core.animation.Animator.AnimatorUpdateListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorUpdateListener listener)` Removes a listener from the set listening to frame updates for this animation. | | `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/Animator` | `https://developer.android.com/reference/androidx/core/animation/Animator#setDuration(long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long duration)` Sets the duration of the animation. | | `abstract void` | `https://developer.android.com/reference/androidx/core/animation/Animator#setStartDelay(long)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long startDelay)` The amount of time, in milliseconds, to delay processing the animation after `https://developer.android.com/reference/androidx/core/animation/Animator#start()` is called. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#setTarget(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html target)` Sets the target object whose property will be animated by this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#setupEndValues()()` This method tells the object to use appropriate information to extract ending values for the animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/Animator#setupStartValues()()` This method tells the object to use appropriate information to extract starting values for the animation. | |
| From [androidx.core.animation.ValueAnimator](https://developer.android.com/reference/androidx/core/animation/ValueAnimator) |---|---| | `static boolean` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#areAnimatorsEnabled()()` Returns whether animators are currently enabled, system-wide. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#cancel()()` Cancels the animation. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#clone()()` | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#end()()` Ends the animation. | | `float` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getAnimatedFraction()()` Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getAnimatedValue()()` The most recent value calculated by this `ValueAnimator` when there is just one property being animated. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getAnimatedValue(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html propertyName)` The most recent value calculated by this `ValueAnimator` for `propertyName`. | | `long` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getCurrentPlayTime()()` Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started. | | `long` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getDuration()()` Gets the length of the animation. | | `static long` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getFrameDelay()()` The amount of time, in milliseconds, between each frame of the animation. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/animation/Interpolator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getInterpolator()()` Returns the timing interpolator that this ValueAnimator uses. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getNameForTrace()()` Returns the name of this animator for debugging purposes. | | `int` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getRepeatCount()()` Defines how many times the animation should repeat. | | `int` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getRepeatMode()()` Defines what this animation should do when it reaches the end. | | `long` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getStartDelay()()` The amount of time, in milliseconds, to delay starting the animation after `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#start()` is called. | | `long` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getTotalDuration()()` Gets the total duration of the animation, accounting for animation sequences, start delay, and repeating. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PropertyValuesHolder[]` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#getValues()()` Returns the values that this ValueAnimator animates between. | | `boolean` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#isRunning()()` Returns whether this Animator is currently running (having been started and gone past any initial startDelay period and not yet ended). | | `boolean` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#isStarted()()` Returns whether this Animator has been started and not yet ended. | | `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#ofArgb(int...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html int[] values)` Constructs and returns a ValueAnimator that animates between color values. | | `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#ofFloat(float...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] values)` Constructs and returns a ValueAnimator that animates between float values. | | `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#ofInt(int...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html int[] values)` Constructs and returns a ValueAnimator that animates between int values. | | `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#ofObject(androidx.core.animation.TypeEvaluator,java.lang.Object...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/TypeEvaluator evaluator, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Object[] values)` Constructs and returns a ValueAnimator that animates between Object values. | | `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#ofPropertyValuesHolder(androidx.core.animation.PropertyValuesHolder...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PropertyValuesHolder[] values)` Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#pause()()` Pauses a running animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#resume()()` Resumes a paused animation, causing the animator to pick up where it left off when it was paused. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#reverse()()` Plays the ValueAnimator in reverse. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setCurrentFraction(float)(float fraction)` Sets the position of the animation to the specified fraction. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/ValueAnimator` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setDuration(long)(long duration)` Sets the length of the animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setEvaluator(androidx.core.animation.TypeEvaluator)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/animation/TypeEvaluator value)` The type evaluator to be used when calculating the animated values of this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setFloatValues(float...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html float[] values)` Sets float values that will be animated between. | | `static void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setFrameDelay(long)(long frameDelay)` The amount of time, in milliseconds, between each frame of the animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setIntValues(int...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html int[] values)` Sets int values that will be animated between. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setInterpolator(androidx.core.animation.Interpolator)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/animation/Interpolator value)` The interpolator used in calculating the elapsed fraction of this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setNameForTrace(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html animationName)` Sets a name for the animation to show up in the systrace. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setObjectValues(java.lang.Object...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html Object[] values)` Sets the values to animate between for this animation. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setRepeatCount(int)(int value)` Sets how many times the animation should be repeated. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setRepeatMode(int)(int value)` Defines what this animation should do when it reaches the end. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setStartDelay(long)(long startDelay)` The amount of time, in milliseconds, to delay starting the animation after `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#start()` is called. | | `void` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#setValues(androidx.core.animation.PropertyValuesHolder...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html PropertyValuesHolder[] values)` Sets the values, per property, being animated between. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/animation/ValueAnimator#toString()()` | |

## Public constructors

### TimeAnimator

Added in 1.0.0

```
public TimeAnimator()
```

## Public methods

### setCurrentPlayTime

```
public void setCurrentPlayTime(long playTime)
```

Sets the position of the animation to the specified point in time. This time should be between 0 and the total duration of the animation, including any repetition. If the animation has not yet been started, then it will not advance forward after it is set to this time; it will simply set the time to this value and perform any appropriate actions based on that time. If the animation is already running, then setCurrentPlayTime() will set the current playing time to this value and continue playing from that point.

| Parameters |
|---|---|
| `long playTime` | The time, in milliseconds, to which the animation is advanced or rewound. |

### setTimeListener

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

```
public void setTimeListener(@Nullable TimeAnimator.TimeListener listener)
```

Sets a listener that is sent update events throughout the life of an animation.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/animation/TimeAnimator.TimeListener listener` | the listener to be set. |

### start

```
public void start()
```

Starts this animation. If the animation has a nonzero startDelay, the animation will start running after that delay elapses. A non-delayed animation will have its initial value(s) set immediately, followed by calls to `https://developer.android.com/reference/androidx/core/animation/Animator.AnimatorListener#onAnimationStart(androidx.core.animation.Animator)` for any listeners of this animator.

The animation started by calling this method will be run on the thread that called this method. This thread should have a Looper on it (a runtime exception will be thrown if this is not the case). Also, if the animation will animate properties of objects in the view hierarchy, then the calling thread should be the UI thread for that view hierarchy.