public class

Animation

extends Object
java.lang.Object
   ↳ com.shinobicontrols.charts.Animation<T>
Known Direct Subclasses

Class Overview

Provides a flexible means of animating arbitrary properties. Through the use of appropriate Animation.Listeners, other objects can react to changes in the animated property accordingly.

Animations are not tied to being time-based. Instead, they work on a general concept of progress through the Animation. This opens up the possibility of using alternative means to run the Animation, for example, the position of a android.widget.SeekBar or the current range of an Axis. That said, Animations can still be run over a set time period by using the AnimationRunner.

An AnimationCurve defines the proportion of the animated property for a given progress value. Therefore, as the Animation's progress changes the proportion of the animated property changes according to the specific AnimationCurve implementation.

It is the job of the Evaluator to map a proportion to an actual value. How it does this is dependent on the Evaluator implementation; we provide a FloatEvaluator and DoubleEvaluator which both take a startValue and an endValue and use linear interpolation to find a value based on the proportion. It is of course possible to create custom Evaluators for any type of property.

Summary

Nested Classes
interface Animation.Listener<T> Provides a means of being informed about changes to the progress value of an Animation
Public Constructors
Animation(AnimationCurve animationCurve, Evaluator<T> evaluator)
Constructs a new Animation with the given Evaluator and AnimationCurve.
Public Methods
void addListener(Listener<T> listener)
Adds an Animation.Listener to this Animation.
T getAnimatedValue()
Returns the value of the property being animated at the current progress for this Animation.
float getDuration()
This method is deprecated. as of version 1.10.0, duration is now set on the AnimationRunner during construction, see AnimationRunner#AnimationRunner(Animation, float, boolean)
float getProgress()
Returns the current progress for this Animation.
void notifyInitiated()
Calls the onInitiated(Animation) method on any Animation.Listener which has been added to this Animation.
void notifyTerminatedWithProgressOne()
Calls the onTerminatedWithProgressOne(Animation) method on any Animation.Listener which has been added to this Animation.
void notifyTerminatedWithProgressZero()
Calls the onTerminatedWithProgressZero(Animation) method on any Animation.Listener which has been added to this Animation.
void removeListener(Listener<T> listener)
Removes the given Animation.Listener from this Animation.
void setDuration(float duration)
This method is deprecated. as of version 1.10.0, duration is now set on the AnimationRunner during construction, see AnimationRunner#AnimationRunner(Animation, float, boolean)
void setProgress(float progress)
Sets the current progress of this Animation.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Animation (AnimationCurve animationCurve, Evaluator<T> evaluator)

Constructs a new Animation with the given Evaluator and AnimationCurve.

Parameters
animationCurve the AnimationCurve that defines the proportion of the animated property based on progress
evaluator the Evaluator that maps a proportion of an animated property to an actual value

Public Methods

public void addListener (Listener<T> listener)

Adds an Animation.Listener to this Animation. Must not be null. Animation.Listeners can be used to update objects when the animated property changes.

Parameters
listener the Animation.Listener to add to this Animation

public T getAnimatedValue ()

Returns the value of the property being animated at the current progress for this Animation. The animated value will be determined by the AnimationCurve and the Evaluator given to the Animation upon creation.

Generally this method is called from inside the methods of the Animation.Listener to obtain the latest animated value for an object's property, allowing the object to be updated accordingly.

Returns
  • the value of the animated property at the current progress for this Animation

public float getDuration ()

This method is deprecated.
as of version 1.10.0, duration is now set on the AnimationRunner during construction, see AnimationRunner#AnimationRunner(Animation, float, boolean)

Gets the duration, in seconds.

Returns
  • the duration, in seconds
See Also

public float getProgress ()

Returns the current progress for this Animation. This is a measure of the current position in the Animation and is a value in the range of 0.0 to 1.0. A progress value of 0.0 represents the point at the beginning of the Animation's AnimationCurve. A progress value of 1.0 represents the point at the end of the Animation's AnimationCurve.

A progress value less than 0.0 will be coerced to 0.0. Similarly, a progress value greater than 1.0 will be coerced to 1.0.

When the progress value is updated each Animation.Listener held by this Animation is informed of the change via the onProgressChanged(Animation) method.

Returns

public void notifyInitiated ()

Calls the onInitiated(Animation) method on any Animation.Listener which has been added to this Animation.

public void notifyTerminatedWithProgressOne ()

Calls the onTerminatedWithProgressOne(Animation) method on any Animation.Listener which has been added to this Animation.

public void notifyTerminatedWithProgressZero ()

Calls the onTerminatedWithProgressZero(Animation) method on any Animation.Listener which has been added to this Animation.

public void removeListener (Listener<T> listener)

Removes the given Animation.Listener from this Animation.

Parameters
listener the Animation.Listener to remove from this Animation

public void setDuration (float duration)

This method is deprecated.
as of version 1.10.0, duration is now set on the AnimationRunner during construction, see AnimationRunner#AnimationRunner(Animation, float, boolean)

Sets the duration, in seconds.

Parameters
duration the duration to set, in seconds
See Also

public void setProgress (float progress)

Sets the current progress of this Animation. This is a measure of the current position in the Animation and is a value in the range of 0.0 to 1.0. A progress value of 0.0 represents the point at the beginning of the Animation's AnimationCurve. A progress value of 1.0 represents the point at the end of the Animation's AnimationCurve.

A progress value less than 0.0 will be coerced to 0.0. Similarly, a progress value greater than 1.0 will be coerced to 1.0.

When the progress value is updated each Animation.Listener held by this Animation is informed of the change via the onProgressChanged(Animation) method.

Parameters
progress the progress to set for this Animation
See Also