11package com .hackplan .androidarcmenu ;
22
33import android .animation .Animator ;
4+ import android .animation .AnimatorListenerAdapter ;
45import android .content .Context ;
56import android .graphics .Canvas ;
67import android .graphics .Point ;
2122 * Created by Dacer on 12/11/2016.
2223 */
2324
24- public class ArcMenuLayout extends ViewGroup implements Animator . AnimatorListener {
25+ public class ArcMenuLayout extends ViewGroup {
2526 private Point touchPoint = new Point ();
2627 private final Rect mScreenRect = new Rect ();
2728 private Rect tempRect = new Rect ();
@@ -99,7 +100,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
99100 (int )(yEnd + child .getMeasuredHeight ()/2 ));
100101 }
101102 }
102- AnimatorUtils .showMenu (this , touchPoint , this );
103+ AnimatorUtils .showMenu (this , touchPoint , animListener );
103104 }
104105
105106 private int lastFocusIndex = -1 ;
@@ -113,8 +114,8 @@ public boolean onTouchEvent(MotionEvent event) {
113114 case MotionEvent .ACTION_CANCEL :
114115 if (!show ) break ;
115116 if (lastFocusIndex != -1 ) {
116- AnimatorUtils .openMenu (this , lastFocusIndex );
117117 show = false ;
118+ AnimatorUtils .openMenu (this , lastFocusIndex , animListener );
118119 if (onClickBtnListener != null ) {
119120 View clickedView = getChildAt (lastFocusIndex );
120121 onClickBtnListener .onClickArcMenu (clickedView , (int )clickedView .getTag ());
@@ -170,23 +171,24 @@ public float dpToPx(float dipValue) {
170171 }
171172
172173 private boolean animFinished = true ;
173- @ Override
174- public void onAnimationStart (Animator animation ) {
175- animFinished = false ;
176- }
177174
178- @ Override
179- public void onAnimationEnd (Animator animation ) {
180- animFinished = true ;
181- }
175+ private AnimatorListenerAdapter animListener = new AnimatorListenerAdapter () {
182176
183- @ Override
184- public void onAnimationCancel (Animator animation ) {
185- animFinished = true ;
186- }
177+ @ Override
178+ public void onAnimationStart (Animator animation ) {
179+ animFinished = false ;
180+ }
187181
188- @ Override
189- public void onAnimationRepeat (Animator animation ) {
182+ @ Override
183+ public void onAnimationEnd (Animator animation ) {
184+ animFinished = true ;
185+ if (!show ) removeAllViews ();
186+ }
187+
188+ @ Override
189+ public void onAnimationCancel (Animator animation ) {
190+ animFinished = true ;
191+ }
192+ };
190193
191- }
192194}
0 commit comments