Code example for ValueAnimator

Methods: addListener, addUpdateListener, start

10
        if (v.getBackground() instanceof BackgroundAlphaColorDrawable) { 
            final BackgroundAlphaColorDrawable bg = (BackgroundAlphaColorDrawable) v 
                    .getBackground(); 
            anim = ValueAnimator.ofObject(new ArgbEvaluator(), info.color, 
                    BackgroundAlphaColorDrawable.applyAlphaToColor(bg.getBgColor(), alpha)); 
            anim.addUpdateListener(new AnimatorUpdateListener() { 
                @Override 
                public void onAnimationUpdate(ValueAnimator animation) { 
                    info.color = (Integer) animation.getAnimatedValue(); 
                    bg.setColor(info.color); 
                } 
            }); 
        } else { 
            // custom image is set by the theme, let's just apply the alpha if we can. 
            v.getBackground().setAlpha(BackgroundAlphaColorDrawable.floatAlphaToInt(alpha)); 
            return null; 
        } 
        anim.addListener(new AnimatorListener() { 
            @Override 
            public void onAnimationStart(Animator animation) {
            } 
            @Override 
            public void onAnimationRepeat(Animator animation) {
            } 
            @Override 
            public void onAnimationEnd(Animator animation) {
                info.anim = null; 
            } 
            @Override 
            public void onAnimationCancel(Animator animation) {
                info.anim = null; 
            } 
        }); 
        info.anim = anim; 
        return anim; 
    } 
 
    private void doTransparentUpdate() { 
        mIsKeyguardShowing = isKeyguardShowing();
        mIsHomeShowing = isLauncherShowing();
 
        ValueAnimator navAnim = null, sbAnim = null;
        if (mNavbar != null) {
            navAnim = createAnimation(mNavbarInfo, (View)mNavbar);
        } 
        if (mStatusbar != null) {
            sbAnim = createAnimation(mStatusbarInfo, (View)mStatusbar);
        } 
        if (navAnim != null && sbAnim != null) {
            AnimatorSet set = new AnimatorSet();
            set.playTogether(navAnim, sbAnim);
            set.start();
        } else { 
            if(navAnim != null) {
                navAnim.start();
            } else if(sbAnim != null) {
                sbAnim.start();
            } 
        } 
    }