Chet Haase | 17fb4b0 | 2010-06-28 17:55:07 -0700 | [diff] [blame] | 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>int</code> values. |
| 21 | */ |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 22 | public class IntEvaluator implements TypeEvaluator<Integer> { |
Chet Haase | 17fb4b0 | 2010-06-28 17:55:07 -0700 | [diff] [blame] | 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 |
Laura Davis | b7ffb5f | 2018-06-25 13:05:24 -0700 | [diff] [blame] | 27 | * calculation is a simple parametric calculation: <code>result = x0 + t * (x1 - x0)</code>, |
Chet Haase | 17fb4b0 | 2010-06-28 17:55:07 -0700 | [diff] [blame] | 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>int</code> or |
| 33 | * <code>Integer</code> |
| 34 | * @param endValue The end value; should be of type <code>int</code> or <code>Integer</code> |
| 35 | * @return A linear interpolation between the start and end values, given the |
| 36 | * <code>fraction</code> parameter. |
| 37 | */ |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 38 | public Integer evaluate(float fraction, Integer startValue, Integer endValue) { |
| 39 | int startInt = startValue; |
| 40 | return (int)(startInt + fraction * (endValue - startInt)); |
Chet Haase | 17fb4b0 | 2010-06-28 17:55:07 -0700 | [diff] [blame] | 41 | } |
Laura Davis | b7ffb5f | 2018-06-25 13:05:24 -0700 | [diff] [blame] | 42 | } |