Code example for ObjectAnimator

Methods: addListener, setDuration, start

0
            } 
 
            CrossFadeDrawable crossFadeDrawable = newCrossFadeDrawable(from, to);
            ObjectAnimator animator = crossFadeDrawable.getAnimator();
            imageView.setImageDrawable(crossFadeDrawable);
            animator.setDuration(ANIMATION_DURATION);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override 
                public void onAnimationStart(Animator animation) {
                    if (FADE_DBG) {
                        log("cross-fade animation start (" 
                                + Integer.toHexString(from.hashCode()) + " -> "
                                + Integer.toHexString(to.hashCode()) + ")");
                    } 
                } 
 
                @Override 
                public void onAnimationEnd(Animator animation) {
                    if (FADE_DBG) {
                        log("cross-fade animation ended (" 
                                + Integer.toHexString(from.hashCode()) + " -> "
                                + Integer.toHexString(to.hashCode()) + ")");
                    } 
                    animation.removeAllListeners();
                    // Workaround for issue 6300562; this will force the drawable to the 
                    // resultant one regardless of animation glitch. 
                    imageView.setImageDrawable(to);
                } 
            }); 
            animator.start();
 
            /* We could use TransitionDrawable here, but it may cause some weird animation in 
             * some corner cases. See issue 6300562 
             * TODO: decide which to be used in the long run. TransitionDrawable is old but system 
             * one. Ours uses new animation framework and thus have callback (great for testing),