summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-02-26 01:56:11 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-26 01:56:14 +0000
commit40d13f260c50ac5235f7405e1c3a83d6f46a8d62 (patch)
tree8553e0e63a38d8eb832b04a581de4c6ff1e36475 /graphics
parent745677f117880d7e67e6de7da3826696339a49e8 (diff)
parent039bd51a23d886d0acaa93458e286329503bd243 (diff)
downloadframeworks_base-40d13f260c50ac5235f7405e1c3a83d6f46a8d62.zip
frameworks_base-40d13f260c50ac5235f7405e1c3a83d6f46a8d62.tar.gz
frameworks_base-40d13f260c50ac5235f7405e1c3a83d6f46a8d62.tar.bz2
Merge "Remove obsolete code from AnimatedRotateDrawable state"
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java102
-rw-r--r--graphics/java/android/graphics/drawable/RotateDrawable.java2
2 files changed, 46 insertions, 58 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
index db94d89..24e0d6a 100644
--- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java
@@ -37,38 +37,47 @@ import com.android.internal.R;
/**
* @hide
*/
-public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable, Animatable {
+public class AnimatedRotateDrawable extends DrawableWrapper implements Animatable {
private AnimatedRotateState mState;
private float mCurrentDegrees;
private float mIncrement;
+
+ /** Whether this drawable is currently animating. */
private boolean mRunning;
+ /**
+ * Creates a new animated rotating drawable with no wrapped drawable.
+ */
public AnimatedRotateDrawable() {
this(new AnimatedRotateState(null), null);
}
@Override
public void draw(Canvas canvas) {
- int saveCount = canvas.save();
-
- final AnimatedRotateState st = mState;
- final Drawable drawable = st.mDrawable;
+ final Drawable drawable = getDrawable();
final Rect bounds = drawable.getBounds();
+ final int w = bounds.right - bounds.left;
+ final int h = bounds.bottom - bounds.top;
- int w = bounds.right - bounds.left;
- int h = bounds.bottom - bounds.top;
-
- float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
- float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;
+ final AnimatedRotateState st = mState;
+ final float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
+ final float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;
+ final int saveCount = canvas.save();
canvas.rotate(mCurrentDegrees, px + bounds.left, py + bounds.top);
-
drawable.draw(canvas);
-
canvas.restoreToCount(saveCount);
}
+ /**
+ * Starts the rotation animation.
+ * <p>
+ * The animation will run until {@link #stop()} is called. Calling this
+ * method while the animation is already running has no effect.
+ *
+ * @see #stop()
+ */
@Override
public void start() {
if (!mRunning) {
@@ -77,10 +86,15 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
}
}
+ /**
+ * Stops the rotation animation.
+ *
+ * @see #start()
+ */
@Override
public void stop() {
mRunning = false;
- unscheduleSelf(this);
+ unscheduleSelf(mNextFrame);
}
@Override
@@ -89,20 +103,8 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
}
private void nextFrame() {
- unscheduleSelf(this);
- scheduleSelf(this, SystemClock.uptimeMillis() + mState.mFrameDuration);
- }
-
- @Override
- public void run() {
- // TODO: This should be computed in draw(Canvas), based on the amount
- // of time since the last frame drawn
- mCurrentDegrees += mIncrement;
- if (mCurrentDegrees > (360.0f - mIncrement)) {
- mCurrentDegrees = 0.0f;
- }
- invalidateSelf();
- nextFrame();
+ unscheduleSelf(mNextFrame);
+ scheduleSelf(mNextFrame, SystemClock.uptimeMillis() + mState.mFrameDuration);
}
@Override
@@ -114,7 +116,7 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
nextFrame();
}
} else {
- unscheduleSelf(this);
+ unscheduleSelf(mNextFrame);
}
return changed;
}
@@ -208,11 +210,6 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
}
static final class AnimatedRotateState extends DrawableWrapper.DrawableWrapperState {
- Drawable mDrawable;
- int[] mThemeAttrs;
-
- int mChangingConfigurations;
-
boolean mPivotXRel = false;
float mPivotX = 0;
boolean mPivotYRel = false;
@@ -220,9 +217,6 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
int mFrameDuration = 150;
int mFramesCount = 12;
- private boolean mCanConstantState;
- private boolean mCheckedConstantState;
-
public AnimatedRotateState(AnimatedRotateState orig) {
super(orig);
@@ -240,26 +234,6 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
public Drawable newDrawable(Resources res) {
return new AnimatedRotateDrawable(this, res);
}
-
- @Override
- public boolean canApplyTheme() {
- return mThemeAttrs != null || (mDrawable != null && mDrawable.canApplyTheme())
- || super.canApplyTheme();
- }
-
- @Override
- public int getChangingConfigurations() {
- return mChangingConfigurations;
- }
-
- public boolean canConstantState() {
- if (!mCheckedConstantState) {
- mCanConstantState = mDrawable.getConstantState() != null;
- mCheckedConstantState = true;
- }
-
- return mCanConstantState;
- }
}
private AnimatedRotateDrawable(AnimatedRotateState state, Resources res) {
@@ -276,7 +250,7 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
// Force the wrapped drawable to use filtering and AA, if applicable,
// so that it looks smooth when rotated.
- final Drawable drawable = state.mDrawable;
+ final Drawable drawable = getDrawable();
if (drawable != null) {
drawable.setFilterBitmap(true);
if (drawable instanceof BitmapDrawable) {
@@ -284,4 +258,18 @@ public class AnimatedRotateDrawable extends DrawableWrapper implements Runnable,
}
}
}
+
+ private final Runnable mNextFrame = new Runnable() {
+ @Override
+ public void run() {
+ // TODO: This should be computed in draw(Canvas), based on the amount
+ // of time since the last frame drawn
+ mCurrentDegrees += mIncrement;
+ if (mCurrentDegrees > (360.0f - mIncrement)) {
+ mCurrentDegrees = 0.0f;
+ }
+ invalidateSelf();
+ nextFrame();
+ }
+ };
}
diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java
index aeef659..ca161ee 100644
--- a/graphics/java/android/graphics/drawable/RotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/RotateDrawable.java
@@ -58,7 +58,7 @@ public class RotateDrawable extends DrawableWrapper {
private RotateState mState;
/**
- * Create a new rotating drawable with an empty state.
+ * Creates a new rotating drawable with no wrapped drawable.
*/
public RotateDrawable() {
this(new RotateState(null), null);