Example usage for android.view ViewPropertyAnimator setListener

List of usage examples for android.view ViewPropertyAnimator setListener

Introduction

In this page you can find the example usage for android.view ViewPropertyAnimator setListener.

Prototype

public ViewPropertyAnimator setListener(Animator.AnimatorListener listener) 

Source Link

Document

Sets a listener for events in the underlying Animators that run the property animations.

Usage

From source file:test.hugo.ui.ImgShowActivity.java

@Override
public void onBackPressed() {
    float screenWidth = getResources().getDisplayMetrics().widthPixels;
    float screenHeight = getResources().getDisplayMetrics().heightPixels;
    float endX = (screenWidth - mInit_width) / 2;
    float endY = (screenHeight - mInit_height) / 2;

    int currentItem = vp_data.getCurrentItem();
    Pair<Float, Float> pair = pairs[currentItem];
    ViewPropertyAnimator animator = vp_data.animate().setDuration(300).setInterpolator(interpolator)
            .scaleX(mInit_width / pair.first).scaleY(mInit_height / pair.second)
            .translationX(mLocation_left - endX).translationY(mLocation_top - endY);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        animator.withEndAction(new Runnable() {
            @Override//from w  ww  . j  a  v  a  2s  .c  o m
            public void run() {
                finish();
                overridePendingTransition(0, 0);
            }
        }).start();
    } else {
        animator.setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                finish();
                overridePendingTransition(0, 0);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        }).start();
    }
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        mChangeAnimations.add(changeInfo.oldHolder);
        final ViewPropertyAnimator oldViewAnim = view.animate().setDuration(getChangeDuration());
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
            @Override/*from  ww w. j  a  v a 2  s . co  m*/
            public void onAnimationStart(Animator animation) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                View mView = view;
                if (animation instanceof ObjectAnimator) {
                    mView = (View) ((ObjectAnimator) animation).getTarget();
                }
                oldViewAnim.setListener(null);
                mView.setAlpha(1);
                mView.setTranslationX(0);
                mView.setTranslationY(0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        mChangeAnimations.add(changeInfo.newHolder);
        final ViewPropertyAnimator newViewAnimation = newView.animate();
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1)
                .setListener(new VpaListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator view) {
                        dispatchChangeStarting(changeInfo.newHolder, false);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        newViewAnimation.setListener(null);
                        newView.setAlpha(1);
                        newView.setTranslationX(0);
                        newView.setTranslationY(0);
                        dispatchChangeFinished(changeInfo.newHolder, false);
                        mChangeAnimations.remove(changeInfo.newHolder);
                        dispatchFinishedWhenDone();
                    }
                }).start();
    }
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        view.animate().translationX(0);/*from   w w  w  .  j  a v a 2s . com*/
    }
    if (deltaY != 0) {
        view.animate().translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    mMoveAnimations.add(holder);
    final ViewPropertyAnimator animation = view.animate();
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            View mView = view;
            if (animator instanceof ObjectAnimator) {
                mView = (View) ((ObjectAnimator) animator).getTarget();
            }
            if (deltaX != 0) {
                mView.setTranslationX(0);
            }
            if (deltaY != 0) {
                mView.setTranslationY(0);
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}