blob: c149bed0d00ebba803d2aa756bfd4740120bf812 [file] [log] [blame]
George Mount984011f2014-08-21 14:28:01 -07001/*
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 */
16package android.animation;
17
Yigit Boyard422dc32014-09-25 12:23:35 -070018import java.util.List;
George Mount984011f2014-08-21 14:28:01 -070019
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 */
24interface Keyframes extends Cloneable {
25
26 /**
27 * Sets the TypeEvaluator to be used when calculating animated values. This object
28 * is required only for Keyframes that are not either IntKeyframes or FloatKeyframes,
29 * both of which assume their own evaluator to speed up calculations with those primitive
30 * types.
31 *
32 * @param evaluator The TypeEvaluator to be used to calculate animated values.
33 */
34 void setEvaluator(TypeEvaluator evaluator);
35
36 /**
37 * @return The value type contained by the contained Keyframes.
38 */
39 Class getType();
40
41 /**
42 * Gets the animated value, given the elapsed fraction of the animation (interpolated by the
43 * animation's interpolator) and the evaluator used to calculate in-between values. This
44 * function maps the input fraction to the appropriate keyframe interval and a fraction
45 * between them and returns the interpolated value. Note that the input fraction may fall
46 * outside the [0-1] bounds, if the animation's interpolator made that happen (e.g., a
47 * spring interpolation that might send the fraction past 1.0). We handle this situation by
48 * just using the two keyframes at the appropriate end when the value is outside those bounds.
49 *
50 * @param fraction The elapsed fraction of the animation
51 * @return The animated value.
52 */
53 Object getValue(float fraction);
54
55 /**
56 * If subclass has variables that it calculates based on the Keyframes, it should reset them
57 * when this method is called because Keyframe contents might have changed.
58 */
59 void invalidateCache();
60
61 /**
62 * @return A list of all Keyframes contained by this. This may return null if this is
63 * not made up of Keyframes.
64 */
Yigit Boyard422dc32014-09-25 12:23:35 -070065 List<Keyframe> getKeyframes();
George Mount984011f2014-08-21 14:28:01 -070066
67 Keyframes clone();
68
69 /**
70 * A specialization of Keyframes that has integer primitive value calculation.
71 */
72 public interface IntKeyframes extends Keyframes {
73
74 /**
75 * Works like {@link #getValue(float)}, but returning a primitive.
76 * @param fraction The elapsed fraction of the animation
77 * @return The animated value.
78 */
79 int getIntValue(float fraction);
80 }
81
82 /**
83 * A specialization of Keyframes that has float primitive value calculation.
84 */
85 public interface FloatKeyframes extends Keyframes {
86
87 /**
88 * Works like {@link #getValue(float)}, but returning a primitive.
89 * @param fraction The elapsed fraction of the animation
90 * @return The animated value.
91 */
92 float getFloatValue(float fraction);
93 }
94}