Home | History | Annotate | Download | only in animation
      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 
     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 quickly and
     25  * and then decelerates.
     26  *
     27  */
     28 public 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         if (mFactor == 1.0f) {
     54             return (float)(1.0f - (1.0f - input) * (1.0f - input));
     55         } else {
     56             return (float)(1.0f - Math.pow((1.0f - input), 2 * mFactor));
     57         }
     58     }
     59 
     60     private float mFactor = 1.0f;
     61 }
     62