Search in sources :

Example 1 with SwipeCard

use of com.tmall.wireless.tangram3.structure.card.SwipeCard in project Tangram-Android by alibaba.

the class SwipeItemTouchListener method onTouchEvent.

@Override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
    mSwipeGestureDector.onTouchEvent(motionEvent);
    if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
        final boolean reachActionEdge = swipeType == SWIPING_HOR && (Math.abs(mDistanceX) > (mActionEdge > 0 ? mActionEdge : recyclerView.getWidth() / 3));
        boolean reachTabEdge = false;
        if (mSwipeCardRef != null && mSwipeCardRef.get() != null && swipeType == SWIPING_HOR) {
            SwipeCard swipeCard = mSwipeCardRef.get();
            if (swipeCard.getCurrentIndex() == 0 && mDistanceX > 0 || (swipeCard.getCurrentIndex() == swipeCard.getTotalPage() - 1) && mDistanceX < 0) {
                reachTabEdge = true;
            }
        }
        int direction = 1;
        if (swipeType == SWIPING_HOR) {
            direction = mDistanceX > 0 ? 1 : -1;
        } else if (swipeType == SWIPING_VER) {
            direction = mDistanceY > 0 ? 1 : -1;
        }
        resetViews(recyclerView, swipeType, reachActionEdge && !reachTabEdge, direction);
    }
}
Also used : SwipeCard(com.tmall.wireless.tangram3.structure.card.SwipeCard)

Example 2 with SwipeCard

use of com.tmall.wireless.tangram3.structure.card.SwipeCard in project Tangram-Android by alibaba.

the class SwipeItemTouchListener method resetViews.

private void resetViews(RecyclerView recyclerView, final int swipingType, final boolean reachActionEdge, final int direction) {
    if (enableAnim) {
        int contentWidth = recyclerView.getWidth();
        AnimatorSet animatorSet = new AnimatorSet();
        List<Animator> list = new ArrayList<>();
        String translation = "translationX";
        if (swipingType == SWIPING_VER) {
            translation = "translationY";
        }
        for (View view : mChildList) {
            ObjectAnimator animator;
            if (reachActionEdge) {
                animator = ObjectAnimator.ofFloat(view, translation, contentWidth * direction).setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new AccelerateInterpolator());
            } else {
                animator = ObjectAnimator.ofFloat(view, translation, 0).setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new DecelerateInterpolator());
            }
            list.add(animator);
        }
        animatorSet.playTogether(list);
        animatorSet.addListener(new Animator.AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (swipingType == SWIPING_HOR && reachActionEdge) {
                    if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                        SwipeCard swipeCard = mSwipeCardRef.get();
                        swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
                    }
                }
                mChildList.clear();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        animatorSet.start();
    } else {
        if (swipingType == SWIPING_HOR && reachActionEdge) {
            if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                SwipeCard swipeCard = mSwipeCardRef.get();
                swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
            }
        }
        mChildList.clear();
    }
    if (swipingType == SWIPING_VER) {
        if (pullFromEndListener != null) {
            if (mDistanceY < 0 && (mDistanceY < -pullFromEndListener.getPullEdge())) {
                pullFromEndListener.onAction();
            } else {
                pullFromEndListener.onReset();
            }
        }
    }
    swipeType = SWIPING_NONE;
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeCard(com.tmall.wireless.tangram3.structure.card.SwipeCard) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator)

Aggregations

SwipeCard (com.tmall.wireless.tangram3.structure.card.SwipeCard)2 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 ArrayList (java.util.ArrayList)1