1b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase/* 2b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * Copyright (C) 2013 The Android Open Source Project 3b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * 4b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * Licensed under the Apache License, Version 2.0 (the "License"); 5b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * you may not use this file except in compliance with the License. 6b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * You may obtain a copy of the License at 7b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * 8b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * http://www.apache.org/licenses/LICENSE-2.0 9b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * 10b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * Unless required by applicable law or agreed to in writing, software 11b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * distributed under the License is distributed on an "AS IS" BASIS, 12b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * See the License for the specific language governing permissions and 14b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * limitations under the License. 15b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase */ 16b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haasepackage android.animation; 17b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase 18b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haaseimport android.graphics.Rect; 19b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase 20b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase/** 21edf6f4b49f6e77c349f5055372ce381b74f12efbChet Haase * This evaluator can be used to perform type interpolation between <code>Rect</code> values. 22b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase */ 23b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haasepublic class RectEvaluator implements TypeEvaluator<Rect> { 24b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase 25b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase /** 26b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * This function returns the result of linearly interpolating the start and 27b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * end Rect values, with <code>fraction</code> representing the proportion 28b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * between the start and end values. The calculation is a simple parametric 29b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * calculation on each of the separate components in the Rect objects 30b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * (left, top, right, and bottom). 31b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * 32b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * @param fraction The fraction from the starting to the ending values 33b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * @param startValue The start Rect 34b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * @param endValue The end Rect 35b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * @return A linear interpolation between the start and end values, given the 36b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase * <code>fraction</code> parameter. 37b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase */ 38b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase @Override 39b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase public Rect evaluate(float fraction, Rect startValue, Rect endValue) { 40b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase return new Rect(startValue.left + (int)((endValue.left - startValue.left) * fraction), 41b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase startValue.top + (int)((endValue.top - startValue.top) * fraction), 42b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase startValue.right + (int)((endValue.right - startValue.right) * fraction), 43b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase startValue.bottom + (int)((endValue.bottom - startValue.bottom) * fraction)); 44b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase } 45b989502e5cf44d65c6dddc0179b6d9b6e61ef7fdChet Haase} 46