Example usage for android.support.v4.view ViewPropertyAnimatorListener ViewPropertyAnimatorListener

List of usage examples for android.support.v4.view ViewPropertyAnimatorListener ViewPropertyAnimatorListener

Introduction

In this page you can find the example usage for android.support.v4.view ViewPropertyAnimatorListener ViewPropertyAnimatorListener.

Prototype

ViewPropertyAnimatorListener

Source Link

Usage

From source file:com.test.xujixiao.xjx.widget.view.swipe_listview.SwipeListViewTouchListener.java

/**
 * Create dismiss animation/*w w  w . jav  a2s  .  c  o  m*/
 *
 * @param view      affected view
 * @param swap      If will change state. If is "false" returns to the original position
 * @param swapRight If swap is true, this parameter tells if move is to the right or left
 * @param position  Position of list
 */
private void generateDismissAnimate(final View view, final boolean swap, final boolean swapRight,
        final int position) {
    int moveTo = 0;
    if (opened.get(position)) {
        if (!swap) {
            moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset)
                    : (int) (-viewWidth + leftOffset);
        }
    } else {
        if (swap) {
            moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
        }
    }

    int alpha = 1;
    if (swap) {
        ++dismissAnimationRefCount;
        alpha = 0;
    }

    animate(view).translationX(moveTo).alpha(alpha).setDuration(animationTime)
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {

                }

                @Override
                public void onAnimationCancel(View view) {

                }

                @Override
                public void onAnimationEnd(View animation) {
                    if (swap) {
                        closeOpenedItems();
                        performDismiss(view, position, true);
                    }
                    resetCell();
                }
            });

}

From source file:com.tr4android.recyclerviewslideitem.SwipeItem.java

private void showUndoAction(final boolean show) {
    ViewCompat.setAlpha(mSwipeUndo, show ? 0 : 1);
    ViewCompat.setAlpha(mSwipeInfo, show ? 1 : 0);
    if (show)/*ww  w.j  ava 2  s. co  m*/
        mSwipeUndo.setVisibility(VISIBLE);
    if (!show)
        mSwipeInfo.setVisibility(VISIBLE);
    final ViewPropertyAnimatorCompat undoAnimation = ViewCompat.animate(mSwipeUndo);
    undoAnimation.setDuration(300).alpha(show ? 1 : 0).setListener(new ViewPropertyAnimatorListener() {
        @Override
        public void onAnimationStart(View view) {
        }

        @Override
        public void onAnimationEnd(View view) {
            undoAnimation.setListener(null);
            ViewCompat.setAlpha(view, show ? 1 : 0);
            if (!show)
                view.setVisibility(GONE);
        }

        @Override
        public void onAnimationCancel(View view) {
        }
    }).start();
    final ViewPropertyAnimatorCompat infoAnimation = ViewCompat.animate(mSwipeInfo);
    infoAnimation.setDuration(300).alpha(show ? 0 : 1).setListener(new ViewPropertyAnimatorListener() {
        @Override
        public void onAnimationStart(View view) {
        }

        @Override
        public void onAnimationEnd(View view) {
            infoAnimation.setListener(null);
            ViewCompat.setAlpha(view, show ? 0 : 1);
            if (show)
                view.setVisibility(GONE);
        }

        @Override
        public void onAnimationCancel(View view) {
        }
    }).start();
}

From source file:com.test.xujixiao.xjx.widget.view.swipe_listview.SwipeListViewTouchListener.java

/**
 * Create reveal animation// www . j ava2 s. c  om
 *
 * @param view      affected view
 * @param swap      If will change state. If "false" returns to the original position
 * @param swapRight If swap is true, this parameter tells if movement is toward right or left
 * @param position  list position
 */
private void generateRevealAnimate(final View view, final boolean swap, final boolean swapRight,
        final int position) {
    int moveTo = 0;
    if (opened.get(position)) {
        if (!swap) {
            moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset)
                    : (int) (-viewWidth + leftOffset);
        }
    } else {
        if (swap) {
            moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
        }
    }

    animate(view).translationX(moveTo).setDuration(animationTime)
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {

                }

                @Override
                public void onAnimationCancel(View view) {

                }

                @Override
                public void onAnimationEnd(View animation) {
                    swipeListView.resetScrolling();
                    if (swap) {
                        boolean aux = !opened.get(position);
                        opened.set(position, aux);
                        if (aux) {
                            swipeListView.onOpened(position, swapRight);
                            openedRight.set(position, swapRight);
                        } else {
                            swipeListView.onClosed(position, openedRight.get(position));
                        }
                    }
                    resetCell();
                }

            });
}

From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java

/**
 * Slide out a view to the right or left of the list. After the animation has finished, the
 * view will be dismissed by calling {@link #performDismiss(android.view.View, android.view.View, int)}.
 *
 * @param view        The view, that should be slided out.
 * @param childView   The whole view of the list item.
 * @param position    The item position of the item.
 * @param toRightSide Whether it should slide out to the right side.
 *///from   ww  w  .j  av a2 s . co  m
private void slideOutView(final View view, final View childView, final int position, boolean toRightSide) {

    // Only start new animation, if this view isn't already animated (too fast swiping bug)
    synchronized (mAnimationLock) {
        if (mAnimatedViews.contains(view)) {
            return;
        }
        ++mDismissAnimationRefCount;
        mAnimatedViews.add(view);
    }

    ViewCompat.animate(view).translationX(toRightSide ? mViewWidth : -mViewWidth).alpha(0)
            .setDuration(mAnimationTime).setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {
                }

                @Override
                public void onAnimationEnd(View view) {
                    performDismiss(view, childView, position);
                }

                @Override
                public void onAnimationCancel(View view) {

                }
            });
}