diff options
author | Alan Viverette <alanv@google.com> | 2015-02-25 17:55:22 -0800 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-02-25 17:55:22 -0800 |
commit | 039bd51a23d886d0acaa93458e286329503bd243 (patch) | |
tree | f7910352937a5fddb4fa34bf65bb23df24972389 /graphics | |
parent | b3f3762ee0f57c94ea25bc1cc9d4baf0ee2a2976 (diff) | |
download | frameworks_base-039bd51a23d886d0acaa93458e286329503bd243.zip frameworks_base-039bd51a23d886d0acaa93458e286329503bd243.tar.gz frameworks_base-039bd51a23d886d0acaa93458e286329503bd243.tar.bz2 |
Remove obsolete code from AnimatedRotateDrawable state
DrawableWrappers shouldn't have drawables inside their state, nor should
they manage their own drawables. Also cleans up documentation.
Bug: 19518051
Change-Id: I2aea011afe80e94aadec702e1680c3765528b112
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java | 102 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/RotateDrawable.java | 2 |
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 595061c..3437bb3 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(null, null); |