Skip to content

Commit f108949

Browse files
committed
Merge pull request #46 from robertoestivill/animator_callbacks
Exposing AnimatorListener methods in AnimationComposer fix #45
2 parents 681d4dc + 109729d commit f108949

File tree

1 file changed

+47
-0
lines changed
  • library/src/main/java/com/daimajia/androidanimations/library

1 file changed

+47
-0
lines changed

library/src/main/java/com/daimajia/androidanimations/library/YoYo.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ public static AnimationComposer with(BaseViewAnimator animator) {
6262
return new AnimationComposer(animator);
6363
}
6464

65+
public interface AnimatorCallback {
66+
public void call(Animator animator);
67+
}
68+
69+
private static class EmptyAnimatorListener implements Animator.AnimatorListener {
70+
@Override
71+
public void onAnimationStart(Animator animation){}
72+
@Override
73+
public void onAnimationEnd(Animator animation){}
74+
@Override
75+
public void onAnimationCancel(Animator animation){}
76+
@Override
77+
public void onAnimationRepeat(Animator animation){}
78+
}
79+
6580
public static final class AnimationComposer {
6681

6782
private List<Animator.AnimatorListener> callbacks = new ArrayList<Animator.AnimatorListener>();
@@ -101,6 +116,38 @@ public AnimationComposer withListener(Animator.AnimatorListener listener) {
101116
return this;
102117
}
103118

119+
public AnimationComposer onStart(final AnimatorCallback callback) {
120+
callbacks.add(new EmptyAnimatorListener() {
121+
@Override
122+
public void onAnimationStart(Animator animation) { callback.call(animation); }
123+
});
124+
return this;
125+
}
126+
127+
public AnimationComposer onEnd(final AnimatorCallback callback) {
128+
callbacks.add(new EmptyAnimatorListener() {
129+
@Override
130+
public void onAnimationEnd(Animator animation) { callback.call(animation); }
131+
});
132+
return this;
133+
}
134+
135+
public AnimationComposer onCancel(final AnimatorCallback callback) {
136+
callbacks.add(new EmptyAnimatorListener() {
137+
@Override
138+
public void onAnimationCancel(Animator animation) { callback.call(animation); }
139+
});
140+
return this;
141+
}
142+
143+
public AnimationComposer onRepeat(final AnimatorCallback callback) {
144+
callbacks.add(new EmptyAnimatorListener() {
145+
@Override
146+
public void onAnimationRepeat(Animator animation) { callback.call(animation); }
147+
});
148+
return this;
149+
}
150+
104151
public YoYoString playOn(View target) {
105152
this.target = target;
106153
return new YoYoString(new YoYo(this).play(), this.target);

0 commit comments

Comments
 (0)