blob: 28d496b346f05878572c70d76dc476e5c0140105 [file] [log] [blame]
Chet Haaseb9895022013-04-02 15:10:58 -07001/*
2 * Copyright (C) 2013 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 */
16package android.animation;
17
18import android.graphics.Rect;
19
20/**
Chet Haaseedf6f4b2013-03-26 07:55:30 -070021 * This evaluator can be used to perform type interpolation between <code>Rect</code> values.
Chet Haaseb9895022013-04-02 15:10:58 -070022 */
23public class RectEvaluator implements TypeEvaluator<Rect> {
24
25 /**
26 * This function returns the result of linearly interpolating the start and
27 * end Rect values, with <code>fraction</code> representing the proportion
28 * between the start and end values. The calculation is a simple parametric
29 * calculation on each of the separate components in the Rect objects
30 * (left, top, right, and bottom).
31 *
32 * @param fraction The fraction from the starting to the ending values
33 * @param startValue The start Rect
34 * @param endValue The end Rect
35 * @return A linear interpolation between the start and end values, given the
36 * <code>fraction</code> parameter.
37 */
38 @Override
39 public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
40 return new Rect(startValue.left + (int)((endValue.left - startValue.left) * fraction),
41 startValue.top + (int)((endValue.top - startValue.top) * fraction),
42 startValue.right + (int)((endValue.right - startValue.right) * fraction),
43 startValue.bottom + (int)((endValue.bottom - startValue.bottom) * fraction));
44 }
45}