|
|
@@ -30,6 +30,7 @@ public class FloatingActionButtonCoordinator {
|
|
30
|
30
|
private final int crossFadeAnimationDuration;
|
|
31
|
31
|
private final int actionSize;
|
|
32
|
32
|
final int margin = (int) ViewUtils.convertDpToPixel(16);
|
|
|
33
|
+ FloatingActionButtonAnimator fabAnimator;
|
|
33
|
34
|
private final ArrayList<FloatingActionButton> actions;
|
|
34
|
35
|
|
|
35
|
36
|
public FloatingActionButtonCoordinator(CoordinatorLayout parent) {
|
|
|
@@ -44,22 +45,19 @@ public class FloatingActionButtonCoordinator {
|
|
44
|
45
|
createCollapsedFab();
|
|
45
|
46
|
createExpendedFab();
|
|
46
|
47
|
setStyle();
|
|
47
|
|
- show();
|
|
48
|
|
- }
|
|
49
|
|
-
|
|
50
|
|
- public void remove() {
|
|
51
|
|
- remove(null);
|
|
|
48
|
+ fabAnimator = new FloatingActionButtonAnimator(collapsedFab, expendedFab, crossFadeAnimationDuration);
|
|
|
49
|
+ fabAnimator.show();
|
|
52
|
50
|
}
|
|
53
|
51
|
|
|
54
|
52
|
public void remove(@Nullable final Runnable onComplete) {
|
|
55
|
|
- if (parent.getChildCount() == 0) {
|
|
|
53
|
+ if (parent.getChildCount() == 0 || fabAnimator.isAnimating()) {
|
|
56
|
54
|
if (onComplete != null) {
|
|
57
|
55
|
onComplete.run();
|
|
58
|
56
|
}
|
|
59
|
57
|
return;
|
|
60
|
58
|
}
|
|
61
|
59
|
|
|
62
|
|
- removeFabFromScreen(expendedFab, new AnimatorListenerAdapter() {
|
|
|
60
|
+ fabAnimator.removeFabFromScreen(expendedFab, new AnimatorListenerAdapter() {
|
|
63
|
61
|
@Override
|
|
64
|
62
|
public void onAnimationEnd(Animator animation) {
|
|
65
|
63
|
removeAllViews();
|
|
|
@@ -68,29 +66,8 @@ public class FloatingActionButtonCoordinator {
|
|
68
|
66
|
}
|
|
69
|
67
|
}
|
|
70
|
68
|
});
|
|
71
|
|
- removeFabFromScreen(collapsedFab, null);
|
|
72
|
|
- removeActionsFromScreen();
|
|
73
|
|
- }
|
|
74
|
|
-
|
|
75
|
|
- private void removeActionsFromScreen() {
|
|
76
|
|
- for (FloatingActionButton action : actions) {
|
|
77
|
|
- action.animate()
|
|
78
|
|
- .alpha(0)
|
|
79
|
|
- .scaleX(0)
|
|
80
|
|
- .scaleY(0)
|
|
81
|
|
- .setDuration(crossFadeAnimationDuration)
|
|
82
|
|
- .start();
|
|
83
|
|
- }
|
|
84
|
|
- }
|
|
85
|
|
-
|
|
86
|
|
- private void removeFabFromScreen(FloatingActionButton fab, AnimatorListenerAdapter animationListener) {
|
|
87
|
|
- fab.animate()
|
|
88
|
|
- .alpha(0)
|
|
89
|
|
- .scaleX(0)
|
|
90
|
|
- .scaleY(0)
|
|
91
|
|
- .setDuration(crossFadeAnimationDuration)
|
|
92
|
|
- .setListener(animationListener)
|
|
93
|
|
- .start();
|
|
|
69
|
+ fabAnimator.removeFabFromScreen(collapsedFab, null);
|
|
|
70
|
+ fabAnimator.removeActionsFromScreen(actions);
|
|
94
|
71
|
}
|
|
95
|
72
|
|
|
96
|
73
|
private void removeAllViews() {
|
|
|
@@ -110,8 +87,8 @@ public class FloatingActionButtonCoordinator {
|
|
110
|
87
|
collapsedFab.setOnClickListener(new View.OnClickListener() {
|
|
111
|
88
|
@Override
|
|
112
|
89
|
public void onClick(View v) {
|
|
113
|
|
- hideCollapsed();
|
|
114
|
|
- showExpended();
|
|
|
90
|
+ fabAnimator.hideCollapsed();
|
|
|
91
|
+ fabAnimator.showExpended();
|
|
115
|
92
|
showActions();
|
|
116
|
93
|
}
|
|
117
|
94
|
});
|
|
|
@@ -125,8 +102,8 @@ public class FloatingActionButtonCoordinator {
|
|
125
|
102
|
expendedFab.setOnClickListener(new View.OnClickListener() {
|
|
126
|
103
|
@Override
|
|
127
|
104
|
public void onClick(View v) {
|
|
128
|
|
- hideExpended();
|
|
129
|
|
- showCollapsed();
|
|
|
105
|
+ fabAnimator.hideExpended();
|
|
|
106
|
+ fabAnimator.showCollapsed();
|
|
130
|
107
|
}
|
|
131
|
108
|
});
|
|
132
|
109
|
}
|
|
|
@@ -138,43 +115,6 @@ public class FloatingActionButtonCoordinator {
|
|
138
|
115
|
return fab;
|
|
139
|
116
|
}
|
|
140
|
117
|
|
|
141
|
|
- private void hideCollapsed() {
|
|
142
|
|
- animateFab(collapsedFab, 0, 90);
|
|
143
|
|
- }
|
|
144
|
|
-
|
|
145
|
|
- private void showExpended() {
|
|
146
|
|
- animateFab(expendedFab, 1, 0);
|
|
147
|
|
- }
|
|
148
|
|
-
|
|
149
|
|
- private void showCollapsed() {
|
|
150
|
|
- animateFab(collapsedFab, 1, 0);
|
|
151
|
|
- }
|
|
152
|
|
-
|
|
153
|
|
- private void hideExpended() {
|
|
154
|
|
- animateFab(expendedFab, 0, -90);
|
|
155
|
|
- }
|
|
156
|
|
-
|
|
157
|
|
- private void animateFab(final FloatingActionButton fab, final int alpha, int rotation) {
|
|
158
|
|
- fab.animate()
|
|
159
|
|
- .alpha(alpha)
|
|
160
|
|
- .setDuration(crossFadeAnimationDuration)
|
|
161
|
|
- .rotation(rotation)
|
|
162
|
|
- .setListener(new AnimatorListenerAdapter() {
|
|
163
|
|
- @Override
|
|
164
|
|
- public void onAnimationStart(Animator animation) {
|
|
165
|
|
- if (fab.getVisibility() == View.GONE) {
|
|
166
|
|
- fab.setVisibility(View.VISIBLE);
|
|
167
|
|
- }
|
|
168
|
|
- }
|
|
169
|
|
-
|
|
170
|
|
- @Override
|
|
171
|
|
- public void onAnimationEnd(Animator animation) {
|
|
172
|
|
- fab.setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
|
|
173
|
|
- }
|
|
174
|
|
- })
|
|
175
|
|
- .start();
|
|
176
|
|
- }
|
|
177
|
|
-
|
|
178
|
118
|
private CoordinatorLayout.LayoutParams createFabLayoutParams() {
|
|
179
|
119
|
final CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
|
|
180
|
120
|
lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
|
|
|
@@ -189,17 +129,6 @@ public class FloatingActionButtonCoordinator {
|
|
189
|
129
|
expendedFab.setBackgroundTintList(ColorStateList.valueOf(params.backgroundColor.getColor()));
|
|
190
|
130
|
}
|
|
191
|
131
|
|
|
192
|
|
- private void show() {
|
|
193
|
|
- collapsedFab.setScaleX(0);
|
|
194
|
|
- collapsedFab.setScaleY(0);
|
|
195
|
|
- collapsedFab.animate()
|
|
196
|
|
- .alpha(1)
|
|
197
|
|
- .scaleX(1)
|
|
198
|
|
- .scaleY(1)
|
|
199
|
|
- .setDuration(crossFadeAnimationDuration)
|
|
200
|
|
- .start();
|
|
201
|
|
- }
|
|
202
|
|
-
|
|
203
|
132
|
private void showActions() {
|
|
204
|
133
|
if (actions.size() > 0) {
|
|
205
|
134
|
return;
|