1 /*
2  * Copyright (C) 2016 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 package com.android.systemui.shared.recents.utilities;
17 
18 import android.animation.TypeEvaluator;
19 import android.graphics.RectF;
20 
21 /**
22  * This evaluator can be used to perform type interpolation between <code>RectF</code> values.
23  */
24 public class RectFEvaluator implements TypeEvaluator<RectF> {
25 
26     private final RectF mRect = new RectF();
27 
28     /**
29      * This function returns the result of linearly interpolating the start and
30      * end Rect values, with <code>fraction</code> representing the proportion
31      * between the start and end values. The calculation is a simple parametric
32      * calculation on each of the separate components in the Rect objects
33      * (left, top, right, and bottom).
34      *
35      * <p>The object returned will be the <code>reuseRect</code> passed into the constructor.</p>
36      *
37      * @param fraction   The fraction from the starting to the ending values
38      * @param startValue The start Rect
39      * @param endValue   The end Rect
40      * @return A linear interpolation between the start and end values, given the
41      *         <code>fraction</code> parameter.
42      */
43     @Override
evaluate(float fraction, RectF startValue, RectF endValue)44     public RectF evaluate(float fraction, RectF startValue, RectF endValue) {
45         float left = startValue.left + ((endValue.left - startValue.left) * fraction);
46         float top = startValue.top + ((endValue.top - startValue.top) * fraction);
47         float right = startValue.right + ((endValue.right - startValue.right) * fraction);
48         float bottom = startValue.bottom + ((endValue.bottom - startValue.bottom) * fraction);
49         mRect.set(left, top, right, bottom);
50         return mRect;
51     }
52 }
53