| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.animation; |
| 18 |
|
| 19 |
import android.animation.Keyframe.FloatKeyframe; |
| 20 |
|
| 21 |
import java.util.List; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class FloatKeyframeSet extends KeyframeSet implements Keyframes.FloatKeyframes { |
| 34 |
public FloatKeyframeSet(FloatKeyframe... keyframes) { |
| 35 |
super(keyframes); |
| 36 |
} |
| 37 |
|
| 38 |
@Override |
| 39 |
public Object getValue(float fraction) { |
| 40 |
return getFloatValue(fraction); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public FloatKeyframeSet clone() { |
| 45 |
final List<Keyframe> keyframes = mKeyframes; |
| 46 |
final int numKeyframes = mKeyframes.size(); |
| 47 |
FloatKeyframe[] newKeyframes = new FloatKeyframe[numKeyframes]; |
| 48 |
for (int i = 0; i < numKeyframes; ++i) { |
| 49 |
newKeyframes[i] = (FloatKeyframe) keyframes.get(i).clone(); |
| 50 |
} |
| 51 |
FloatKeyframeSet newSet = new FloatKeyframeSet(newKeyframes); |
| 52 |
return newSet; |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public float getFloatValue(float fraction) { |
| 57 |
if (fraction <= 0f) { |
| 58 |
final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0); |
| 59 |
final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(1); |
| 60 |
float prevValue = prevKeyframe.getFloatValue(); |
| 61 |
float nextValue = nextKeyframe.getFloatValue(); |
| 62 |
float prevFraction = prevKeyframe.getFraction(); |
| 63 |
float nextFraction = nextKeyframe.getFraction(); |
| 64 |
final TimeInterpolator interpolator = nextKeyframe.getInterpolator(); |
| 65 |
if (interpolator != null) { |
| 66 |
fraction = interpolator.getInterpolation(fraction); |
| 67 |
} |
| 68 |
float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction); |
| 69 |
return mEvaluator == null ? |
| 70 |
prevValue + intervalFraction * (nextValue - prevValue) : |
| 71 |
((Number)mEvaluator.evaluate(intervalFraction, prevValue, nextValue)). |
| 72 |
floatValue(); |
| 73 |
} else if (fraction >= 1f) { |
| 74 |
final FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 2); |
| 75 |
final FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(mNumKeyframes - 1); |
| 76 |
float prevValue = prevKeyframe.getFloatValue(); |
| 77 |
float nextValue = nextKeyframe.getFloatValue(); |
| 78 |
float prevFraction = prevKeyframe.getFraction(); |
| 79 |
float nextFraction = nextKeyframe.getFraction(); |
| 80 |
final TimeInterpolator interpolator = nextKeyframe.getInterpolator(); |
| 81 |
if (interpolator != null) { |
| 82 |
fraction = interpolator.getInterpolation(fraction); |
| 83 |
} |
| 84 |
float intervalFraction = (fraction - prevFraction) / (nextFraction - prevFraction); |
| 85 |
return mEvaluator == null ? |
| 86 |
prevValue + intervalFraction * (nextValue - prevValue) : |
| 87 |
((Number)mEvaluator.evaluate(intervalFraction, prevValue, nextValue)). |
| 88 |
floatValue(); |
| 89 |
} |
| 90 |
FloatKeyframe prevKeyframe = (FloatKeyframe) mKeyframes.get(0); |
| 91 |
for (int i = 1; i < mNumKeyframes; ++i) { |
| 92 |
FloatKeyframe nextKeyframe = (FloatKeyframe) mKeyframes.get(i); |
| 93 |
if (fraction < nextKeyframe.getFraction()) { |
| 94 |
final TimeInterpolator interpolator = nextKeyframe.getInterpolator(); |
| 95 |
float intervalFraction = (fraction - prevKeyframe.getFraction()) / |
| 96 |
(nextKeyframe.getFraction() - prevKeyframe.getFraction()); |
| 97 |
float prevValue = prevKeyframe.getFloatValue(); |
| 98 |
float nextValue = nextKeyframe.getFloatValue(); |
| 99 |
|
| 100 |
if (interpolator != null) { |
| 101 |
intervalFraction = interpolator.getInterpolation(intervalFraction); |
| 102 |
} |
| 103 |
return mEvaluator == null ? |
| 104 |
prevValue + intervalFraction * (nextValue - prevValue) : |
| 105 |
((Number)mEvaluator.evaluate(intervalFraction, prevValue, nextValue)). |
| 106 |
floatValue(); |
| 107 |
} |
| 108 |
prevKeyframe = nextKeyframe; |
| 109 |
} |
| 110 |
|
| 111 |
return ((Number)mKeyframes.get(mNumKeyframes - 1).getValue()).floatValue(); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public Class getType() { |
| 116 |
return Float.class; |
| 117 |
} |
| 118 |
} |
| 119 |
|