| 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 |
|
| 34 |
|
| 35 |
@HasNativeInterpolator |
| 36 |
public class AccelerateInterpolator extends BaseInterpolator implements NativeInterpolator { |
| 37 |
private final float mFactor; |
| 38 |
private final double mDoubleFactor; |
| 39 |
|
| 40 |
public AccelerateInterpolator() { |
| 41 |
mFactor = 1.0f; |
| 42 |
mDoubleFactor = 2.0; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public AccelerateInterpolator(float factor) { |
| 54 |
mFactor = factor; |
| 55 |
mDoubleFactor = 2 * mFactor; |
| 56 |
} |
| 57 |
|
| 58 |
public AccelerateInterpolator(Context context, AttributeSet attrs) { |
| 59 |
this(context.getResources(), context.getTheme(), attrs); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
public AccelerateInterpolator(Resources res, Theme theme, AttributeSet attrs) { |
| 64 |
TypedArray a; |
| 65 |
if (theme != null) { |
| 66 |
a = theme.obtainStyledAttributes(attrs, R.styleable.AccelerateInterpolator, 0, 0); |
| 67 |
} else { |
| 68 |
a = res.obtainAttributes(attrs, R.styleable.AccelerateInterpolator); |
| 69 |
} |
| 70 |
|
| 71 |
mFactor = a.getFloat(R.styleable.AccelerateInterpolator_factor, 1.0f); |
| 72 |
mDoubleFactor = 2 * mFactor; |
| 73 |
setChangingConfiguration(a.getChangingConfigurations()); |
| 74 |
a.recycle(); |
| 75 |
} |
| 76 |
|
| 77 |
public float getInterpolation(float input) { |
| 78 |
if (mFactor == 1.0f) { |
| 79 |
return input * input; |
| 80 |
} else { |
| 81 |
return (float)Math.pow(input, mDoubleFactor); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
@Override |
| 87 |
public long createNativeInterpolator() { |
| 88 |
return NativeInterpolatorFactory.createAccelerateInterpolator(mFactor); |
| 89 |
} |
| 90 |
} |