|
32 | 32 |
|
33 | 33 | public class CircleMenuView extends FrameLayout implements View.OnClickListener {
|
34 | 34 |
|
| 35 | + public static class EventListener { |
| 36 | + public void onMenuOpenAnimationStart(@NonNull CircleMenuView view) {} |
| 37 | + public void onMenuOpenAnimationEnd(@NonNull CircleMenuView view) {} |
| 38 | + public void onMenuCloseAnimationStart(@NonNull CircleMenuView view) {} |
| 39 | + public void onMenuCloseAnimationEnd(@NonNull CircleMenuView view) {} |
| 40 | + public void onButtonClickAnimationStart(@NonNull CircleMenuView view, int buttonIndex) {} |
| 41 | + public void onButtonClickAnimationEnd(@NonNull CircleMenuView view, int buttonIndex) {} |
| 42 | + } |
| 43 | + |
| 44 | + private EventListener mListener; |
| 45 | + |
35 | 46 | private FloatingActionButton mMenuButton;
|
36 | 47 | private RingEffectView mRingView;
|
37 | 48 |
|
@@ -141,6 +152,30 @@ public void onClick(View view) {
|
141 | 152 |
|
142 | 153 | final Animator animation = mClosedState ? getOpenMenuAnimation() : getCloseMenuAnimation();
|
143 | 154 | animation.setDuration(mClosedState ? mDurationClose : mDurationOpen);
|
| 155 | + animation.addListener(new AnimatorListenerAdapter() { |
| 156 | + @Override |
| 157 | + public void onAnimationStart(Animator animation) { |
| 158 | + if (mListener != null) { |
| 159 | + if (mClosedState) { |
| 160 | + mListener.onMenuOpenAnimationStart(CircleMenuView.this); |
| 161 | + } else { |
| 162 | + mListener.onMenuCloseAnimationStart(CircleMenuView.this); |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + @Override |
| 167 | + public void onAnimationEnd(Animator animation) { |
| 168 | + animation.removeListener(this); |
| 169 | + if (mListener != null) { |
| 170 | + if (mClosedState) { |
| 171 | + mListener.onMenuOpenAnimationEnd(CircleMenuView.this); |
| 172 | + } else { |
| 173 | + mListener.onMenuCloseAnimationEnd(CircleMenuView.this); |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + }); |
| 178 | + |
144 | 179 | animation.start();
|
145 | 180 | }
|
146 | 181 | });
|
@@ -199,13 +234,27 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
|
199 | 234 | }
|
200 | 235 |
|
201 | 236 | @Override
|
202 |
| - public void onClick(View view) { |
| 237 | + public void onClick(final View view) { |
203 | 238 | if (mIsAnimating) {
|
204 | 239 | return;
|
205 | 240 | }
|
206 | 241 |
|
207 | 242 | final Animator click = getButtonClickAnimation((FloatingActionButton)view);
|
208 | 243 | click.setDuration(mDurationRing);
|
| 244 | + click.addListener(new AnimatorListenerAdapter() { |
| 245 | + @Override |
| 246 | + public void onAnimationStart(Animator animation) { |
| 247 | + if (mListener != null) { |
| 248 | + mListener.onButtonClickAnimationStart(CircleMenuView.this, mButtons.indexOf(view)); |
| 249 | + } |
| 250 | + } |
| 251 | + @Override |
| 252 | + public void onAnimationEnd(Animator animation) { |
| 253 | + if (mListener != null) { |
| 254 | + mListener.onButtonClickAnimationEnd(CircleMenuView.this, mButtons.indexOf(view)); |
| 255 | + } |
| 256 | + } |
| 257 | + }); |
209 | 258 | click.start();
|
210 | 259 | }
|
211 | 260 |
|
@@ -452,4 +501,12 @@ public float getDistance() {
|
452 | 501 | return mDistance;
|
453 | 502 | }
|
454 | 503 |
|
| 504 | + public void setEventListener(EventListener listener) { |
| 505 | + mListener = listener; |
| 506 | + } |
| 507 | + |
| 508 | + public EventListener getEventListener() { |
| 509 | + return mListener; |
| 510 | + } |
| 511 | + |
455 | 512 | }
|
0 commit comments