diff options
| author | Chet Haase <chet@google.com> | 2010-07-20 14:00:01 -0700 |
|---|---|---|
| committer | Chet Haase <chet@google.com> | 2010-07-21 08:00:40 -0700 |
| commit | 3dd207a6dbd5d9244dc7fe213d5caa3cddaff0db (patch) | |
| tree | 4e2684e913ee2d081c2a2f894e0a6755da789898 /core/java/android/animation/Keyframe.java | |
| parent | bcfdb32839d1fa4c1c793913d60574674910c042 (diff) | |
Add keyframes to animation framework.
Change-Id: I5c8c8037aeeedae1ce7a18200986caf57264772f
Diffstat (limited to 'core/java/android/animation/Keyframe.java')
| -rw-r--r-- | core/java/android/animation/Keyframe.java | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/core/java/android/animation/Keyframe.java b/core/java/android/animation/Keyframe.java new file mode 100644 index 000000000000..b98994a37440 --- /dev/null +++ b/core/java/android/animation/Keyframe.java @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.animation; + +import android.view.animation.Interpolator; + +/** + * This class represents timea time/value pair for an animation. The Keyframe class is used + * by {@link Animator} to define the values that the animation target will have over the course + * of the animation. As the time proceeds from one keyframe to the other, the value of the + * target object will animate between the value at the previous keyframe and the value at the + * next keyframe. Each keyframe also holds an option {@link android.view.animation.Interpolator} + * object, which defines the time interpolation over the intervalue preceding the keyframe. + */ +public class Keyframe { + /** + * The time at which mValue will hold true. + */ + private float mFraction; + + /** + * The value of the animation at the time mFraction. + */ + private Object mValue; + + /** + * The type of the value in this Keyframe. This type is determined at construction time, + * based on the type of the <code>value</code> object passed into the constructor. + */ + private Class mValueType; + + /** + * The optional time interpolator for the interval preceding this keyframe. A null interpolator + * (the default) results in linear interpolation over the interval. + */ + private Interpolator mInterpolator = null; + + /** + * Private constructor, called from the public constructors with the additional + * <code>valueType</code> parameter. + * + * @param fraction The time, expressed as a value between 0 and 1, representing the fraction + * of time elapsed of the overall animation duration. + * @param value The value that the object will animate to as the animation time approaches + * the time in this keyframe, and the the value animated from as the time passes the time in + * this keyframe. + * @param valueType The type of the <code>value</code> object. This is used by the + * {@link #getValue()} functionm, which is queried by {@link Animator} to determine + * the type of {@link TypeEvaluator} to use to interpolate between values. + */ + private Keyframe(float fraction, Object value, Class valueType) { + mFraction = fraction; + mValue = value; + mValueType = valueType; + } + + /** + * Constructs a Keyframe object with the given time and value. The time defines the + * time, as a proportion of an overall animation's duration, at which the value will hold true + * for the animation. The value for the animation between keyframes will be calculated as + * an interpolation between the values at those keyframes. + * + * @param fraction The time, expressed as a value between 0 and 1, representing the fraction + * of time elapsed of the overall animation duration. + * @param value The value that the object will animate to as the animation time approaches + * the time in this keyframe, and the the value animated from as the time passes the time in + * this keyframe. + */ + public Keyframe(float fraction, Object value) { + this(fraction, value, Object.class); + } + + /** + * Constructs a Keyframe object with the given time and integer value. The time defines the + * time, as a proportion of an overall animation's duration, at which the value will hold true + * for the animation. The value for the animation between keyframes will be calculated as + * an interpolation between the values at those keyframes. + * + * @param fraction The time, expressed as a value between 0 and 1, representing the fraction + * of time elapsed of the overall animation duration. + * @param value The value that the object will animate to as the animation time approaches + * the time in this keyframe, and the the value animated from as the time passes the time in + * this keyframe. + */ + public Keyframe(float fraction, int value) { + this(fraction, value, int.class); + } + + /** + * Constructs a Keyframe object with the given time and float value. The time defines the + * time, as a proportion of an overall animation's duration, at which the value will hold true + * for the animation. The value for the animation between keyframes will be calculated as + * an interpolation between the values at those keyframes. + * + * @param fraction The time, expressed as a value between 0 and 1, representing the fraction + * of time elapsed of the overall animation duration. + * @param value The value that the object will animate to as the animation time approaches + * the time in this keyframe, and the the value animated from as the time passes the time in + * this keyframe. + */ + public Keyframe(float fraction, float value) { + this(fraction, value, float.class); + } + + /** + * Constructs a Keyframe object with the given time and double value. The time defines the + * time, as a proportion of an overall animation's duration, at which the value will hold true + * for the animation. The value for the animation between keyframes will be calculated as + * an interpolation between the values at those keyframes. + * + * @param fraction The time, expressed as a value between 0 and 1, representing the fraction + * of time elapsed of the overall animation duration. + * @param value The value that the object will animate to as the animation time approaches + * the time in this keyframe, and the the value animated from as the time passes the time in + * this keyframe. + */ + public Keyframe(float fraction, double value) { + this(fraction, value, double.class); + } + + /** + * Gets the value for this Keyframe. + * + * @return The value for this Keyframe. + */ + public Object getValue() { + return mValue; + } + + /** + * Gets the time for this keyframe, as a fraction of the overall animation duration. + * + * @return The time associated with this keyframe, as a fraction of the overall animation + * duration. This should be a value between 0 and 1. + */ + public float getFraction() { + return mFraction; + } + + /** + * Gets the optional interpolator for this Keyframe. A value of <code>null</code> indicates + * that there is no interpolation, which is the same as linear interpolation. + * + * @return The optional interpolator for this Keyframe. + */ + public Interpolator getInterpolator() { + return mInterpolator; + } + + /** + * Sets the optional interpolator for this Keyframe. A value of <code>null</code> indicates + * that there is no interpolation, which is the same as linear interpolation. + * + * @return The optional interpolator for this Keyframe. + */ + public void setInterpolator(Interpolator interpolator) { + mInterpolator = interpolator; + } + + /** + * Gets the type of keyframe. This information is used by Animator to determine the type of + * {@linke TypeEvaluator} to use when calculating values between keyframes. The type is based + * on the type of Keyframe created. For example, {@link IntKeyframe} returns a value of + * <code>int.class</code>. This superclass returns a value of <code>Object.class</code>. + * + * @return The type of the value stored in the Keyframe. + */ + public Class getType() { + return mValueType; + } +} |
