Added in API level 16

TimeAnimator


open class TimeAnimator : ValueAnimator

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 classes
abstract

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.

Inherited constants
Long DURATION_INFINITE

The value used to indicate infinite duration (e.g. when Animators repeat infinitely).

Int INFINITE

This value used used with the setRepeatCount(int) property to repeat the animation indefinitely.

Int RESTART

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

Int REVERSE

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

Public constructors

Public methods
open Unit

open Unit

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

open Unit

Inherited functions
Unit addListener(listener: Animator.AnimatorListener!)

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Unit addPauseListener(listener: Animator.AnimatorPauseListener!)

Adds a pause listener to this animator.

ArrayList<Animator.AnimatorListener!>! getListeners()

Gets the set of android.animation.Animator.AnimatorListener objects that are currently listening for events on this Animator object.

Boolean isPaused()

Returns whether this animator is currently in a paused state.

Unit removeAllListeners()

Removes all listeners and pauseListeners from this object.

Unit removeListener(listener: Animator.AnimatorListener!)

Removes a listener from the set listening to this animation.

Unit removePauseListener(listener: Animator.AnimatorPauseListener!)

Removes a pause listener from the set listening to this animation.

Unit setTarget(target: Any?)

Sets the target object whose property will be animated by this animation. Not all subclasses operate on target objects (for example, ValueAnimator, but this method is on the superclass for the convenience of dealing generically with those subclasses that do handle targets.

Note: The target is stored as a weak reference internally to avoid leaking resources by having animators directly reference old targets. Therefore, you should ensure that animator targets always have a hard reference elsewhere.

Unit setupEndValues()

This method tells the object to use appropriate information to extract ending values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.

Unit setupStartValues()

This method tells the object to use appropriate information to extract starting values for the animation. For example, a AnimatorSet object will pass this call to its child objects to tell them to set up the values. A ObjectAnimator object will use the information it has about its target object and PropertyValuesHolder objects to get the start values for its properties. A ValueAnimator object will ignore the request since it does not have enough information (such as a target object) to gather these values.

Unit addUpdateListener(listener: ValueAnimator.AnimatorUpdateListener!)

Adds a listener to the set of listeners that are sent update events through the life of an animation. This method is called on all listeners for every frame of the animation, after the values for the animation have been calculated.

Boolean areAnimatorsEnabled()

Returns whether animators are currently enabled, system-wide. By default, all animators are enabled. This can change if either the user sets a Developer Option to set the animator duration scale to 0 or by Battery Savery mode being enabled (which disables all animations).

Developers should not typically need to call this method, but should an app wish to show a different experience when animators are disabled, this return value can be used as a decider of which experience to offer.

Unit cancel()

ValueAnimator clone()

Unit end()

Float getAnimatedFraction()

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

Any! getAnimatedValue()

The most recent value calculated by this ValueAnimator when there is just one property being animated. This value is only sensible while the animation is running. The main purpose for this read-only property is to retrieve the value from the ValueAnimator during a call to AnimatorUpdateListener.onAnimationUpdate(ValueAnimator), which is called during each animation frame, immediately after the value is calculated.

Any! getAnimatedValue(propertyName: String!)

The most recent value calculated by this ValueAnimator for propertyName. The main purpose for this read-only property is to retrieve the value from the ValueAnimator during a call to AnimatorUpdateListener.onAnimationUpdate(ValueAnimator), which is called during each animation frame, immediately after the value is calculated.

Long getCurrentPlayTime()

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started. An animation that is not yet started will return a value of zero, unless the animation has has its play time set via setCurrentPlayTime(long) or setCurrentFraction(float), in which case it will return the time that was set.

Long getDuration()

Gets the length of the animation. The default duration is 300 milliseconds.

Float getDurationScale()

Returns the system-wide scaling factor for Animator-based animations. This affects both the start delay and duration of all such animations. Setting to 0 will cause animations to end immediately. The default value is 1.0f.

Long getFrameDelay()

The amount of time, in milliseconds, between each frame of the animation. This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop. The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations. Note that this method should be called from the same thread that start() is called in order to check the frame delay for that animation. A runtime exception will be thrown if the calling thread does not have a Looper.

TimeInterpolator! getInterpolator()

Returns the timing interpolator that this ValueAnimator uses.

Int getRepeatCount()

Defines how many times the animation should repeat. The default value is 0.

Int getRepeatMode()

Defines what this animation should do when it reaches the end.

Long getStartDelay()

The amount of time, in milliseconds, to delay starting the animation after start() is called.

Long getTotalDuration()

Array<PropertyValuesHolder!>! getValues()

Returns the values that this ValueAnimator animates between. These values are stored in PropertyValuesHolder objects, even if the ValueAnimator was created with a simple list of value objects instead.

Boolean isRunning()

Boolean isStarted()

ValueAnimator! ofArgb(vararg values: Int)

Constructs and returns a ValueAnimator that animates between color values. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

ValueAnimator! ofFloat(vararg values: Float)

Constructs and returns a ValueAnimator that animates between float values. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

ValueAnimator! ofInt(vararg values: Int)

Constructs and returns a ValueAnimator that animates between int values. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

ValueAnimator! ofObject(evaluator: TypeEvaluator<Any!>!, vararg values: Any!)

Constructs and returns a ValueAnimator that animates between Object values. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

Note: The Object values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.

Since ValueAnimator does not know how to animate between arbitrary Objects, this factory method also takes a TypeEvaluator object that the ValueAnimator will use to perform that interpolation.

ValueAnimator! ofPropertyValuesHolder(vararg values: PropertyValuesHolder!)

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

Unit pause()

Boolean registerDurationScaleChangeListener(listener: ValueAnimator.DurationScaleChangeListener)

Registers a DurationScaleChangeListener This listens for changes to the system-wide scaling factor for Animator-based animations. Listeners will be called on the main thread.

Unit removeAllUpdateListeners()

Removes all listeners from the set listening to frame updates for this animation.

Unit removeUpdateListener(listener: ValueAnimator.AnimatorUpdateListener!)

Removes a listener from the set listening to frame updates for this animation.

Unit resume()

Unit reverse()

Plays the ValueAnimator in reverse. If the animation is already running, it will stop itself and play backwards from the point reached when reverse was called. If the animation is not currently running, then it will start from the end and play backwards. This behavior is only set for the current animation; future playing of the animation will use the default behavior of playing forward.

Unit setCurrentFraction(fraction: Float)

Sets the position of the animation to the specified fraction. This fraction should be between 0 and the total fraction of the animation, including any repetition. That is, a fraction of 0 will position the animation at the beginning, a value of 1 at the end, and a value of 2 at the end of a reversing animator that repeats once. If the animation has not yet been started, then it will not advance forward after it is set to this fraction; it will simply set the fraction to this value and perform any appropriate actions based on that fraction. If the animation is already running, then setCurrentFraction() will set the current fraction to this value and continue playing from that point. Animator.AnimatorListener events are not called due to changing the fraction; those events are only processed while the animation is running.

ValueAnimator! setDuration(duration: Long)

Sets the length of the animation. The default duration is 300 milliseconds.

Unit setEvaluator(value: TypeEvaluator<Any!>!)

The type evaluator to be used when calculating the animated values of this animation. The system will automatically assign a float or int evaluator based on the type of startValue and endValue in the constructor. But if these values are not one of these primitive types, or if different evaluation is desired (such as is necessary with int values that represent colors), a custom evaluator needs to be assigned. For example, when running an animation on color values, the ArgbEvaluator should be used to get correct RGB color interpolation.

If this ValueAnimator has only one set of values being animated between, this evaluator will be used for that set. If there are several sets of values being animated, which is the case if PropertyValuesHolder objects were set on the ValueAnimator, then the evaluator is assigned just to the first PropertyValuesHolder object.

Unit setFloatValues(vararg values: Float)

Sets float values that will be animated between. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.

Unit setFrameDelay(frameDelay: Long)

The amount of time, in milliseconds, between each frame of the animation. This is a requested time that the animation will attempt to honor, but the actual delay between frames may be different, depending on system load and capabilities. This is a static function because the same delay will be applied to all animations, since they are all run off of a single timing loop. The frame delay may be ignored when the animation system uses an external timing source, such as the display refresh rate (vsync), to govern animations. Note that this method should be called from the same thread that start() is called in order to have the new frame delay take effect on that animation. A runtime exception will be thrown if the calling thread does not have a Looper.

Unit setIntValues(vararg values: Int)

Sets int values that will be animated between. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.

Unit setInterpolator(value: TimeInterpolator!)

The time interpolator used in calculating the elapsed fraction of this animation. The interpolator determines whether the animation runs with linear or non-linear motion, such as acceleration and deceleration. The default value is android.view.animation.AccelerateDecelerateInterpolator

Unit setObjectValues(vararg values: Any!)

Sets the values to animate between for this animation. A single value implies that that value is the one being animated to. However, this is not typically useful in a ValueAnimator object because there is no way for the object to determine the starting value for the animation (unlike ObjectAnimator, which can derive that value from the target object and property being animated). Therefore, there should typically be two or more values.

Note: The Object values are stored as references to the original objects, which means that changes to those objects after this method is called will affect the values on the animator. If the objects will be mutated externally after this method is called, callers should pass a copy of those objects instead.

If there are already multiple sets of values defined for this ValueAnimator via more than one PropertyValuesHolder object, this method will set the values for the first of those objects.

There should be a TypeEvaluator set on the ValueAnimator that knows how to interpolate between these value objects. ValueAnimator only knows how to interpolate between the primitive types specified in the other setValues() methods.

Unit setRepeatCount(value: Int)

Sets how many times the animation should be repeated. If the repeat count is 0, the animation is never repeated. If the repeat count is greater than 0 or INFINITE, the repeat mode will be taken into account. The repeat count is 0 by default.

Unit setRepeatMode(value: Int)

Defines what this animation should do when it reaches the end. This setting is applied only when the repeat count is either greater than 0 or INFINITE. Defaults to RESTART.

Unit setStartDelay(startDelay: Long)

The amount of time, in milliseconds, to delay starting the animation after start() is called. Note that the start delay should always be non-negative. Any negative start delay will be clamped to 0 on N and above.

Unit setValues(vararg values: PropertyValuesHolder!)

Sets the values, per property, being animated between. This function is called internally by the constructors of ValueAnimator that take a list of values. But a ValueAnimator can be constructed without values and this method can be called to set the values manually instead.

String toString()

Boolean unregisterDurationScaleChangeListener(listener: ValueAnimator.DurationScaleChangeListener)

Unregisters a DurationScaleChangeListener.

Public constructors

TimeAnimator

TimeAnimator()

Public methods

setCurrentPlayTime

Added in API level 16
open fun setCurrentPlayTime(playTime: Long): Unit
Parameters
playTime Long: The time, in milliseconds, to which the animation is advanced or rewound.

setTimeListener

Added in API level 16
open fun setTimeListener(listener: TimeAnimator.TimeListener!): Unit

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

Parameters
listener TimeAnimator.TimeListener!: the listener to be set.

start

Added in API level 16
open fun start(): Unit