• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 change starts backward then flings forward.
25  */
26 public class AnticipateInterpolator implements Interpolator {
27     private final float mTension;
28 
AnticipateInterpolator()29     public AnticipateInterpolator() {
30         mTension = 2.0f;
31     }
32 
33     /**
34      * @param tension Amount of anticipation. When tension equals 0.0f, there is
35      *                no anticipation and the interpolator becomes a simple
36      *                acceleration interpolator.
37      */
AnticipateInterpolator(float tension)38     public AnticipateInterpolator(float tension) {
39         mTension = tension;
40     }
41 
AnticipateInterpolator(Context context, AttributeSet attrs)42     public AnticipateInterpolator(Context context, AttributeSet attrs) {
43         TypedArray a = context.obtainStyledAttributes(attrs,
44                 com.android.internal.R.styleable.AnticipateInterpolator);
45 
46         mTension =
47                 a.getFloat(com.android.internal.R.styleable.AnticipateInterpolator_tension, 2.0f);
48 
49         a.recycle();
50     }
51 
getInterpolation(float t)52     public float getInterpolation(float t) {
53         // a(t) = t * t * ((tension + 1) * t - tension)
54         return t * t * ((mTension + 1) * t - mTension);
55     }
56 }
57