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