1/* 2 * Copyright (C) 2007 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.view.animation; 18 19import android.content.Context; 20import android.content.res.TypedArray; 21import android.util.AttributeSet; 22 23/** 24 * An interpolator where the rate of change starts out quickly and 25 * and then decelerates. 26 * 27 */ 28public class DecelerateInterpolator implements Interpolator { 29 public DecelerateInterpolator() { 30 } 31 32 /** 33 * Constructor 34 * 35 * @param factor Degree to which the animation should be eased. Setting factor to 1.0f produces 36 * an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the 37 * ease-out effect (i.e., it starts even faster and ends evens slower) 38 */ 39 public DecelerateInterpolator(float factor) { 40 mFactor = factor; 41 } 42 43 public DecelerateInterpolator(Context context, AttributeSet attrs) { 44 TypedArray a = 45 context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.DecelerateInterpolator); 46 47 mFactor = a.getFloat(com.android.internal.R.styleable.DecelerateInterpolator_factor, 1.0f); 48 49 a.recycle(); 50 } 51 52 public float getInterpolation(float input) { 53 float result; 54 if (mFactor == 1.0f) { 55 result = (float)(1.0f - (1.0f - input) * (1.0f - input)); 56 } else { 57 result = (float)(1.0f - Math.pow((1.0f - input), 2 * mFactor)); 58 } 59 return result; 60 } 61 62 private float mFactor = 1.0f; 63} 64