Skip to content

Commit 877221c

Browse files
authored
Merge pull request yuyakaido#87 from katsuya-yamada-eureka/patch_2_overlay_alpha_animation
overlay run with alpha animation
2 parents c837977 + 53ed8fd commit 877221c

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,27 @@ public void performSwipe(Point point, final Animator.AnimatorListener listener)
261261
.start();
262262
}
263263

264-
public void performSwipe(SwipeDirection direction, AnimatorSet set, final Animator.AnimatorListener listener) {
265-
if (direction == SwipeDirection.Left) {
264+
public void performSwipe(SwipeDirection direction, AnimatorSet set, AnimatorSet overlayAnimatorSet, final Animator.AnimatorListener listener) {
265+
boolean showOverlay;
266+
if (showOverlay = direction == SwipeDirection.Left) {
266267
getTopView().showLeftOverlay();
267-
getTopView().setOverlayAlpha(1f);
268-
} else if (direction == SwipeDirection.Right) {
268+
} else if (showOverlay = direction == SwipeDirection.Right) {
269269
getTopView().showRightOverlay();
270-
getTopView().setOverlayAlpha(1f);
271-
} else if (direction == SwipeDirection.Bottom){
270+
} else if (showOverlay = direction == SwipeDirection.Bottom){
272271
getTopView().showBottomOverlay();
273-
getTopView().setOverlayAlpha(1f);
274-
} else if (direction == SwipeDirection.Top){
272+
} else if (showOverlay = direction == SwipeDirection.Top){
275273
getTopView().showTopOverlay();
276-
getTopView().setOverlayAlpha(1f);
274+
} else {
275+
showOverlay = false;
276+
}
277+
if(showOverlay) {
278+
if(overlayAnimatorSet != null) {
279+
getTopView().setOverlayAlpha(overlayAnimatorSet);
280+
} else {
281+
getTopView().setOverlayAlpha(1f);
282+
}
277283
}
284+
278285
set.addListener(listener);
279286
set.setInterpolator(new TimeInterpolator() {
280287
@Override
@@ -476,8 +483,12 @@ public void onAnimationEnd(Animator animator) {
476483
}
477484

478485
public void swipe(final SwipeDirection direction, AnimatorSet set) {
486+
swipe(direction, set, null);
487+
}
488+
489+
public void swipe(final SwipeDirection direction, AnimatorSet cardAnimatorSet, AnimatorSet overlayAnimatorSet) {
479490
executePreSwipeTask();
480-
performSwipe(direction, set, new AnimatorListenerAdapter() {
491+
performSwipe(direction, cardAnimatorSet, overlayAnimatorSet, new AnimatorListenerAdapter() {
481492
@Override
482493
public void onAnimationEnd(Animator animator) {
483494
executePostSwipeTask(new Point(0, -2000), direction);

cardstackview/src/main/java/com/yuyakaido/android/cardstackview/internal/CardContainerView.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yuyakaido.android.cardstackview.internal;
22

3+
import android.animation.AnimatorSet;
34
import android.content.Context;
45
import android.graphics.Point;
56
import android.support.v4.view.MotionEventCompat;
@@ -306,6 +307,12 @@ public void setOverlay(int left, int right, int bottom, int top) {
306307
}
307308
}
308309

310+
public void setOverlayAlpha(AnimatorSet overlayAnimatorSet) {
311+
if(overlayAnimatorSet != null) {
312+
overlayAnimatorSet.start();
313+
}
314+
}
315+
309316
public void setOverlayAlpha(float alpha) {
310317
ViewCompat.setAlpha(overlayContainer, alpha);
311318
}

sample/src/main/java/com/yuyakaido/android/cardstackview/sample/MainActivity.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public void swipeLeft() {
208208
}
209209

210210
View target = cardStackView.getTopView();
211+
View targetOverlay = cardStackView.getTopView().getOverlayContainer();
211212

212213
ValueAnimator rotation = ObjectAnimator.ofPropertyValuesHolder(
213214
target, PropertyValuesHolder.ofFloat("rotation", -10f));
@@ -220,10 +221,15 @@ public void swipeLeft() {
220221
translateY.setStartDelay(100);
221222
translateX.setDuration(500);
222223
translateY.setDuration(500);
223-
AnimatorSet set = new AnimatorSet();
224-
set.playTogether(rotation, translateX, translateY);
224+
AnimatorSet cardAnimationSet = new AnimatorSet();
225+
cardAnimationSet.playTogether(rotation, translateX, translateY);
225226

226-
cardStackView.swipe(SwipeDirection.Left, set);
227+
ObjectAnimator overlayAnimator = ObjectAnimator.ofFloat(targetOverlay, "alpha", 0f, 1f);
228+
overlayAnimator.setDuration(200);
229+
AnimatorSet overlayAnimationSet = new AnimatorSet();
230+
overlayAnimationSet.playTogether(overlayAnimator);
231+
232+
cardStackView.swipe(SwipeDirection.Left, cardAnimationSet, overlayAnimationSet);
227233
}
228234

229235
public void swipeRight() {
@@ -233,6 +239,7 @@ public void swipeRight() {
233239
}
234240

235241
View target = cardStackView.getTopView();
242+
View targetOverlay = cardStackView.getTopView().getOverlayContainer();
236243

237244
ValueAnimator rotation = ObjectAnimator.ofPropertyValuesHolder(
238245
target, PropertyValuesHolder.ofFloat("rotation", 10f));
@@ -245,10 +252,15 @@ public void swipeRight() {
245252
translateY.setStartDelay(100);
246253
translateX.setDuration(500);
247254
translateY.setDuration(500);
248-
AnimatorSet set = new AnimatorSet();
249-
set.playTogether(rotation, translateX, translateY);
255+
AnimatorSet cardAnimationSet = new AnimatorSet();
256+
cardAnimationSet.playTogether(rotation, translateX, translateY);
257+
258+
ObjectAnimator overlayAnimator = ObjectAnimator.ofFloat(targetOverlay, "alpha", 0f, 1f);
259+
overlayAnimator.setDuration(200);
260+
AnimatorSet overlayAnimationSet = new AnimatorSet();
261+
overlayAnimationSet.playTogether(overlayAnimator);
250262

251-
cardStackView.swipe(SwipeDirection.Right, set);
263+
cardStackView.swipe(SwipeDirection.Right, cardAnimationSet, overlayAnimationSet);
252264
}
253265

254266
private void reverse() {

0 commit comments

Comments
 (0)