views:

44

answers:

0

Hello all,

I'm creating an app that targets Android 1.5 and up and I can't seem to find a way to pause/resume/cancel a running animation. Does anyone here know how to do these 3 things?

More Info:

I create a custom AnimationSet (which I add 2 ScaleAnimations to when needed) and set at AnimationSet as the animation for an ImageView. I want to be able to display a pause menu or dialog over the current running Activity and have any running Animations pause, wait for the user to resume the main activity, and then start back up again from the exact position they left off. Also, I'd like to be able to save the animation "position" to a SharedPreferences file so I can resume the animation from where it left off, if the app is closed.

Thanks.

[CODE:] (the cancel() method seems to work, but is there a better way?)

public static class PopAnimationSet extends AnimationSet
    {
        protected AnimationListener myListener;

        public PopAnimationSet(boolean shareInterpolator) {
            super(shareInterpolator);
        }

        public PopAnimationSet(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        @Override
        public void setAnimationListener(AnimationListener listener)
        {
            myListener = listener;
            super.setAnimationListener(listener);
        }

        /**
         * Cancel the animation. Cancelling an animation invokes the animation
         * listener, if set, to notify the end of the animation.
         * 
         * If you cancel an animation manually, you must call {@link #reset()}
         * before starting the animation again.
         * 
         * @see #reset() 
         * @see #start() 
         * @see #startNow() 
         */
        public void cancel() 
        {
            if (this.hasStarted() && !this.hasEnded()) 
            {
                if (myListener != null) myListener.onAnimationEnd(this);
                //mEnded = true;
            }
            // Make sure we move the animation to the end
            this.setStartTime(Long.MIN_VALUE);
            //mStartTime = Long.MIN_VALUE;
            //mMore = mOneMoreTime = false;
        }
    }