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 * @return A list of all Keyframes contained by this. This may return null if this is 58 * not made up of Keyframes. 59 */ getKeyframes()60 List<Keyframe> getKeyframes(); 61 clone()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 */ getIntValue(float fraction)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 */ getFloatValue(float fraction)87 float getFloatValue(float fraction); 88 } 89 } 90