@Override public boolean animateExit(@NonNull CardDraggableView draggableView, Direction direction, int duration) { resetCard(shuffle.getDraggableView(1), duration); return super.animateExit(draggableView, direction, duration); }
public void updateViewsPositions(float percentX, float percentY) { if (shuffle != null) { final ShuffleSettings shuffleSettings = shuffle.getShuffleSettings(); float percent = shuffleSettings.isVertical() ? percentY : percentX; int numberOfCards = shuffleSettings.getNumberOfDisplayedCards(); for (int i = 1; i < numberOfCards; ++i) { DraggableView view = shuffle.getDraggableView(i); float myScale = shuffleSettings.getScaleForPosition(i); float nextScale = shuffleSettings.getScaleForPosition(i - 1); float percentAbs = myScale + (nextScale - myScale) * Math.abs(percent); ViewCompat.setScaleX(view, percentAbs); ViewCompat.setScaleY(view, percentAbs); float myTranslationY = shuffleSettings.getTranslationYForPosition(i); if (shuffleSettings.isStackFromTop()) { myTranslationY *= -1; } float nextTranslationY = shuffleSettings.getTranslationYForPosition(i - 1); if (shuffleSettings.isStackFromTop()) { nextTranslationY *= -1; } float translationY = myTranslationY - Math.abs(percent) * (myTranslationY - nextTranslationY); ViewCompat.setTranslationY(view, translationY); float myTranslationX = shuffleSettings.getTranslationXForPosition(i); float nextTranslationX = shuffleSettings.getTranslationXForPosition(i - 1); float translationX = myTranslationX - Math.abs(percent) * (myTranslationX - nextTranslationX); ViewCompat.setTranslationX(view, translationX); } } }
@Override public void update(CardDraggableView draggableViewFront, float percentX, float percentY) { CardDraggableView draggableViewBottom = shuffle.getDraggableView(1); if (percentX <= 0) { draggableViewBottom.setOverlayLeftAlpha(1f); draggableViewBottom.setOverlayRightAlpha(0f); } else { draggableViewBottom.setOverlayLeftAlpha(0f); draggableViewBottom.setOverlayRightAlpha(1f); } float percent = Math.abs(percentX); percent = (float) Math.pow(percent, 10); percent = Math.min(0.09f, percent); if(percent == 0f){ ViewCompat.setAlpha(draggableViewBottom.getOverlayView(), 0f); ViewCompat.animate(draggableViewBottom.getContent()).withLayer().setDuration(100).alpha(1f); } else { ViewCompat.animate(draggableViewBottom.getContent()).cancel(); ViewCompat.setAlpha(draggableViewBottom.getContent(), percent); ViewCompat.setAlpha(draggableViewBottom.getOverlayView(), 1f); } } }