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