4
4
import android .content .Context ;
5
5
import android .content .Intent ;
6
6
import android .content .IntentFilter ;
7
-
8
7
import android .os .Build ;
9
8
import android .os .Bundle ;
10
9
import android .util .Log ;
11
10
import android .view .View ;
11
+ import android .view .animation .AccelerateDecelerateInterpolator ;
12
+ import android .widget .TextView ;
12
13
13
14
import androidx .activity .result .ActivityResultLauncher ;
14
15
import androidx .annotation .RequiresApi ;
31
32
public class MainActivity extends AppCompatActivity {
32
33
33
34
private FloatingActionButton buttonScan , buttonChat , buttonProfile , buttonYourEvents , buttonHomepage ;
35
+ private TextView textHome , textEvents , textChat , textProfile ;
34
36
private NavController navController ;
35
37
private View appBar ;
36
38
private ActivityResultLauncher <ScanOptions > qrCodeScanner ;
37
39
private QrScannerController qrScannerController ;
38
40
private int buttonChatColorFlag = -1 ; // Default color
41
+
39
42
private final BroadcastReceiver receiver = new BroadcastReceiver () {
40
43
@ Override
41
44
public void onReceive (Context context , Intent intent ) {
42
45
String message = intent .getStringExtra ("message" );
43
46
Log .d ("msg" , "broadcast received MAIN: " );
44
-
45
47
updateUI (message );
46
48
}
47
49
};
48
50
49
-
50
51
@ RequiresApi (api = Build .VERSION_CODES .TIRAMISU )
51
52
@ Override
52
53
protected void onCreate (Bundle savedInstanceState ) {
53
54
54
55
SplashScreen .installSplashScreen (this ); // show splash screen
55
56
56
57
super .onCreate (savedInstanceState );
57
-
58
58
setContentView (R .layout .nav_host );
59
59
setNavbarVisibility (false );
60
60
initializeViews ();
61
61
setupButtonListeners ();
62
62
setupNavController ();
63
63
64
-
65
64
//receiver notif stuff
66
65
IntentFilter filter = new IntentFilter ("com.example.scanpal.MESSAGE_RECEIVED" );
67
-
68
66
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
69
67
Log .d ("msg" , "build good" );
70
- registerReceiver (receiver , filter ,Context .RECEIVER_EXPORTED );
68
+ registerReceiver (receiver , filter , Context .RECEIVER_EXPORTED );
71
69
}
72
70
73
71
@@ -77,7 +75,6 @@ protected void onCreate(Bundle savedInstanceState) {
77
75
new UserFetchCallback () {
78
76
@ Override
79
77
public void onSuccess (User user ) {
80
- // Continue
81
78
}
82
79
83
80
@ Override
@@ -86,11 +83,25 @@ public void onError(Exception e) {
86
83
}
87
84
}
88
85
);
89
-
90
86
}
91
87
88
+ // Set up navigation & navbar
89
+ private void animateText (TextView showText , TextView ... hideTexts ) {
90
+ showText .animate ()
91
+ .alpha (1f )
92
+ .setDuration (200 )
93
+ .setInterpolator (new AccelerateDecelerateInterpolator ())
94
+ .start ();
95
+
96
+ for (TextView text : hideTexts ) {
97
+ text .animate ()
98
+ .alpha (0f )
99
+ .setDuration (200 )
100
+ .setInterpolator (new AccelerateDecelerateInterpolator ())
101
+ .start ();
102
+ }
103
+ }
92
104
93
- // Sets up navigation
94
105
private void setupNavController () {
95
106
NavHostFragment navHostFragment = (NavHostFragment ) getSupportFragmentManager ()
96
107
.findFragmentById (R .id .nav_host_fragment );
@@ -103,24 +114,23 @@ private void setupNavController() {
103
114
buttonYourEvents .setColorFilter (getResources ().getColor (R .color .default_icon_tint ));
104
115
buttonHomepage .setColorFilter (getResources ().getColor (R .color .default_icon_tint ));
105
116
106
- if (buttonChatColorFlag == 0 ) {
107
- buttonChat .setColorFilter (getResources ().getColor (R .color .button_alert ));//keep red
108
- Log .d ("msg" , "Recreating main assets" );
109
-
110
- }else {
111
- buttonChat .setColorFilter (getResources ().getColor (R .color .default_icon_tint ));//keep red
117
+ if (buttonChatColorFlag == 0 ) {
118
+ buttonChat .setColorFilter (getResources ().getColor (R .color .button_alert ));
112
119
}
113
120
114
-
115
121
if (destination .getId () == R .id .notificationsFragment ) {
116
122
buttonChatColorFlag = -1 ;
117
123
buttonChat .setColorFilter (getResources ().getColor (R .color .button_default ));
124
+ animateText (textChat , textHome , textEvents , textProfile );
118
125
} else if (destination .getId () == R .id .profile_fragment ) {
119
126
buttonProfile .setColorFilter (getResources ().getColor (R .color .button_default ));
127
+ animateText (textProfile , textHome , textEvents , textChat );
120
128
} else if (destination .getId () == R .id .yourEvents ) {
121
129
buttonYourEvents .setColorFilter (getResources ().getColor (R .color .button_default ));
130
+ animateText (textEvents , textHome , textChat , textProfile );
122
131
} else if (destination .getId () == R .id .eventsPage ) {
123
132
buttonHomepage .setColorFilter (getResources ().getColor (R .color .button_default ));
133
+ animateText (textHome , textEvents , textChat , textProfile );
124
134
}
125
135
});
126
136
@@ -144,13 +154,16 @@ private void initializeViews() {
144
154
buttonYourEvents = findViewById (R .id .button_your_events );
145
155
buttonHomepage = findViewById (R .id .button_homepage );
146
156
appBar = findViewById (R .id .app_bar );
157
+ textHome = findViewById (R .id .text_homepage );
158
+ textEvents = findViewById (R .id .text_your_events );
159
+ textChat = findViewById (R .id .text_chat );
160
+ textProfile = findViewById (R .id .text_profile );
147
161
}
148
162
149
163
/**
150
164
* Sets up listeners for the various buttons in the profile fragment.
151
165
*/
152
166
private void setupButtonListeners () {
153
-
154
167
AttendeeController attendeeController = new AttendeeController (FirebaseFirestore .getInstance ());
155
168
qrScannerController = new QrScannerController (this , attendeeController );
156
169
@@ -176,14 +189,13 @@ public void onError(String errorMessage) {
176
189
}
177
190
});
178
191
179
- buttonScan .setOnClickListener (v -> qrCodeScanner .launch (QrScannerController .getOptions ()));
180
-
192
+ buttonScan .setOnClickListener (v -> {
193
+ animateText (textHome , textEvents , textChat , textProfile );
194
+ qrCodeScanner .launch (QrScannerController .getOptions ());
195
+ });
181
196
buttonChat .setOnClickListener (v -> navController .navigate (R .id .notificationsFragment ));
182
-
183
197
buttonProfile .setOnClickListener (v -> navController .navigate (R .id .profile_fragment ));
184
-
185
198
buttonYourEvents .setOnClickListener (v -> navController .navigate (R .id .yourEvents ));
186
-
187
199
buttonHomepage .setOnClickListener (v -> navController .navigate (R .id .eventsPage ));
188
200
}
189
201
@@ -195,6 +207,10 @@ public void setNavbarVisibility(boolean isVisible) {
195
207
if (buttonYourEvents != null ) buttonYourEvents .setVisibility (visibility );
196
208
if (buttonHomepage != null ) buttonHomepage .setVisibility (visibility );
197
209
if (appBar != null ) appBar .setVisibility (visibility );
210
+ if (textHome != null ) textHome .setVisibility (visibility );
211
+ if (textEvents != null ) textEvents .setVisibility (visibility );
212
+ if (textChat != null ) textChat .setVisibility (visibility );
213
+ if (textProfile != null ) textProfile .setVisibility (visibility );
198
214
}
199
215
200
216
@ Override
@@ -206,17 +222,14 @@ protected void onDestroy() {
206
222
207
223
/**
208
224
* Method accordingly updates the UI based on Received cloud messages
225
+ *
209
226
* @param message the message that was sent
210
227
*/
211
228
private void updateUI (String message ) {
212
-
213
229
if (buttonChat != null ) {
214
230
Log .d ("msg" , "MAKE RED: " + "message.getNotification().getBody())" );
215
-
216
231
buttonChatColorFlag = 0 ;
217
232
buttonChat .setColorFilter (getResources ().getColor (R .color .button_alert ));
218
-
219
233
}
220
-
221
234
}
222
- }
235
+ }
0 commit comments