| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.animation; |
| 18 |
|
| 19 |
import static com.android.internal.R.styleable.AnticipateOvershootInterpolator; |
| 20 |
import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_extraTension; |
| 21 |
import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_tension; |
| 22 |
|
| 23 |
import android.content.Context; |
| 24 |
import android.content.res.Resources; |
| 25 |
import android.content.res.Resources.Theme; |
| 26 |
import android.content.res.TypedArray; |
| 27 |
import android.graphics.animation.HasNativeInterpolator; |
| 28 |
import android.graphics.animation.NativeInterpolator; |
| 29 |
import android.graphics.animation.NativeInterpolatorFactory; |
| 30 |
import android.util.AttributeSet; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@HasNativeInterpolator |
| 38 |
public class AnticipateOvershootInterpolator extends BaseInterpolator |
| 39 |
implements NativeInterpolator { |
| 40 |
private final float mTension; |
| 41 |
|
| 42 |
public AnticipateOvershootInterpolator() { |
| 43 |
mTension = 2.0f * 1.5f; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public AnticipateOvershootInterpolator(float tension) { |
| 52 |
mTension = tension * 1.5f; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public AnticipateOvershootInterpolator(float tension, float extraTension) { |
| 64 |
mTension = tension * extraTension; |
| 65 |
} |
| 66 |
|
| 67 |
public AnticipateOvershootInterpolator(Context context, AttributeSet attrs) { |
| 68 |
this(context.getResources(), context.getTheme(), attrs); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
public AnticipateOvershootInterpolator(Resources res, Theme theme, AttributeSet attrs) { |
| 73 |
TypedArray a; |
| 74 |
if (theme != null) { |
| 75 |
a = theme.obtainStyledAttributes(attrs, AnticipateOvershootInterpolator, 0, 0); |
| 76 |
} else { |
| 77 |
a = res.obtainAttributes(attrs, AnticipateOvershootInterpolator); |
| 78 |
} |
| 79 |
|
| 80 |
mTension = a.getFloat(AnticipateOvershootInterpolator_tension, 2.0f) * |
| 81 |
a.getFloat(AnticipateOvershootInterpolator_extraTension, 1.5f); |
| 82 |
setChangingConfiguration(a.getChangingConfigurations()); |
| 83 |
a.recycle(); |
| 84 |
} |
| 85 |
|
| 86 |
private static float a(float t, float s) { |
| 87 |
return t * t * ((s + 1) * t - s); |
| 88 |
} |
| 89 |
|
| 90 |
private static float o(float t, float s) { |
| 91 |
return t * t * ((s + 1) * t + s); |
| 92 |
} |
| 93 |
|
| 94 |
public float getInterpolation(float t) { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
if (t < 0.5f) return 0.5f * a(t * 2.0f, mTension); |
| 100 |
else return 0.5f * (o(t * 2.0f - 2.0f, mTension) + 2.0f); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
@Override |
| 105 |
public long createNativeInterpolator() { |
| 106 |
return NativeInterpolatorFactory.createAnticipateOvershootInterpolator(mTension); |
| 107 |
} |
| 108 |
} |