/** * Start the animation playing. This version of start() takes a boolean flag that indicates * whether the animation should play in reverse. The flag is usually false, but may be set to true * if called from the reverse() method. * * <p>The animation started by calling this method will be run on the thread that called this * method. This thread should have a Looper on it (a runtime exception will be thrown if this is * not the case). Also, if the animation will animate properties of objects in the view hierarchy, * then the calling thread should be the UI thread for that view hierarchy. * * @param playBackwards Whether the ValueAnimator should start playing in reverse. */ private void start(boolean playBackwards) { if (Looper.myLooper() == null) { throw new AndroidRuntimeException("Animators may only be run on Looper threads"); } mPlayingBackwards = playBackwards; mCurrentIteration = 0; mPlayingState = STOPPED; mStarted = true; mStartedDelay = false; sPendingAnimations.get().add(this); if (mStartDelay == 0) { // This sets the initial value of the animation, prior to actually starting it running setCurrentPlayTime(getCurrentPlayTime()); mPlayingState = STOPPED; mRunning = true; if (mListeners != null) { ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); int numListeners = tmpListeners.size(); for (int i = 0; i < numListeners; ++i) { tmpListeners.get(i).onAnimationStart(this); } } } AnimationHandler animationHandler = sAnimationHandler.get(); if (animationHandler == null) { animationHandler = new AnimationHandler(); sAnimationHandler.set(animationHandler); } animationHandler.sendEmptyMessage(ANIMATION_START); }
private void start(boolean playBackwards) { if (Looper.myLooper() == null) { throw new AndroidRuntimeException("Animators may only be run on Looper threads"); } mPlayingBackwards = playBackwards; mCurrentIteration = 0; mPlayingState = STOPPED; mStarted = true; mStartedDelay = false; mPaused = false; AnimationHandler animationHandler = getOrCreateAnimationHandler(); animationHandler.mPendingAnimations.add(this); if (mStartDelay == 0) { setCurrentPlayTime(0); mPlayingState = STOPPED; mRunning = true; notifyStartListeners(); } animationHandler.start(); }
private Notifcation(final int points) { this.points = points; alpha = new AnimatedValue(255); x = new AnimatedValue(screenWidth - X_MARGIN); y = new AnimatedValue(Y_MARGIN); AnimationHandler.getInstance() .addAnimation( new Animation( alpha, 255, 0, System.nanoTime(), 1, Animation.INTERPOLATION.COSINE, Animation.TYPE.POINT_TO_POINT)); xAnimation = new Animation( x, x.getValue(), x.getValue() + Math.random() * X_DIFF, System.nanoTime(), 0.25f, Animation.INTERPOLATION.COSINE, Animation.TYPE.ENDLESS); AnimationHandler.getInstance().addAnimation(xAnimation); AnimationHandler.getInstance() .addAnimation( new Animation( y, y.getValue(), y.getValue() + Y_DIST, System.nanoTime(), 1.0f, Animation.INTERPOLATION.COSINE, Animation.TYPE.POINT_TO_POINT)); }