1 /* 2 * Copyright (C) 2010 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 17 package android.animation; 18 19 /** 20 * This evaluator can be used to perform type interpolation between <code>float</code> values. 21 */ 22 public class FloatEvaluator implements TypeEvaluator<Number> { 23 24 /** 25 * This function returns the result of linearly interpolating the start and end values, with 26 * <code>fraction</code> representing the proportion between the start and end values. The 27 * calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>, 28 * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>, 29 * and <code>t</code> is <code>fraction</code>. 30 * 31 * @param fraction The fraction from the starting to the ending values 32 * @param startValue The start value; should be of type <code>float</code> or 33 * <code>Float</code> 34 * @param endValue The end value; should be of type <code>float</code> or <code>Float</code> 35 * @return A linear interpolation between the start and end values, given the 36 * <code>fraction</code> parameter. 37 */ evaluate(float fraction, Number startValue, Number endValue)38 public Float evaluate(float fraction, Number startValue, Number endValue) { 39 float startFloat = startValue.floatValue(); 40 return startFloat + fraction * (endValue.floatValue() - startFloat); 41 } 42 }