Skip to content

Commit 8b557d1

Browse files
committed
remove menu views after disapper
1 parent bfbe8c5 commit 8b557d1

2 files changed

Lines changed: 23 additions & 26 deletions

File tree

androidarcmenu/src/main/java/com/hackplan/androidarcmenu/AnimatorUtils.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void clearFocusChild(ViewGroup viewGroup, int index) {
6767
animSet.start();
6868
}
6969

70-
static void showMenu(ViewGroup viewGroup, Point touchPoint, Animator.AnimatorListener listener) {
70+
static void showMenu(ViewGroup viewGroup, Point touchPoint, AnimatorListenerAdapter listener) {
7171
List<Animator> animList = new ArrayList<>();
7272

7373
for (int i = 0, len = viewGroup.getChildCount(); i < len; i++) {
@@ -101,7 +101,7 @@ public void onAnimationEnd(Animator animation) {
101101
});
102102
animSet.start();
103103
}
104-
static void openMenu(ViewGroup viewGroup, int openIndex) {
104+
static void openMenu(ViewGroup viewGroup, int openIndex, AnimatorListenerAdapter endListener) {
105105
List<Animator> animList = new ArrayList<>();
106106

107107
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
@@ -115,12 +115,7 @@ static void openMenu(ViewGroup viewGroup, int openIndex) {
115115
animSet.setDuration(ANIM_DURATION);
116116
animSet.setInterpolator(new AnticipateInterpolator());
117117
animSet.playTogether(animList);
118-
animSet.addListener(new AnimatorListenerAdapter() {
119-
@Override
120-
public void onAnimationEnd(Animator animation) {
121-
super.onAnimationEnd(animation);
122-
}
123-
});
118+
animSet.addListener(endListener);
124119
animSet.start();
125120
}
126121

androidarcmenu/src/main/java/com/hackplan/androidarcmenu/ArcMenuLayout.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.hackplan.androidarcmenu;
22

33
import android.animation.Animator;
4+
import android.animation.AnimatorListenerAdapter;
45
import android.content.Context;
56
import android.graphics.Canvas;
67
import android.graphics.Point;
@@ -21,7 +22,7 @@
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

Comments
 (0)