• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.animation;
17 
18 import java.util.List;
19 
20 /**
21  * This interface abstracts a collection of Keyframe objects and is called by
22  * ValueAnimator to calculate values between those keyframes for a given animation.
23  * @hide
24  */
25 public interface Keyframes extends Cloneable {
26 
27     /**
28      * Sets the TypeEvaluator to be used when calculating animated values. This object
29      * is required only for Keyframes that are not either IntKeyframes or FloatKeyframes,
30      * both of which assume their own evaluator to speed up calculations with those primitive
31      * types.
32      *
33      * @param evaluator The TypeEvaluator to be used to calculate animated values.
34      */
setEvaluator(TypeEvaluator evaluator)35     void setEvaluator(TypeEvaluator evaluator);
36 
37     /**
38      * @return The value type contained by the contained Keyframes.
39      */
getType()40     Class getType();
41 
42     /**
43      * Gets the animated value, given the elapsed fraction of the animation (interpolated by the
44      * animation's interpolator) and the evaluator used to calculate in-between values. This
45      * function maps the input fraction to the appropriate keyframe interval and a fraction
46      * between them and returns the interpolated value. Note that the input fraction may fall
47      * outside the [0-1] bounds, if the animation's interpolator made that happen (e.g., a
48      * spring interpolation that might send the fraction past 1.0). We handle this situation by
49      * just using the two keyframes at the appropriate end when the value is outside those bounds.
50      *
51      * @param fraction The elapsed fraction of the animation
52      * @return The animated value.
53      */
getValue(float fraction)54     Object getValue(float fraction);
55 
56     /**
57      * If subclass has variables that it calculates based on the Keyframes, it should reset them
58      * when this method is called because Keyframe contents might have changed.
59      */
invalidateCache()60     void invalidateCache();
61 
62     /**
63      * @return A list of all Keyframes contained by this. This may return null if this is
64      * not made up of Keyframes.
65      */
getKeyframes()66     List<Keyframe> getKeyframes();
67 
clone()68     Keyframes clone();
69 
70     /**
71      * A specialization of Keyframes that has integer primitive value calculation.
72      */
73     public interface IntKeyframes extends Keyframes {
74 
75         /**
76          * Works like {@link #getValue(float)}, but returning a primitive.
77          * @param fraction The elapsed fraction of the animation
78          * @return The animated value.
79          */
getIntValue(float fraction)80         int getIntValue(float fraction);
81     }
82 
83     /**
84      * A specialization of Keyframes that has float primitive value calculation.
85      */
86     public interface FloatKeyframes extends Keyframes {
87 
88         /**
89          * Works like {@link #getValue(float)}, but returning a primitive.
90          * @param fraction The elapsed fraction of the animation
91          * @return The animated value.
92          */
getFloatValue(float fraction)93         float getFloatValue(float fraction);
94     }
95 }
96