public abstract class ALcdAnimation extends Object implements ILcdAnimation
ILcdView
based animations.
It has only one abstract method: setTimeImpl(double)
for updating the animation.
To customize the timing of the animation, you can supply an
Interpolator
.
Additionally, you can override isLoop()
to implement looping animations, and
override the empty start()
, stop()
, and restart()
implementations
to do additional bookkeeping and cleanup, such as handling a canceled animation.
You can supply any number of
ILcdView
objects at construction time. ALcdAnimation
makes sure
to invalidate them when setTime(double)
is invoked.Modifier and Type | Class and Description |
---|---|
static interface |
ALcdAnimation.Interpolator
Implementations of this interface transform the relative progress of the animation
(between 0 and 1 with respect to the animation's duration).
|
Modifier | Constructor and Description |
---|---|
protected |
ALcdAnimation(double aDuration,
ILcdView... aView)
Creates a new animation with the given duration.
|
protected |
ALcdAnimation(ILcdView... aView)
Creates a new animation of one second.
|
Modifier and Type | Method and Description |
---|---|
double |
getDuration()
Returns the duration of this animation in seconds.
|
ALcdAnimation.Interpolator |
getInterpolator()
Returns the
ALcdAnimation.Interpolator of this ALcdAnimation . |
protected static double |
interpolate(double aStart,
double aTarget,
double aFraction)
Interpolates linearly between the two given values.
|
boolean |
isLoop()
If true,
ALcdAnimationManager will play this animation repeatedly
until it is explicitly terminated. |
void |
restart()
Called by
ALcdAnimationManager when this animation is looped and needs to
start a new loop. |
void |
setInterpolator(ALcdAnimation.Interpolator aInterpolator)
Updates the interpolator of this
ALcdAnimation . |
void |
setTime(double aTime)
Updates the animation in function of the time elapsed since its start.
|
protected abstract void |
setTimeImpl(double aTime)
Performs the actual updates that are necessary to progress the animation to the given
time.
|
void |
start()
Called by
ALcdAnimationManager when this animation is added
to the manager and needs to starts playing. |
void |
stop()
Called by
ALcdAnimationManager when this animation is removed from
the manager and needs to stops playing. |
protected ALcdAnimation(ILcdView... aView)
setTime(double)
is called. By default the ALcdAnimation.Interpolator
of the new
ALcdAnimation
instance is set to ALcdAnimation.Interpolator.LINEAR
.aView
- the given views.protected ALcdAnimation(double aDuration, ILcdView... aView)
setTime(double)
is called. By default the ALcdAnimation.Interpolator
of the new
ALcdAnimation
instance is set to ALcdAnimation.Interpolator.LINEAR
.aDuration
- the duration of the animation (in seconds)aView
- the given views.public ALcdAnimation.Interpolator getInterpolator()
ALcdAnimation.Interpolator
of this ALcdAnimation
.ALcdAnimation.Interpolator
of this ALcdAnimation
public void setInterpolator(ALcdAnimation.Interpolator aInterpolator)
ALcdAnimation
.aInterpolator
- the new interpolator for this ALcdAnimation
.IllegalArgumentException
- when aInterpolator
equals null.public final void setTime(double aTime)
setTimeImpl(double)
to perform the
actual update of the animation.
All ILcdView
objects provided at construction time are invalidated.setTime
in interface ILcdAnimation
aTime
- the duration (in seconds) for which the animation has been runningprotected abstract void setTimeImpl(double aTime)
aTime
- the duration (in seconds) for which the animation has been runningprotected static double interpolate(double aStart, double aTarget, double aFraction)
aStart
- the first valueaTarget
- the second valueaFraction
- the difference between the first value and the interpolated value
relative to the difference between the first and the second valuepublic double getDuration()
ILcdAnimation
getDuration
in interface ILcdAnimation
public boolean isLoop()
ILcdAnimation
ALcdAnimationManager
will play this animation repeatedly
until it is explicitly terminated. Each successive playback will be
surrounded with a call to ILcdAnimation.start()
and ILcdAnimation.stop()
.isLoop
in interface ILcdAnimation
public void restart()
ILcdAnimation
ALcdAnimationManager
when this animation is looped and needs to
start a new loop.restart
in interface ILcdAnimation
public void start()
ILcdAnimation
ALcdAnimationManager
when this animation is added
to the manager and needs to starts playing.start
in interface ILcdAnimation
public void stop()
ILcdAnimation
ALcdAnimationManager
when this animation is removed from
the manager and needs to stops playing.stop
in interface ILcdAnimation