| 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.TypedArray; |
| 21 |
import android.util.AttributeSet; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class RotateAnimation extends Animation { |
| 31 |
private float mFromDegrees; |
| 32 |
private float mToDegrees; |
| 33 |
|
| 34 |
private int mPivotXType = ABSOLUTE; |
| 35 |
private int mPivotYType = ABSOLUTE; |
| 36 |
private float mPivotXValue = 0.0f; |
| 37 |
private float mPivotYValue = 0.0f; |
| 38 |
|
| 39 |
private float mPivotX; |
| 40 |
private float mPivotY; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public RotateAnimation(Context context, AttributeSet attrs) { |
| 49 |
super(context, attrs); |
| 50 |
|
| 51 |
TypedArray a = context.obtainStyledAttributes(attrs, |
| 52 |
com.android.internal.R.styleable.RotateAnimation); |
| 53 |
|
| 54 |
mFromDegrees = a.getFloat( |
| 55 |
com.android.internal.R.styleable.RotateAnimation_fromDegrees, 0.0f); |
| 56 |
mToDegrees = a.getFloat(com.android.internal.R.styleable.RotateAnimation_toDegrees, 0.0f); |
| 57 |
|
| 58 |
Description d = Description.parseValue(a.peekValue( |
| 59 |
com.android.internal.R.styleable.RotateAnimation_pivotX), context); |
| 60 |
mPivotXType = d.type; |
| 61 |
mPivotXValue = d.value; |
| 62 |
|
| 63 |
d = Description.parseValue(a.peekValue( |
| 64 |
com.android.internal.R.styleable.RotateAnimation_pivotY), context); |
| 65 |
mPivotYType = d.type; |
| 66 |
mPivotYValue = d.value; |
| 67 |
|
| 68 |
a.recycle(); |
| 69 |
|
| 70 |
initializePivotPoint(); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public RotateAnimation(float fromDegrees, float toDegrees) { |
| 83 |
mFromDegrees = fromDegrees; |
| 84 |
mToDegrees = toDegrees; |
| 85 |
mPivotX = 0.0f; |
| 86 |
mPivotY = 0.0f; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY) { |
| 105 |
mFromDegrees = fromDegrees; |
| 106 |
mToDegrees = toDegrees; |
| 107 |
|
| 108 |
mPivotXType = ABSOLUTE; |
| 109 |
mPivotYType = ABSOLUTE; |
| 110 |
mPivotXValue = pivotX; |
| 111 |
mPivotYValue = pivotY; |
| 112 |
initializePivotPoint(); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, |
| 141 |
int pivotYType, float pivotYValue) { |
| 142 |
mFromDegrees = fromDegrees; |
| 143 |
mToDegrees = toDegrees; |
| 144 |
|
| 145 |
mPivotXValue = pivotXValue; |
| 146 |
mPivotXType = pivotXType; |
| 147 |
mPivotYValue = pivotYValue; |
| 148 |
mPivotYType = pivotYType; |
| 149 |
initializePivotPoint(); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
private void initializePivotPoint() { |
| 157 |
if (mPivotXType == ABSOLUTE) { |
| 158 |
mPivotX = mPivotXValue; |
| 159 |
} |
| 160 |
if (mPivotYType == ABSOLUTE) { |
| 161 |
mPivotY = mPivotYValue; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
@Override |
| 166 |
protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 167 |
float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime); |
| 168 |
float scale = getScaleFactor(); |
| 169 |
|
| 170 |
if (mPivotX == 0.0f && mPivotY == 0.0f) { |
| 171 |
t.getMatrix().setRotate(degrees); |
| 172 |
} else { |
| 173 |
t.getMatrix().setRotate(degrees, mPivotX * scale, mPivotY * scale); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
@Override |
| 178 |
public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 179 |
super.initialize(width, height, parentWidth, parentHeight); |
| 180 |
mPivotX = resolveSize(mPivotXType, mPivotXValue, width, parentWidth); |
| 181 |
mPivotY = resolveSize(mPivotYType, mPivotYValue, height, parentHeight); |
| 182 |
} |
| 183 |
} |