From b5537c452271634b6ff3981b0624fa65384abd5b Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 30 Jun 2009 12:39:18 -0700 Subject: Replace indeterminate progress animated asset with new ones --- .../java/android/graphics/drawable/Animatable.java | 39 ++++++++++++++++++++++ .../graphics/drawable/AnimatedRotateDrawable.java | 27 ++++++++++++--- .../graphics/drawable/AnimationDrawable.java | 2 +- 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 graphics/java/android/graphics/drawable/Animatable.java (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/Animatable.java b/graphics/java/android/graphics/drawable/Animatable.java new file mode 100644 index 0000000..9dc62c3 --- /dev/null +++ b/graphics/java/android/graphics/drawable/Animatable.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics.drawable; + +/** + * Interface that drawables suporting animations should implement. + */ +public interface Animatable { + /** + * Starts the drawable's animation. + */ + void start(); + + /** + * Stops the drawable's animation. + */ + void stop(); + + /** + * Indicates whether the animation is running. + * + * @return True if the animation is running, false otherwise. + */ + boolean isRunning(); +} diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java index 08d295d..ac96f20 100644 --- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java @@ -35,11 +35,14 @@ import com.android.internal.R; /** * @hide */ -public class AnimatedRotateDrawable extends Drawable implements Drawable.Callback, Runnable { +public class AnimatedRotateDrawable extends Drawable implements Drawable.Callback, Runnable, + Animatable { + private AnimatedRotateState mState; private boolean mMutated; private float mCurrentDegrees; private float mIncrement; + private boolean mRunning; public AnimatedRotateDrawable() { this(null); @@ -80,10 +83,24 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac drawable.draw(canvas); canvas.restoreToCount(saveCount); - - nextFrame(); } - + + public void start() { + if (!mRunning) { + mRunning = true; + nextFrame(); + } + } + + public void stop() { + mRunning = false; + unscheduleSelf(this); + } + + public boolean isRunning() { + return mRunning; + } + private void nextFrame() { unscheduleSelf(this); scheduleSelf(this, SystemClock.uptimeMillis() + mState.mFrameDuration); @@ -96,8 +113,8 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac if (mCurrentDegrees > (360.0f - mIncrement)) { mCurrentDegrees = 0.0f; } - nextFrame(); invalidateSelf(); + nextFrame(); } @Override diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index bab1703..68718c9 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -71,7 +71,7 @@ import android.util.AttributeSet; * @attr ref android.R.styleable#AnimationDrawableItem_duration * @attr ref android.R.styleable#AnimationDrawableItem_drawable */ -public class AnimationDrawable extends DrawableContainer implements Runnable { +public class AnimationDrawable extends DrawableContainer implements Runnable, Animatable { private final AnimationState mAnimationState; private int mCurFrame = -1; private boolean mMutated; -- cgit v1.1