@Override public void start() { // See if any of the current active/pending animators need to be canceled AnimationHandler handler = sAnimationHandler.get(); if (handler != null) { int numAnims = sAnimations.get().size(); for (int i = numAnims - 1; i >= 0; i--) { if (sAnimations.get().get(i) instanceof ObjectAnimator) { ObjectAnimator anim = (ObjectAnimator) sAnimations.get().get(i); if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { anim.cancel(); } } } numAnims = sPendingAnimations.get().size(); for (int i = numAnims - 1; i >= 0; i--) { if (sPendingAnimations.get().get(i) instanceof ObjectAnimator) { ObjectAnimator anim = (ObjectAnimator) sPendingAnimations.get().get(i); if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { anim.cancel(); } } } numAnims = sDelayedAnims.get().size(); for (int i = numAnims - 1; i >= 0; i--) { if (sDelayedAnims.get().get(i) instanceof ObjectAnimator) { ObjectAnimator anim = (ObjectAnimator) sDelayedAnims.get().get(i); if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { anim.cancel(); } } } } if (DBG) { Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration()); for (int i = 0; i < mValues.length; ++i) { PropertyValuesHolder pvh = mValues[i]; ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes; Log.d( "ObjectAnimator", " Values[" + i + "]: " + pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " + keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue()); } } super.start(); }
public MyAnimationView(Context context) { super(context); // Animate background color // Note that setting the background color will automatically invalidate the // view, so that the animated color, and the bouncing balls, get redisplayed on // every frame of the animation. ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE); colorAnim.setDuration(3000); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.start(); }
private void startAnimation() { ValueAnimator mAnimatorAlpha = ValueAnimator.ofInt(255, 0); mAnimatorAlpha.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int a = (int) animation.getAnimatedValue(); Log.e("123132:", "" + a); mNewPaint.setAlpha((int) animation.getAnimatedValue()); invalidate(); } }); mAnimatorAlpha.setDuration(2000); mAnimatorAlpha.start(); // Point startPoint = new Point(RADIUS, RADIUS); // Point endPoint = new Point(getWidth() - RADIUS, getHeight() - RADIUS); // ValueAnimator anim1 = ValueAnimator.ofObject(new PointEvaluator(), startPoint, // endPoint); // // anim = ValueAnimator.ofObject(new ColorEvaluator(), // "#FF0000", "#0000FF" ); // anim2 = ValueAnimator.ofObject( new ColorEvaluator(), // "#0000FF", "#FF0000"); // AnimatorSet animSet = new AnimatorSet(); // animSet.play(anim1).with(anim2); // animSet.setDuration(5000); // anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // @Override // public void onAnimationUpdate(ValueAnimator animation) { // currentPoint = (Point) animation.getAnimatedValue(); // invalidate(); // } // }); // // anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // @Override // public void onAnimationUpdate(ValueAnimator animation) { // mNewPaint.setColor(Color.parseColor((String) animation.getAnimatedValue())); // invalidate(); // } // }); // anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // @Override // public void onAnimationUpdate(ValueAnimator animation) { // mNewPaint.setColor(Color.parseColor((String) animation.getAnimatedValue())); // invalidate(); // } // }); // // anim.addListener(new Animator.AnimatorListener() { // @Override // public void onAnimationStart(Animator animation) { // // } // // @Override // public void onAnimationEnd(Animator animation) { // isTrue = true; // } // // @Override // public void onAnimationCancel(Animator animation) { // // } // // @Override // public void onAnimationRepeat(Animator animation) { // // } // }); // anim2.addListener(new Animator.AnimatorListener() { // @Override // public void onAnimationStart(Animator animation) { // // } // // @Override // public void onAnimationEnd(Animator animation) { // anim.setDuration(5000); // anim.start(); // } // // @Override // public void onAnimationCancel(Animator animation) { // // } // // @Override // public void onAnimationRepeat(Animator animation) { // // } // }); // // anim2.start(); }
/** * {@inheritDoc} * * <p>Starting this <code>AnimatorSet</code> will, in turn, start the animations for which it is * responsible. The details of when exactly those animations are started depends on the dependency * relationships that have been set up between the animations. */ @SuppressWarnings("unchecked") @Override public void start() { mTerminated = false; mStarted = true; // First, sort the nodes (if necessary). This will ensure that sortedNodes // contains the animation nodes in the correct order. sortNodes(); int numSortedNodes = mSortedNodes.size(); for (int i = 0; i < numSortedNodes; ++i) { Node node = mSortedNodes.get(i); // First, clear out the old listeners ArrayList<AnimatorListener> oldListeners = node.animation.getListeners(); if (oldListeners != null && oldListeners.size() > 0) { final ArrayList<AnimatorListener> clonedListeners = new ArrayList<AnimatorListener>(oldListeners); for (AnimatorListener listener : clonedListeners) { if (listener instanceof DependencyListener || listener instanceof AnimatorSetListener) { node.animation.removeListener(listener); } } } } // nodesToStart holds the list of nodes to be started immediately. We don't want to // start the animations in the loop directly because we first need to set up // dependencies on all of the nodes. For example, we don't want to start an animation // when some other animation also wants to start when the first animation begins. final ArrayList<Node> nodesToStart = new ArrayList<Node>(); for (int i = 0; i < numSortedNodes; ++i) { Node node = mSortedNodes.get(i); if (mSetListener == null) { mSetListener = new AnimatorSetListener(this); } if (node.dependencies == null || node.dependencies.size() == 0) { nodesToStart.add(node); } else { int numDependencies = node.dependencies.size(); for (int j = 0; j < numDependencies; ++j) { Dependency dependency = node.dependencies.get(j); dependency.node.animation.addListener( new DependencyListener(this, node, dependency.rule)); } node.tmpDependencies = (ArrayList<Dependency>) node.dependencies.clone(); } node.animation.addListener(mSetListener); } // Now that all dependencies are set up, start the animations that should be started. if (mStartDelay <= 0) { for (Node node : nodesToStart) { node.animation.start(); mPlayingSet.add(node.animation); } } else { mDelayAnim = ValueAnimator.ofFloat(0f, 1f); mDelayAnim.setDuration(mStartDelay); mDelayAnim.addListener( new AnimatorListenerAdapter() { boolean canceled = false; @Override public void onAnimationCancel(Animator anim) { canceled = true; } @Override public void onAnimationEnd(Animator anim) { if (!canceled) { int numNodes = nodesToStart.size(); for (int i = 0; i < numNodes; ++i) { Node node = nodesToStart.get(i); node.animation.start(); mPlayingSet.add(node.animation); } } } }); mDelayAnim.start(); } 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); } } if (mNodes.size() == 0 && mStartDelay == 0) { // Handle unusual case where empty AnimatorSet is started - should send out // end event immediately since the event will not be sent out at all otherwise mStarted = false; if (mListeners != null) { ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); int numListeners = tmpListeners.size(); for (int i = 0; i < numListeners; ++i) { tmpListeners.get(i).onAnimationEnd(this); } } } }