/
MainActivity.java
175 lines (152 loc) · 6.22 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package tattoo.gogo.app.gogo_android;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
private boolean isFabOpen;
private Animation fab_open;
private Animation fab_close;
private Animation rotate_forward;
private Animation rotate_backward;
@BindView(R.id.fab) FloatingActionButton fab;
@BindView(R.id.fl_new_tattoo) View newTattoo;
@BindView(R.id.fl_new_design) View newDesign;
@BindView(R.id.fl_new_dreadlocks) View newDreadlocks;
@BindView(R.id.fl_new_piercing) View newPiercing;
@BindView(R.id.fl_new_henna) View newHenna;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open);
fab_close = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_close);
rotate_forward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_forward);
rotate_backward = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_backward);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animateFAB();
//fabClicked(view);
}
});
newTattoo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateFAB();
getSupportFragmentManager().beginTransaction()
.addToBackStack("xyz")
.hide(getSupportFragmentManager().findFragmentByTag("welcome"))
.add(R.id.fragment_container, new NewTattooFragment(), "new tattoo")
.commit();
}
});
newPiercing.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateFAB();
getSupportFragmentManager().beginTransaction()
.addToBackStack("xyz")
.hide(getSupportFragmentManager().findFragmentByTag("welcome"))
.add(R.id.fragment_container, new NewPiercingFragment(), "new piercing")
.commit();
}
});
newDesign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateFAB();
getSupportFragmentManager().beginTransaction()
.addToBackStack("xyz")
.hide(getSupportFragmentManager().findFragmentByTag("welcome"))
.add(R.id.fragment_container, new NewDesignFragment(), "new design")
.commit();
}
});
newHenna.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateFAB();
getSupportFragmentManager().beginTransaction()
.addToBackStack("xyz")
.hide(getSupportFragmentManager().findFragmentByTag("welcome"))
.add(R.id.fragment_container, new NewHennaFragment(), "new henna")
.commit();
}
});
}
public void animateFAB() {
if (isFabOpen) {
fab.startAnimation(rotate_backward);
newTattoo.startAnimation(fab_close);
newTattoo.setClickable(false);
newHenna.startAnimation(fab_close);
newHenna.setClickable(false);
newDesign.startAnimation(fab_close);
newDesign.setClickable(false);
newPiercing.startAnimation(fab_close);
newPiercing.setClickable(false);
newDreadlocks.startAnimation(fab_close);
newDreadlocks.setClickable(false);
isFabOpen = false;
} else {
fab.startAnimation(rotate_forward);
newTattoo.startAnimation(fab_open);
newTattoo.setClickable(true);
newHenna.startAnimation(fab_open);
newHenna.setClickable(true);
newDesign.startAnimation(fab_open);
newDesign.setClickable(true);
newPiercing.startAnimation(fab_open);
newPiercing.setClickable(true);
newDreadlocks.startAnimation(fab_open);
newDreadlocks.setClickable(true);
isFabOpen = true;
}
}
public FloatingActionButton getFloatingActionButton() {
return (FloatingActionButton) findViewById(R.id.fab);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
if (isFabOpen) {
animateFAB();
} else {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animateFAB();
}
});
super.onBackPressed();
}
}
}