ch6 animation

satya - Saturday, September 19, 2009 8:09:17 AM

They have introduced 4 new interpolators


AnticipateInterpolator 
AnticipateOvershootInterpolator 
BounceInterpolator 
OvershootInterpolator

satya - Saturday, September 19, 2009 8:20:54 AM

The api reference

The api reference

satya - Saturday, September 19, 2009 8:51:50 AM

Previous notes on animation 1

Previous notes on animation 1

satya - Saturday, September 19, 2009 8:55:03 AM

Here is the source code AnticipateInterpolator

Here is the source code AnticipateInterpolator

satya - Saturday, September 19, 2009 8:55:21 AM

Here is how you would have searched for it

Here is how you would have searched for it

satya - Saturday, September 19, 2009 8:58:03 AM

Here is a quick review of it


26 public class AnticipateInterpolator implements Interpolator {
27     private final float mTension;
28 
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      */
38     public AnticipateInterpolator(float tension) {
39         mTension = tension;
40     }
41 
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 
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 }

satya - Saturday, September 19, 2009 9:35:10 AM

You can graph this equation online here

You can graph this equation online here

satya - Saturday, September 19, 2009 9:40:38 AM

Here is the equation for OvershootInterpolator


53     public float getInterpolation(float t) {
56         t -= 1.0f;
57         return t * t * ((mTension + 1) * t + mTension) + 1.0f;
58     }

satya - Saturday, September 19, 2009 9:45:09 AM

Here is bounce


public class BounceInterpolator implements Interpolator {
27     public BounceInterpolator() {
28     }
29 
30     @SuppressWarnings({"UnusedDeclaration"})
31     public BounceInterpolator(Context context, AttributeSet attrs) {
32     }
33 
34     private static float bounce(float t) {
35         return t * t * 8.0f;
36     }
37 
38     public float getInterpolation(float t) {
39         // _b(t) = t * t * 8
40         // bs(t) = _b(t) for t < 0.3535
41         // bs(t) = _b(t - 0.54719) + 0.7 for t < 0.7408
42         // bs(t) = _b(t - 0.8526) + 0.9 for t < 0.9644
43         // bs(t) = _b(t - 1.0435) + 0.95 for t <= 1.0
44         // b(t) = bs(t * 1.1226)
45         t *= 1.1226f;
46         if (t < 0.3535f) return bounce(t);
47         else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f;
48         else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f;
49         else return bounce(t - 1.0435f) + 0.95f;
50     }
51 }