| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.animation; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.res.Resources; |
| 21 |
import android.content.res.Resources.Theme; |
| 22 |
import android.content.res.TypedArray; |
| 23 |
import android.graphics.animation.HasNativeInterpolator; |
| 24 |
import android.graphics.animation.NativeInterpolator; |
| 25 |
import android.graphics.animation.NativeInterpolatorFactory; |
| 26 |
import android.util.AttributeSet; |
| 27 |
|
| 28 |
import com.android.internal.R; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
@HasNativeInterpolator |
| 34 |
public class AnticipateInterpolator extends BaseInterpolator implements NativeInterpolator { |
| 35 |
private final float mTension; |
| 36 |
|
| 37 |
public AnticipateInterpolator() { |
| 38 |
mTension = 2.0f; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public AnticipateInterpolator(float tension) { |
| 47 |
mTension = tension; |
| 48 |
} |
| 49 |
|
| 50 |
public AnticipateInterpolator(Context context, AttributeSet attrs) { |
| 51 |
this(context.getResources(), context.getTheme(), attrs); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
public AnticipateInterpolator(Resources res, Theme theme, AttributeSet attrs) { |
| 56 |
TypedArray a; |
| 57 |
if (theme != null) { |
| 58 |
a = theme.obtainStyledAttributes(attrs, R.styleable.AnticipateInterpolator, 0, 0); |
| 59 |
} else { |
| 60 |
a = res.obtainAttributes(attrs, R.styleable.AnticipateInterpolator); |
| 61 |
} |
| 62 |
|
| 63 |
mTension = a.getFloat(R.styleable.AnticipateInterpolator_tension, 2.0f); |
| 64 |
setChangingConfiguration(a.getChangingConfigurations()); |
| 65 |
a.recycle(); |
| 66 |
} |
| 67 |
|
| 68 |
public float getInterpolation(float t) { |
| 69 |
|
| 70 |
return t * t * ((mTension + 1) * t - mTension); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
@Override |
| 75 |
public long createNativeInterpolator() { |
| 76 |
return NativeInterpolatorFactory.createAnticipateInterpolator(mTension); |
| 77 |
} |
| 78 |
} |