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);
}
}
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;
}
Aggregations