1984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount/*
2984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * Copyright (C) 2014 The Android Open Source Project
3984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount *
4984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * Licensed under the Apache License, Version 2.0 (the "License");
5984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * you may not use this file except in compliance with the License.
6984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * You may obtain a copy of the License at
7984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount *
8984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount *      http://www.apache.org/licenses/LICENSE-2.0
9984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount *
10984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * Unless required by applicable law or agreed to in writing, software
11984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * distributed under the License is distributed on an "AS IS" BASIS,
12984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * See the License for the specific language governing permissions and
14984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * limitations under the License.
15984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount */
16984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mountpackage android.animation;
17984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
18d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport java.util.List;
19984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
20984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount/**
21984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * This interface abstracts a collection of Keyframe objects and is called by
22984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount * ValueAnimator to calculate values between those keyframes for a given animation.
23c69bd2246f4ec5000591fdc381f84cd90be85b7fJorim Jaggi * @hide
24984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount */
25c69bd2246f4ec5000591fdc381f84cd90be85b7fJorim Jaggipublic interface Keyframes extends Cloneable {
26984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
27984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
28984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * Sets the TypeEvaluator to be used when calculating animated values. This object
29984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * is required only for Keyframes that are not either IntKeyframes or FloatKeyframes,
30984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * both of which assume their own evaluator to speed up calculations with those primitive
31984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * types.
32984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     *
33984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * @param evaluator The TypeEvaluator to be used to calculate animated values.
34984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
35984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    void setEvaluator(TypeEvaluator evaluator);
36984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
37984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
38984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * @return The value type contained by the contained Keyframes.
39984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
40984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    Class getType();
41984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
42984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
43984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * Gets the animated value, given the elapsed fraction of the animation (interpolated by the
44984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * animation's interpolator) and the evaluator used to calculate in-between values. This
45984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * function maps the input fraction to the appropriate keyframe interval and a fraction
46984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * between them and returns the interpolated value. Note that the input fraction may fall
47984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * outside the [0-1] bounds, if the animation's interpolator made that happen (e.g., a
48984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * spring interpolation that might send the fraction past 1.0). We handle this situation by
49984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * just using the two keyframes at the appropriate end when the value is outside those bounds.
50984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     *
51984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * @param fraction The elapsed fraction of the animation
52984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * @return The animated value.
53984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
54984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    Object getValue(float fraction);
55984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
56984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
57984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * If subclass has variables that it calculates based on the Keyframes, it should reset them
58984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * when this method is called because Keyframe contents might have changed.
59984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
60984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    void invalidateCache();
61984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
62984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
63984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * @return A list of all Keyframes contained by this. This may return null if this is
64984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * not made up of Keyframes.
65984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
66d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    List<Keyframe> getKeyframes();
67984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
68984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    Keyframes clone();
69984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
70984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
71984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * A specialization of Keyframes that has integer primitive value calculation.
72984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
73984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    public interface IntKeyframes extends Keyframes {
74984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
75984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount        /**
76984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * Works like {@link #getValue(float)}, but returning a primitive.
77984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * @param fraction The elapsed fraction of the animation
78984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * @return The animated value.
79984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         */
80984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount        int getIntValue(float fraction);
81984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    }
82984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
83984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    /**
84984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     * A specialization of Keyframes that has float primitive value calculation.
85984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount     */
86984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    public interface FloatKeyframes extends Keyframes {
87984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount
88984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount        /**
89984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * Works like {@link #getValue(float)}, but returning a primitive.
90984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * @param fraction The elapsed fraction of the animation
91984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         * @return The animated value.
92984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount         */
93984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount        float getFloatValue(float fraction);
94984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount    }
95984011f6850fd4b6ad4db6d6022bd475d7a2c712George Mount}
96