Fields Summary |
---|
public static final int | INFINITERepeat the animation indefinitely. |
public static final int | RESTARTWhen the animation reaches the end and the repeat count is INFINTE_REPEAT
or a positive value, the animation restarts from the beginning. |
public static final int | REVERSEWhen the animation reaches the end and the repeat count is INFINTE_REPEAT
or a positive value, the animation plays backward (and then forward again). |
public static final int | START_ON_FIRST_FRAMECan be used as the start time to indicate the start time should be the current
time when {@link #getTransformation(long, Transformation)} is invoked for the
first animation frame. This can is useful for short animations. |
public static final int | ABSOLUTEThe specified dimension is an absolute number of pixels. |
public static final int | RELATIVE_TO_SELFThe specified dimension holds a float and should be multiplied by the
height or width of the object being animated. |
public static final int | RELATIVE_TO_PARENTThe specified dimension holds a float and should be multiplied by the
height or width of the parent of the object being animated. |
public static final int | ZORDER_NORMALRequests that the content being animated be kept in its current Z
order. |
public static final int | ZORDER_TOPRequests that the content being animated be forced on top of all other
content for the duration of the animation. |
public static final int | ZORDER_BOTTOMRequests that the content being animated be forced under all other
content for the duration of the animation. |
private static final boolean | USE_CLOSEGUARD |
boolean | mEndedSet by {@link #getTransformation(long, Transformation)} when the animation ends. |
boolean | mStartedSet by {@link #getTransformation(long, Transformation)} when the animation starts. |
boolean | mCycleFlipSet by {@link #getTransformation(long, Transformation)} when the animation repeats
in REVERSE mode. |
boolean | mInitializedThis value must be set to true by {@link #initialize(int, int, int, int)}. It
indicates the animation was successfully initialized and can be played. |
boolean | mFillBeforeIndicates whether the animation transformation should be applied before the
animation starts. The value of this variable is only relevant if mFillEnabled is true;
otherwise it is assumed to be true. |
boolean | mFillAfterIndicates whether the animation transformation should be applied after the
animation ends. |
boolean | mFillEnabledIndicates whether fillBefore should be taken into account. |
long | mStartTimeThe time in milliseconds at which the animation must start; |
long | mStartOffsetThe delay in milliseconds after which the animation must start. When the
start offset is > 0, the start time of the animation is startTime + startOffset. |
long | mDurationThe duration of one animation cycle in milliseconds. |
int | mRepeatCountThe number of times the animation must repeat. By default, an animation repeats
indefinitely. |
int | mRepeatedIndicates how many times the animation was repeated. |
int | mRepeatModeThe behavior of the animation when it repeats. The repeat mode is either
{@link #RESTART} or {@link #REVERSE}. |
Interpolator | mInterpolatorThe interpolator used by the animation to smooth the movement. |
AnimationListener | mListenerThe animation listener to be notified when the animation starts, ends or repeats. |
private int | mZAdjustmentDesired Z order mode during animation. |
private int | mBackgroundColorDesired background color behind animation. |
private float | mScaleFactorscalefactor to apply to pivot points, etc. during animation. Subclasses retrieve the
value via getScaleFactor(). |
private boolean | mDetachWallpaperDon't animate the wallpaper. |
private boolean | mMore |
private boolean | mOneMoreTime |
android.graphics.RectF | mPreviousRegion |
android.graphics.RectF | mRegion |
Transformation | mTransformation |
Transformation | mPreviousTransformation |
private final dalvik.system.CloseGuard | guard |
private android.os.Handler | mListenerHandler |
private Runnable | mOnStart |
private Runnable | mOnRepeat |
private Runnable | mOnEnd |
Methods Summary |
---|
protected void | applyTransformation(float interpolatedTime, Transformation t)Helper for getTransformation. Subclasses should implement this to apply
their transforms given an interpolation value. Implementations of this
method should always replace the specified Transformation or document
they are doing otherwise.
|
public void | cancel()Cancel the animation. Cancelling an animation invokes the animation
listener, if set, to notify the end of the animation.
If you cancel an animation manually, you must call {@link #reset()}
before starting the animation again.
if (mStarted && !mEnded) {
fireAnimationEnd();
mEnded = true;
guard.close();
}
// Make sure we move the animation to the end
mStartTime = Long.MIN_VALUE;
mMore = mOneMoreTime = false;
|
protected android.view.animation.Animation | clone()
final Animation animation = (Animation) super.clone();
animation.mPreviousRegion = new RectF();
animation.mRegion = new RectF();
animation.mTransformation = new Transformation();
animation.mPreviousTransformation = new Transformation();
return animation;
|
public long | computeDurationHint()Compute a hint at how long the entire animation may last, in milliseconds.
Animations can be written to cause themselves to run for a different
duration than what is computed here, but generally this should be
accurate.
return (getStartOffset() + getDuration()) * (getRepeatCount() + 1);
|
public void | detach()
if (mStarted && !mEnded) {
mEnded = true;
guard.close();
fireAnimationEnd();
}
|
protected void | ensureInterpolator()Gurantees that this animation has an interpolator. Will use
a AccelerateDecelerateInterpolator is nothing else was specified.
if (mInterpolator == null) {
mInterpolator = new AccelerateDecelerateInterpolator();
}
|
protected void | finalize()
try {
if (guard != null) {
guard.warnIfOpen();
}
} finally {
super.finalize();
}
|
private void | fireAnimationEnd()
if (mListener != null) {
if (mListenerHandler == null) mListener.onAnimationEnd(this);
else mListenerHandler.postAtFrontOfQueue(mOnEnd);
}
|
private void | fireAnimationRepeat()
if (mListener != null) {
if (mListenerHandler == null) mListener.onAnimationRepeat(this);
else mListenerHandler.postAtFrontOfQueue(mOnRepeat);
}
|
private void | fireAnimationStart()
if (mListener != null) {
if (mListenerHandler == null) mListener.onAnimationStart(this);
else mListenerHandler.postAtFrontOfQueue(mOnStart);
}
|
public int | getBackgroundColor()Returns the background color behind the animation.
return mBackgroundColor;
|
public boolean | getDetachWallpaper()Return value of {@link #setDetachWallpaper(boolean)}.
return mDetachWallpaper;
|
public long | getDuration()How long this animation should last
return mDuration;
|
public boolean | getFillAfter()If fillAfter is true, this animation will apply its transformation
after the end time of the animation.
return mFillAfter;
|
public boolean | getFillBefore()If fillBefore is true, this animation will apply its transformation
before the start time of the animation. If fillBefore is false and
{@link #isFillEnabled() fillEnabled} is true, the transformation will not be applied until
the start time of the animation.
return mFillBefore;
|
public Interpolator | getInterpolator()Gets the acceleration curve type for this animation.
return mInterpolator;
|
public void | getInvalidateRegion(int left, int top, int right, int bottom, android.graphics.RectF invalidate, Transformation transformation)
final RectF tempRegion = mRegion;
final RectF previousRegion = mPreviousRegion;
invalidate.set(left, top, right, bottom);
transformation.getMatrix().mapRect(invalidate);
// Enlarge the invalidate region to account for rounding errors
invalidate.inset(-1.0f, -1.0f);
tempRegion.set(invalidate);
invalidate.union(previousRegion);
previousRegion.set(tempRegion);
final Transformation tempTransformation = mTransformation;
final Transformation previousTransformation = mPreviousTransformation;
tempTransformation.set(transformation);
transformation.set(previousTransformation);
previousTransformation.set(tempTransformation);
|
public int | getRepeatCount()Defines how many times the animation should repeat. The default value
is 0.
return mRepeatCount;
|
public int | getRepeatMode()Defines what this animation should do when it reaches the end.
return mRepeatMode;
|
protected float | getScaleFactor()The scale factor is set by the call to getTransformation . Overrides of
{@link #getTransformation(long, Transformation, float)} will get this value
directly. Overrides of {@link #applyTransformation(float, Transformation)} can
call this method to get the value.
return mScaleFactor;
|
public long | getStartOffset()When this animation should start, relative to StartTime
return mStartOffset;
|
public long | getStartTime()When this animation should start. If the animation has not startet yet,
this method might return {@link #START_ON_FIRST_FRAME}.
return mStartTime;
|
public boolean | getTransformation(long currentTime, Transformation outTransformation)Gets the transformation to apply at a specified point in time. Implementations of this
method should always replace the specified Transformation or document they are doing
otherwise.
if (mStartTime == -1) {
mStartTime = currentTime;
}
final long startOffset = getStartOffset();
final long duration = mDuration;
float normalizedTime;
if (duration != 0) {
normalizedTime = ((float) (currentTime - (mStartTime + startOffset))) /
(float) duration;
} else {
// time is a step-change with a zero duration
normalizedTime = currentTime < mStartTime ? 0.0f : 1.0f;
}
final boolean expired = normalizedTime >= 1.0f;
mMore = !expired;
if (!mFillEnabled) normalizedTime = Math.max(Math.min(normalizedTime, 1.0f), 0.0f);
if ((normalizedTime >= 0.0f || mFillBefore) && (normalizedTime <= 1.0f || mFillAfter)) {
if (!mStarted) {
fireAnimationStart();
mStarted = true;
if (USE_CLOSEGUARD) {
guard.open("cancel or detach or getTransformation");
}
}
if (mFillEnabled) normalizedTime = Math.max(Math.min(normalizedTime, 1.0f), 0.0f);
if (mCycleFlip) {
normalizedTime = 1.0f - normalizedTime;
}
final float interpolatedTime = mInterpolator.getInterpolation(normalizedTime);
applyTransformation(interpolatedTime, outTransformation);
}
if (expired) {
if (mRepeatCount == mRepeated) {
if (!mEnded) {
mEnded = true;
guard.close();
fireAnimationEnd();
}
} else {
if (mRepeatCount > 0) {
mRepeated++;
}
if (mRepeatMode == REVERSE) {
mCycleFlip = !mCycleFlip;
}
mStartTime = -1;
mMore = true;
fireAnimationRepeat();
}
}
if (!mMore && mOneMoreTime) {
mOneMoreTime = false;
return true;
}
return mMore;
|
public boolean | getTransformation(long currentTime, Transformation outTransformation, float scale)Gets the transformation to apply at a specified point in time. Implementations of this
method should always replace the specified Transformation or document they are doing
otherwise.
mScaleFactor = scale;
return getTransformation(currentTime, outTransformation);
|
public int | getZAdjustment()Returns the Z ordering mode to use while running the animation as
previously set by {@link #setZAdjustment}.
return mZAdjustment;
|
public boolean | hasAlpha()Return true if this animation changes the view's alpha property.
return false;
|
public boolean | hasEnded()Indicates whether this animation has ended or not.
return mEnded;
|
public boolean | hasStarted()Indicates whether this animation has started or not.
return mStarted;
|
public 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. (This is to support animation
sizes being specified relative to these dimensions.)
Objects that interpret Animations should call this method when
the sizes of the object being animated and its parent are known, and
before calling {@link #getTransformation}.
reset();
mInitialized = true;
|
public void | initializeInvalidateRegion(int left, int top, int right, int bottom)
final RectF region = mPreviousRegion;
region.set(left, top, right, bottom);
// Enlarge the invalidate region to account for rounding errors
region.inset(-1.0f, -1.0f);
if (mFillBefore) {
final Transformation previousTransformation = mPreviousTransformation;
applyTransformation(mInterpolator.getInterpolation(0.0f), previousTransformation);
}
|
public boolean | isFillEnabled()If fillEnabled is true, this animation will apply the value of fillBefore.
return mFillEnabled;
|
public boolean | isInitialized()Whether or not the animation has been initialized.
return mInitialized;
|
public void | reset()Reset the initialization state of this animation.
mPreviousRegion.setEmpty();
mPreviousTransformation.clear();
mInitialized = false;
mCycleFlip = false;
mRepeated = 0;
mMore = true;
mOneMoreTime = true;
mListenerHandler = null;
|
protected float | resolveSize(int type, float value, int size, int parentSize)Convert the information in the description of a size to an actual
dimension
switch (type) {
case ABSOLUTE:
return value;
case RELATIVE_TO_SELF:
return size * value;
case RELATIVE_TO_PARENT:
return parentSize * value;
default:
return value;
}
|
public void | restrictDuration(long durationMillis)Ensure that the duration that this animation will run is not longer
than durationMillis. In addition to adjusting the duration
itself, this ensures that the repeat count also will not make it run
longer than the given time.
// If we start after the duration, then we just won't run.
if (mStartOffset > durationMillis) {
mStartOffset = durationMillis;
mDuration = 0;
mRepeatCount = 0;
return;
}
long dur = mDuration + mStartOffset;
if (dur > durationMillis) {
mDuration = durationMillis-mStartOffset;
dur = durationMillis;
}
// If the duration is 0 or less, then we won't run.
if (mDuration <= 0) {
mDuration = 0;
mRepeatCount = 0;
return;
}
// Reduce the number of repeats to keep below the maximum duration.
// The comparison between mRepeatCount and duration is to catch
// overflows after multiplying them.
if (mRepeatCount < 0 || mRepeatCount > durationMillis
|| (dur*mRepeatCount) > durationMillis) {
// Figure out how many times to do the animation. Subtract 1 since
// repeat count is the number of times to repeat so 0 runs once.
mRepeatCount = (int)(durationMillis/dur) - 1;
if (mRepeatCount < 0) {
mRepeatCount = 0;
}
}
|
public void | scaleCurrentDuration(float scale)How much to scale the duration by.
mDuration = (long) (mDuration * scale);
mStartOffset = (long) (mStartOffset * scale);
|
public void | setAnimationListener(android.view.animation.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.
mListener = listener;
|
public void | setBackgroundColor(int bg)Set background behind animation.
mBackgroundColor = bg;
|
public 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. That is, the animation will only be applied
to the window, and the wallpaper behind it will remain static.
mDetachWallpaper = detachWallpaper;
|
public void | setDuration(long durationMillis)How long this animation should last. The duration cannot be negative.
if (durationMillis < 0) {
throw new IllegalArgumentException("Animation duration cannot be negative");
}
mDuration = durationMillis;
|
public void | setFillAfter(boolean fillAfter)If fillAfter is true, the transformation that this animation performed
will persist when it is finished. Defaults to false if not set.
Note that this applies to individual animations and when using an {@link
android.view.animation.AnimationSet AnimationSet} to chain
animations.
mFillAfter = fillAfter;
|
public void | setFillBefore(boolean fillBefore)If fillBefore is true, this animation will apply its transformation
before the start time of the animation. Defaults to true if
{@link #setFillEnabled(boolean)} is not set to true.
Note that this applies when using an {@link
android.view.animation.AnimationSet AnimationSet} to chain
animations. The transformation is not applied before the AnimationSet
itself starts.
mFillBefore = fillBefore;
|
public void | setFillEnabled(boolean fillEnabled)If fillEnabled is true, the animation will apply the value of fillBefore.
Otherwise, fillBefore is ignored and the animation
transformation is always applied until the animation ends.
mFillEnabled = fillEnabled;
|
public void | setInterpolator(android.content.Context context, int resID)Sets the acceleration curve for this animation. The interpolator is loaded as
a resource from the specified context.
setInterpolator(AnimationUtils.loadInterpolator(context, resID));
|
public void | setInterpolator(Interpolator i)Sets the acceleration curve for this animation. Defaults to a linear
interpolation.
mInterpolator = i;
|
public void | setListenerHandler(android.os.Handler handler)Sets the handler used to invoke listeners.
if (mListenerHandler == null) {
mOnStart = new Runnable() {
public void run() {
if (mListener != null) {
mListener.onAnimationStart(Animation.this);
}
}
};
mOnRepeat = new Runnable() {
public void run() {
if (mListener != null) {
mListener.onAnimationRepeat(Animation.this);
}
}
};
mOnEnd = new Runnable() {
public void run() {
if (mListener != null) {
mListener.onAnimationEnd(Animation.this);
}
}
};
}
mListenerHandler = handler;
|
public void | setRepeatCount(int repeatCount)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 {@link #INFINITE}, the repeat mode will be taken
into account. The repeat count is 0 by default.
if (repeatCount < 0) {
repeatCount = INFINITE;
}
mRepeatCount = repeatCount;
|
public void | setRepeatMode(int repeatMode)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 {@link #INFINITE}. Defaults to {@link #RESTART}.
mRepeatMode = repeatMode;
|
public void | setStartOffset(long startOffset)When this animation should start relative to the start time. This is most
useful when composing complex animations using an {@link AnimationSet }
where some of the animations components start at different times.
mStartOffset = startOffset;
|
public void | setStartTime(long startTimeMillis)When this animation should start. When the start time is set to
{@link #START_ON_FIRST_FRAME}, the animation will start the first time
{@link #getTransformation(long, Transformation)} is invoked. The time passed
to this method should be obtained by calling
{@link AnimationUtils#currentAnimationTimeMillis()} instead of
{@link System#currentTimeMillis()}.
mStartTime = startTimeMillis;
mStarted = mEnded = false;
mCycleFlip = false;
mRepeated = 0;
mMore = true;
|
public void | setZAdjustment(int zAdjustment)Set the Z ordering mode to use while running the animation.
mZAdjustment = zAdjustment;
|
public void | start()Convenience method to start the animation the first time
{@link #getTransformation(long, Transformation)} is invoked.
setStartTime(-1);
|
public void | startNow()Convenience method to start the animation at the current time in
milliseconds.
setStartTime(AnimationUtils.currentAnimationTimeMillis());
|
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.
// assume we will change the bounds
return true;
|
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.
// assume we will change the matrix
return true;
|