|
@@ -34,28 +34,8 @@ public class FloatingActionButtonCoordinator {
|
34
|
34
|
collapsedFab.setOnClickListener(new View.OnClickListener() {
|
35
|
35
|
@Override
|
36
|
36
|
public void onClick(View v) {
|
37
|
|
- collapsedFab.animate()
|
38
|
|
- .alpha(0)
|
39
|
|
- .setDuration(crossFadeAnimationDuration)
|
40
|
|
- .rotation(90)
|
41
|
|
- .setListener(new AnimatorListenerAdapter() {
|
42
|
|
- @Override
|
43
|
|
- public void onAnimationEnd(Animator animation) {
|
44
|
|
- collapsedFab.setVisibility(View.GONE);
|
45
|
|
- }
|
46
|
|
- })
|
47
|
|
- .start();
|
48
|
|
- expendedFab.animate()
|
49
|
|
- .alpha(1)
|
50
|
|
- .setDuration(crossFadeAnimationDuration)
|
51
|
|
- .rotation(0)
|
52
|
|
- .setListener(new AnimatorListenerAdapter() {
|
53
|
|
- @Override
|
54
|
|
- public void onAnimationStart(Animator animation) {
|
55
|
|
- expendedFab.setVisibility(View.VISIBLE);
|
56
|
|
- }
|
57
|
|
- })
|
58
|
|
- .start();
|
|
37
|
+ hideCollapsed();
|
|
38
|
+ showExpended();
|
59
|
39
|
}
|
60
|
40
|
});
|
61
|
41
|
}
|
|
@@ -67,32 +47,50 @@ public class FloatingActionButtonCoordinator {
|
67
|
47
|
expendedFab.setOnClickListener(new View.OnClickListener() {
|
68
|
48
|
@Override
|
69
|
49
|
public void onClick(View v) {
|
70
|
|
- expendedFab.animate()
|
71
|
|
- .alpha(0)
|
72
|
|
- .setDuration(crossFadeAnimationDuration)
|
73
|
|
- .rotation(-90)
|
74
|
|
- .setListener(new AnimatorListenerAdapter() {
|
75
|
|
- @Override
|
76
|
|
- public void onAnimationEnd(Animator animation) {
|
77
|
|
- expendedFab.setVisibility(View.GONE);
|
78
|
|
- }
|
79
|
|
- })
|
80
|
|
- .start();
|
81
|
|
- collapsedFab.animate()
|
82
|
|
- .alpha(1)
|
83
|
|
- .setDuration(crossFadeAnimationDuration)
|
84
|
|
- .rotation(0)
|
85
|
|
- .setListener(new AnimatorListenerAdapter() {
|
86
|
|
- @Override
|
87
|
|
- public void onAnimationStart(Animator animation) {
|
88
|
|
- collapsedFab.setVisibility(View.VISIBLE);
|
89
|
|
- }
|
90
|
|
- })
|
91
|
|
- .start();
|
|
50
|
+ hideExpended();
|
|
51
|
+ showCollapsed();
|
92
|
52
|
}
|
93
|
53
|
});
|
94
|
54
|
}
|
95
|
55
|
|
|
56
|
+ private void hideCollapsed() {
|
|
57
|
+ animateFab(collapsedFab, 0, 90);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ private void showExpended() {
|
|
61
|
+ animateFab(expendedFab, 1, 0);
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ private void showCollapsed() {
|
|
65
|
+ animateFab(collapsedFab, 1, 0);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ private void hideExpended() {
|
|
69
|
+ animateFab(expendedFab, 0, -90);
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ private void animateFab(final FloatingActionButton fab, final int alpha, int rotation) {
|
|
73
|
+ fab.animate()
|
|
74
|
+ .alpha(alpha)
|
|
75
|
+ .setDuration(crossFadeAnimationDuration)
|
|
76
|
+ .rotation(rotation)
|
|
77
|
+ .setListener(new AnimatorListenerAdapter() {
|
|
78
|
+ @Override
|
|
79
|
+ public void onAnimationStart(Animator animation) {
|
|
80
|
+ if (fab.getVisibility() == View.GONE) {
|
|
81
|
+ fab.setVisibility(View.VISIBLE);
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Override
|
|
86
|
+ public void onAnimationEnd(Animator animation) {
|
|
87
|
+ fab.setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
|
|
88
|
+ }
|
|
89
|
+ })
|
|
90
|
+ .start();
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+
|
96
|
94
|
private FloatingActionButton createFab(Drawable icon) {
|
97
|
95
|
FloatingActionButton fab = new FloatingActionButton(parent.getContext());
|
98
|
96
|
fab.setImageDrawable(icon);
|
|
@@ -112,4 +110,8 @@ public class FloatingActionButtonCoordinator {
|
112
|
110
|
private void setStyle() {
|
113
|
111
|
|
114
|
112
|
}
|
|
113
|
+
|
|
114
|
+ public void show() {
|
|
115
|
+
|
|
116
|
+ }
|
115
|
117
|
}
|