117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/*
217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Copyright (C) 2010 The Android Open Source Project
317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Licensed under the Apache License, Version 2.0 (the "License");
517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * you may not use this file except in compliance with the License.
617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * You may obtain a copy of the License at
717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *      http://www.apache.org/licenses/LICENSE-2.0
917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
1017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Unless required by applicable law or agreed to in writing, software
1117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * distributed under the License is distributed on an "AS IS" BASIS,
1217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * See the License for the specific language governing permissions and
1417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * limitations under the License.
1517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */
1617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
1717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haasepackage android.animation;
1817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
1917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/**
2017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This evaluator can be used to perform type interpolation between <code>float</code> values.
2117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */
22b39f051631250c49936a475d0e64584afb7f1b93Chet Haasepublic class FloatEvaluator implements TypeEvaluator<Number> {
2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
2417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * This function returns the result of linearly interpolating the start and end values, with
2617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>fraction</code> representing the proportion between the start and end values. The
2717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * calculation is a simple parametric calculation: <code>result = x0 + t * (v1 - v0)</code>,
2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * and <code>t</code> is <code>fraction</code>.
3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
3117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @param fraction   The fraction from the starting to the ending values
3217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @param startValue The start value; should be of type <code>float</code> or
3317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *                   <code>Float</code>
3417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @param endValue   The end value; should be of type <code>float</code> or <code>Float</code>
3517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @return A linear interpolation between the start and end values, given the
3617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *         <code>fraction</code> parameter.
3717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
38b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public Float evaluate(float fraction, Number startValue, Number endValue) {
39b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        float startFloat = startValue.floatValue();
40b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return startFloat + fraction * (endValue.floatValue() - startFloat);
4117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
4217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase}