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
17package android.animation;
18
19/**
20 * This evaluator can be used to perform type interpolation between <code>int</code> values.
21 */
22public class IntEvaluator implements TypeEvaluator<Integer> {
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 * (v1 - v0)</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>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     */
38    public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
39        int startInt = startValue;
40        return (int)(startInt + fraction * (endValue - startInt));
41    }
42}