| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.policy; |
| 18 |
|
| 19 |
import android.graphics.Rect; |
| 20 |
import android.view.animation.ClipRectAnimation; |
| 21 |
import android.view.animation.Interpolator; |
| 22 |
import android.view.animation.Transformation; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class ClipRectTBAnimation extends ClipRectAnimation { |
| 32 |
|
| 33 |
private final int mFromTranslateY; |
| 34 |
private final int mToTranslateY; |
| 35 |
private final Interpolator mTranslateInterpolator; |
| 36 |
private float mNormalizedTime; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public ClipRectTBAnimation(int fromT, int fromB, int toT, int toB, |
| 42 |
int fromTranslateY, int toTranslateY, Interpolator translateInterpolator) { |
| 43 |
super(0, fromT, 0, fromB, 0, toT, 0, toB); |
| 44 |
mFromTranslateY = fromTranslateY; |
| 45 |
mToTranslateY = toTranslateY; |
| 46 |
mTranslateInterpolator = translateInterpolator; |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
final long startOffset = getStartOffset(); |
| 56 |
final long duration = getDuration(); |
| 57 |
float normalizedTime; |
| 58 |
if (duration != 0) { |
| 59 |
normalizedTime = ((float) (currentTime - (getStartTime() + startOffset))) / |
| 60 |
(float) duration; |
| 61 |
} else { |
| 62 |
|
| 63 |
normalizedTime = currentTime < getStartTime() ? 0.0f : 1.0f; |
| 64 |
} |
| 65 |
mNormalizedTime = normalizedTime; |
| 66 |
return super.getTransformation(currentTime, outTransformation); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
@Override |
| 74 |
protected void applyTransformation(float it, Transformation tr) { |
| 75 |
float translationT = mTranslateInterpolator.getInterpolation(mNormalizedTime); |
| 76 |
int translation = |
| 77 |
(int) (mFromTranslateY + (mToTranslateY - mFromTranslateY) * translationT); |
| 78 |
Rect oldClipRect = tr.getClipRect(); |
| 79 |
tr.setClipRect(oldClipRect.left, |
| 80 |
mFromRect.top - translation + (int) ((mToRect.top - mFromRect.top) * it), |
| 81 |
oldClipRect.right, |
| 82 |
mFromRect.bottom - translation + (int) ((mToRect.bottom - mFromRect.bottom) * it)); |
| 83 |
} |
| 84 |
|
| 85 |
} |