public abstract class Animation extends Object implements Cloneable
animation package
description file
.Modifier and Type | Class and Description |
---|---|
static interface |
Animation.AnimationListener
An animation listener receives notifications from an animation.
|
protected static class |
Animation.Description
Utility class to parse a string description of a size.
|
Modifier and Type | Field and Description |
---|---|
static int |
ABSOLUTE
The specified dimension is an absolute number of pixels.
|
static int |
INFINITE
Repeat the animation indefinitely.
|
static int |
RELATIVE_TO_PARENT
The specified dimension holds a float and should be multiplied by the
height or width of the parent of the object being animated.
|
static int |
RELATIVE_TO_SELF
The specified dimension holds a float and should be multiplied by the
height or width of the object being animated.
|
static int |
RESTART
When the animation reaches the end and the repeat count is INFINTE_REPEAT
or a positive value, the animation restarts from the beginning.
|
static int |
REVERSE
When the animation reaches the end and the repeat count is INFINTE_REPEAT
or a positive value, the animation plays backward (and then forward again).
|
static int |
START_ON_FIRST_FRAME
Can be used as the start time to indicate the start time should be the current
time when
getTransformation(long, Transformation) is invoked for the
first animation frame. |
static int |
ZORDER_BOTTOM
Requests that the content being animated be forced under all other
content for the duration of the animation.
|
static int |
ZORDER_NORMAL
Requests that the content being animated be kept in its current Z
order.
|
static int |
ZORDER_TOP
Requests that the content being animated be forced on top of all other
content for the duration of the animation.
|
Constructor and Description |
---|
Animation()
Creates a new animation with a duration of 0ms, the default interpolator, with
fillBefore set to true and fillAfter set to false
|
Animation(Context context,
AttributeSet attrs)
Creates a new animation whose parameters come from the specified context and
attributes set.
|
Modifier and Type | Method and Description |
---|---|
protected void |
applyTransformation(float interpolatedTime,
Transformation t)
Helper for getTransformation.
|
void |
cancel()
Cancel the animation.
|
protected Animation |
clone()
Creates and returns a copy of this object.
|
long |
computeDurationHint()
Compute a hint at how long the entire animation may last, in milliseconds.
|
void |
detach() |
protected void |
ensureInterpolator()
Gurantees that this animation has an interpolator.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
getBackgroundColor()
Returns the background color behind the animation.
|
boolean |
getDetachWallpaper()
Return value of
setDetachWallpaper(boolean) . |
long |
getDuration()
How long this animation should last
|
boolean |
getFillAfter()
If fillAfter is true, this animation will apply its transformation
after the end time of the animation.
|
boolean |
getFillBefore()
If fillBefore is true, this animation will apply its transformation
before the start time of the animation.
|
Interpolator |
getInterpolator()
Gets the acceleration curve type for this animation.
|
void |
getInvalidateRegion(int left,
int top,
int right,
int bottom,
RectF invalidate,
Transformation transformation) |
int |
getRepeatCount()
Defines how many times the animation should repeat.
|
int |
getRepeatMode()
Defines what this animation should do when it reaches the end.
|
protected float |
getScaleFactor()
The scale factor is set by the call to
getTransformation . |
long |
getStartOffset()
When this animation should start, relative to StartTime
|
long |
getStartTime()
When this animation should start.
|
boolean |
getTransformation(long currentTime,
Transformation outTransformation)
Gets the transformation to apply at a specified point in time.
|
boolean |
getTransformation(long currentTime,
Transformation outTransformation,
float scale)
Gets the transformation to apply at a specified point in time.
|
int |
getZAdjustment()
Returns the Z ordering mode to use while running the animation as
previously set by
setZAdjustment(int) . |
boolean |
hasAlpha()
Return true if this animation changes the view's alpha property.
|
boolean |
hasEnded()
Indicates whether this animation has ended or not.
|
boolean |
hasStarted()
Indicates whether this animation has started or not.
|
void |
initialize(int width,
int height,
int parentWidth,
int parentHeight)
Initialize this animation with the dimensions of the object being
animated as well as the objects parents.
|
void |
initializeInvalidateRegion(int left,
int top,
int right,
int bottom) |
boolean |
isFillEnabled()
If fillEnabled is true, this animation will apply the value of fillBefore.
|
boolean |
isInitialized()
Whether or not the animation has been initialized.
|
void |
reset()
Reset the initialization state of this animation.
|
protected float |
resolveSize(int type,
float value,
int size,
int parentSize)
Convert the information in the description of a size to an actual
dimension
|
void |
restrictDuration(long durationMillis)
Ensure that the duration that this animation will run is not longer
than durationMillis.
|
void |
scaleCurrentDuration(float scale)
How much to scale the duration by.
|
void |
setAnimationListener(Animation.AnimationListener listener)
Binds an animation listener to this animation.
|
void |
setBackgroundColor(int bg)
Set background behind animation.
|
void |
setDetachWallpaper(boolean detachWallpaper)
If detachWallpaper is true, and this is a window animation of a window
that has a wallpaper background, then the window will be detached from
the wallpaper while it runs.
|
void |
setDuration(long durationMillis)
How long this animation should last.
|
void |
setFillAfter(boolean fillAfter)
If fillAfter is true, the transformation that this animation performed
will persist when it is finished.
|
void |
setFillBefore(boolean fillBefore)
If fillBefore is true, this animation will apply its transformation
before the start time of the animation.
|
void |
setFillEnabled(boolean fillEnabled)
If fillEnabled is true, the animation will apply the value of fillBefore.
|
void |
setInterpolator(Context context,
int resID)
Sets the acceleration curve for this animation.
|
void |
setInterpolator(Interpolator i)
Sets the acceleration curve for this animation.
|
void |
setListenerHandler(Handler handler)
Sets the handler used to invoke listeners.
|
void |
setRepeatCount(int repeatCount)
Sets how many times the animation should be repeated.
|
void |
setRepeatMode(int repeatMode)
Defines what this animation should do when it reaches the end.
|
void |
setStartOffset(long startOffset)
When this animation should start relative to the start time.
|
void |
setStartTime(long startTimeMillis)
When this animation should start.
|
void |
setZAdjustment(int zAdjustment)
Set the Z ordering mode to use while running the animation.
|
void |
start()
Convenience method to start the animation the first time
getTransformation(long, Transformation) is invoked. |
void |
startNow()
Convenience method to start the animation at the current time in
milliseconds.
|
boolean |
willChangeBounds()
Indicates whether or not this animation will affect the bounds of the
animated view.
|
boolean |
willChangeTransformationMatrix()
Indicates whether or not this animation will affect the transformation
matrix.
|
public static final int INFINITE
public static final int RESTART
public static final int REVERSE
public static final int START_ON_FIRST_FRAME
getTransformation(long, Transformation)
is invoked for the
first animation frame. This can is useful for short animations.public static final int ABSOLUTE
public static final int RELATIVE_TO_SELF
public static final int RELATIVE_TO_PARENT
public static final int ZORDER_NORMAL
public static final int ZORDER_TOP
public static final int ZORDER_BOTTOM
public Animation()
public Animation(Context context, AttributeSet attrs)
context
- the application environmentattrs
- the set of attributes holding the animation parametersprotected Animation clone() throws CloneNotSupportedException
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
clone
in class Object
CloneNotSupportedException
- if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.Cloneable
public void reset()
initialize(int, int, int, int)
public void cancel()
reset()
before starting the animation again.reset()
,
start()
,
startNow()
public void detach()
public boolean isInitialized()
initialize(int, int, int, int)
public void initialize(int width, int height, int parentWidth, int parentHeight)
Objects that interpret Animations should call this method when
the sizes of the object being animated and its parent are known, and
before calling getTransformation(long, android.view.animation.Transformation)
.
width
- Width of the object being animatedheight
- Height of the object being animatedparentWidth
- Width of the animated object's parentparentHeight
- Height of the animated object's parentpublic void setListenerHandler(Handler handler)
public void setInterpolator(Context context, @AnimRes @InterpolatorRes int resID)
context
- The application environmentresID
- The resource identifier of the interpolator to loadpublic void setInterpolator(Interpolator i)
i
- The interpolator which defines the acceleration curvepublic void setStartOffset(long startOffset)
AnimationSet
where some of the animations components start at different times.startOffset
- When this Animation should start, in milliseconds from
the start time of the root AnimationSet.public void setDuration(long durationMillis)
durationMillis
- Duration in millisecondsIllegalArgumentException
- if the duration is < 0public void restrictDuration(long durationMillis)
durationMillis
- The maximum duration the animation is allowed
to run.public void scaleCurrentDuration(float scale)
scale
- The amount to scale the duration.public void setStartTime(long startTimeMillis)
START_ON_FIRST_FRAME
, the animation will start the first time
getTransformation(long, Transformation)
is invoked. The time passed
to this method should be obtained by calling
AnimationUtils.currentAnimationTimeMillis()
instead of
System.currentTimeMillis()
.startTimeMillis
- the start time in millisecondspublic void start()
getTransformation(long, Transformation)
is invoked.public void startNow()
public void setRepeatMode(int repeatMode)
public void setRepeatCount(int repeatCount)
INFINITE
, the repeat mode will be taken
into account. The repeat count is 0 by default.repeatCount
- the number of times the animation should be repeatedpublic boolean isFillEnabled()
public void setFillEnabled(boolean fillEnabled)
fillEnabled
- true if the animation should take the value of fillBefore into accountsetFillBefore(boolean)
,
setFillAfter(boolean)
public void setFillBefore(boolean fillBefore)
setFillEnabled(boolean)
is not set to true.
Note that this applies when using an AnimationSet
to chain
animations. The transformation is not applied before the AnimationSet
itself starts.fillBefore
- true if the animation should apply its transformation before it startssetFillEnabled(boolean)
public void setFillAfter(boolean fillAfter)
AnimationSet
to chain
animations.fillAfter
- true if the animation should apply its transformation after it endssetFillEnabled(boolean)
public void setZAdjustment(int zAdjustment)
zAdjustment
- The desired mode, one of ZORDER_NORMAL
,
ZORDER_TOP
, or ZORDER_BOTTOM
.public void setBackgroundColor(int bg)
bg
- The background color. If 0, no background. Currently must
be black, with any desired alpha level.protected float getScaleFactor()
getTransformation
. Overrides of
getTransformation(long, Transformation, float)
will get this value
directly. Overrides of applyTransformation(float, Transformation)
can
call this method to get the value.ScaleAnimation
and RotateAnimation
.public void setDetachWallpaper(boolean detachWallpaper)
detachWallpaper
- true if the wallpaper should be detached from the animationpublic Interpolator getInterpolator()
Interpolator
associated to this animationpublic long getStartTime()
START_ON_FIRST_FRAME
.START_ON_FIRST_FRAME
public long getDuration()
public long getStartOffset()
public int getRepeatMode()
public int getRepeatCount()
INFINITE
public boolean getFillBefore()
fillEnabled
is true, the transformation will not be applied until
the start time of the animation.public boolean getFillAfter()
public int getZAdjustment()
setZAdjustment(int)
.ZORDER_NORMAL
,
ZORDER_TOP
, or ZORDER_BOTTOM
.public int getBackgroundColor()
public boolean getDetachWallpaper()
setDetachWallpaper(boolean)
.public boolean willChangeTransformationMatrix()
Indicates whether or not this animation will affect the transformation matrix. For instance, a fade animation will not affect the matrix whereas a scale animation will.
public boolean willChangeBounds()
Indicates whether or not this animation will affect the bounds of the animated view. For instance, a fade animation will not affect the bounds whereas a 200% scale animation will.
public void setAnimationListener(Animation.AnimationListener listener)
Binds an animation listener to this animation. The animation listener is notified of animation events such as the end of the animation or the repetition of the animation.
listener
- the animation listener to be notifiedprotected void ensureInterpolator()
public long computeDurationHint()
public boolean getTransformation(long currentTime, Transformation outTransformation)
currentTime
- Where we are in the animation. This is wall clock time.outTransformation
- A transformation object that is provided by the
caller and will be filled in by the animation.public boolean getTransformation(long currentTime, Transformation outTransformation, float scale)
currentTime
- Where we are in the animation. This is wall clock time.outTransformation
- A transformation object that is provided by the
caller and will be filled in by the animation.scale
- Scaling factor to apply to any inputs to the transform operation, such
pivot points being rotated or scaled around.public boolean hasStarted()
Indicates whether this animation has started or not.
public boolean hasEnded()
Indicates whether this animation has ended or not.
protected void applyTransformation(float interpolatedTime, Transformation t)
interpolatedTime
- The value of the normalized time (0.0 to 1.0)
after it has been run through the interpolation function.t
- The Transformation object to fill in with the current
transforms.protected float resolveSize(int type, float value, int size, int parentSize)
type
- One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or
Animation.RELATIVE_TO_PARENT.value
- The dimension associated with the type parametersize
- The size of the object being animatedparentSize
- The size of the parent of the object being animatedpublic void getInvalidateRegion(int left, int top, int right, int bottom, RectF invalidate, Transformation transformation)
left
- top
- right
- bottom
- invalidate
- transformation
- public void initializeInvalidateRegion(int left, int top, int right, int bottom)
left
- top
- right
- bottom
- protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public boolean hasAlpha()