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