Code example for AnimatorSet

Methods: addListener, play, start

0
                mNoRecentAppsView.getVisibility() == View.VISIBLE) {
            noRecentAppsFadeAnim = ObjectAnimator.ofFloat(mNoRecentAppsView, "alpha",
                    mContentView.getAlpha(), appearing ? 1.0f : 0.0f);
            noRecentAppsFadeAnim.setInterpolator(appearing
                    ? new android.view.animation.AccelerateInterpolator(1.0f)
                    : new android.view.animation.DecelerateInterpolator(1.0f));
            noRecentAppsFadeAnim.setDuration(appearing ? OPEN_DURATION : CLOSE_DURATION);
        } 
 
        mContentAnim = new AnimatorSet();
        final Builder builder = mContentAnim.play(fadeAnim).with(posAnim);
 
        if (noRecentAppsFadeAnim != null) {
            builder.with(noRecentAppsFadeAnim);
        } 
 
        if (appearing) {
            Drawable background = mScrimView.getBackground();
            if (background != null) {
                Animator bgAnim = ObjectAnimator.ofInt(background,
                    "alpha", appearing ? 0 : 255, appearing ? 255 : 0);
                bgAnim.setDuration(appearing ? SCRIM_DURATION : CLOSE_DURATION);
                builder.with(bgAnim);
            } 
        } else { 
            final Resources res = mRootView.getResources();
            boolean isTablet = res.getBoolean(R.bool.config_recents_interface_for_tablets);
            if (!isTablet) {
                View recentsTransitionBackground =
                        mRootView.findViewById(R.id.recents_transition_background);
                recentsTransitionBackground.setVisibility(View.VISIBLE);
                Drawable bgDrawable = new ColorDrawable(0xFF000000);
                recentsTransitionBackground.setBackground(bgDrawable);
                Animator bgAnim = ObjectAnimator.ofInt(bgDrawable, "alpha", 0, 255);
                bgAnim.setDuration(CLOSE_DURATION);
                bgAnim.setInterpolator(new android.view.animation.AccelerateInterpolator(1f));
                builder.with(bgAnim);
            } 
        } 
        mContentAnim.addListener(this);
        if (mListener != null) {
            mContentAnim.addListener(mListener);
        }