blob: 6666294058e48cbfa69b678fb5638748c7b0c3ef [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.
Jorim Jaggic69bd222016-03-15 14:38:37 +010023 * @hide
George Mount984011f2014-08-21 14:28:01 -070024 */
Jorim Jaggic69bd222016-03-15 14:38:37 +010025public interface Keyframes extends Cloneable {
George Mount984011f2014-08-21 14:28:01 -070026
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 */
35 void setEvaluator(TypeEvaluator evaluator);
36
37 /**
38 * @return The value type contained by the contained Keyframes.
39 */
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 */
54 Object getValue(float fraction);
55
56 /**
George Mount984011f2014-08-21 14:28:01 -070057 * @return A list of all Keyframes contained by this. This may return null if this is
58 * not made up of Keyframes.
59 */
Yigit Boyard422dc32014-09-25 12:23:35 -070060 List<Keyframe> getKeyframes();
George Mount984011f2014-08-21 14:28:01 -070061
62 Keyframes clone();
63
64 /**
65 * A specialization of Keyframes that has integer primitive value calculation.
66 */
67 public interface IntKeyframes extends Keyframes {
68
69 /**
70 * Works like {@link #getValue(float)}, but returning a primitive.
71 * @param fraction The elapsed fraction of the animation
72 * @return The animated value.
73 */
74 int getIntValue(float fraction);
75 }
76
77 /**
78 * A specialization of Keyframes that has float primitive value calculation.
79 */
80 public interface FloatKeyframes extends Keyframes {
81
82 /**
83 * Works like {@link #getValue(float)}, but returning a primitive.
84 * @param fraction The elapsed fraction of the animation
85 * @return The animated value.
86 */
87 float getFloatValue(float fraction);
88 }
89}