AccelerateInterpolator.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1/* 2 * Copyright (C) 2006 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 slowly and 25 * and then accelerates. 26 * 27 */ 28public class AccelerateInterpolator implements Interpolator { 29 public AccelerateInterpolator() { 30 } 31 32 /** 33 * Constructor 34 * 35 * @param factor Degree to which the animation should be eased. Seting 36 * factor to 1.0f produces a y=x^2 parabola. Increasing factor above 37 * 1.0f exaggerates the ease-in effect (i.e., it starts even 38 * slower and ends evens faster) 39 */ 40 public AccelerateInterpolator(float factor) { 41 mFactor = factor; 42 } 43 44 public AccelerateInterpolator(Context context, AttributeSet attrs) { 45 TypedArray a = 46 context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.AccelerateInterpolator); 47 48 mFactor = a.getFloat(com.android.internal.R.styleable.AccelerateInterpolator_factor, 1.0f); 49 50 a.recycle(); 51 } 52 53 public float getInterpolation(float input) { 54 if (mFactor == 1.0f) { 55 return (float)(input * input); 56 } else { 57 return (float)Math.pow(input, 2 * mFactor); 58 } 59 } 60 61 private float mFactor = 1.0f; 62} 63