Skip to content

Commit 07eeca9

Browse files
committed
feat: animate text below navbar icons
1 parent 8b5ed75 commit 07eeca9

File tree

2 files changed

+103
-30
lines changed

2 files changed

+103
-30
lines changed

app/src/main/java/com/example/scanpal/MainActivity.java

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.content.IntentFilter;
7-
87
import android.os.Build;
98
import android.os.Bundle;
109
import android.util.Log;
1110
import android.view.View;
11+
import android.view.animation.AccelerateDecelerateInterpolator;
12+
import android.widget.TextView;
1213

1314
import androidx.activity.result.ActivityResultLauncher;
1415
import androidx.annotation.RequiresApi;
@@ -31,43 +32,40 @@
3132
public class MainActivity extends AppCompatActivity {
3233

3334
private FloatingActionButton buttonScan, buttonChat, buttonProfile, buttonYourEvents, buttonHomepage;
35+
private TextView textHome, textEvents, textChat, textProfile;
3436
private NavController navController;
3537
private View appBar;
3638
private ActivityResultLauncher<ScanOptions> qrCodeScanner;
3739
private QrScannerController qrScannerController;
3840
private int buttonChatColorFlag = -1; // Default color
41+
3942
private final BroadcastReceiver receiver = new BroadcastReceiver() {
4043
@Override
4144
public void onReceive(Context context, Intent intent) {
4245
String message = intent.getStringExtra("message");
4346
Log.d("msg", "broadcast received MAIN: ");
44-
4547
updateUI(message);
4648
}
4749
};
4850

49-
5051
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
5152
@Override
5253
protected void onCreate(Bundle savedInstanceState) {
5354

5455
SplashScreen.installSplashScreen(this); // show splash screen
5556

5657
super.onCreate(savedInstanceState);
57-
5858
setContentView(R.layout.nav_host);
5959
setNavbarVisibility(false);
6060
initializeViews();
6161
setupButtonListeners();
6262
setupNavController();
6363

64-
6564
//receiver notif stuff
6665
IntentFilter filter = new IntentFilter("com.example.scanpal.MESSAGE_RECEIVED");
67-
6866
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
6967
Log.d("msg", "build good");
70-
registerReceiver(receiver, filter,Context.RECEIVER_EXPORTED);
68+
registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
7169
}
7270

7371

@@ -77,7 +75,6 @@ protected void onCreate(Bundle savedInstanceState) {
7775
new UserFetchCallback() {
7876
@Override
7977
public void onSuccess(User user) {
80-
// Continue
8178
}
8279

8380
@Override
@@ -86,11 +83,25 @@ public void onError(Exception e) {
8683
}
8784
}
8885
);
89-
9086
}
9187

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+
}
92104

93-
// Sets up navigation
94105
private void setupNavController() {
95106
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
96107
.findFragmentById(R.id.nav_host_fragment);
@@ -103,24 +114,23 @@ private void setupNavController() {
103114
buttonYourEvents.setColorFilter(getResources().getColor(R.color.default_icon_tint));
104115
buttonHomepage.setColorFilter(getResources().getColor(R.color.default_icon_tint));
105116

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));
112119
}
113120

114-
115121
if (destination.getId() == R.id.notificationsFragment) {
116122
buttonChatColorFlag = -1;
117123
buttonChat.setColorFilter(getResources().getColor(R.color.button_default));
124+
animateText(textChat, textHome, textEvents, textProfile);
118125
} else if (destination.getId() == R.id.profile_fragment) {
119126
buttonProfile.setColorFilter(getResources().getColor(R.color.button_default));
127+
animateText(textProfile, textHome, textEvents, textChat);
120128
} else if (destination.getId() == R.id.yourEvents) {
121129
buttonYourEvents.setColorFilter(getResources().getColor(R.color.button_default));
130+
animateText(textEvents, textHome, textChat, textProfile);
122131
} else if (destination.getId() == R.id.eventsPage) {
123132
buttonHomepage.setColorFilter(getResources().getColor(R.color.button_default));
133+
animateText(textHome, textEvents, textChat, textProfile);
124134
}
125135
});
126136

@@ -144,13 +154,16 @@ private void initializeViews() {
144154
buttonYourEvents = findViewById(R.id.button_your_events);
145155
buttonHomepage = findViewById(R.id.button_homepage);
146156
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);
147161
}
148162

149163
/**
150164
* Sets up listeners for the various buttons in the profile fragment.
151165
*/
152166
private void setupButtonListeners() {
153-
154167
AttendeeController attendeeController = new AttendeeController(FirebaseFirestore.getInstance());
155168
qrScannerController = new QrScannerController(this, attendeeController);
156169

@@ -176,14 +189,13 @@ public void onError(String errorMessage) {
176189
}
177190
});
178191

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+
});
181196
buttonChat.setOnClickListener(v -> navController.navigate(R.id.notificationsFragment));
182-
183197
buttonProfile.setOnClickListener(v -> navController.navigate(R.id.profile_fragment));
184-
185198
buttonYourEvents.setOnClickListener(v -> navController.navigate(R.id.yourEvents));
186-
187199
buttonHomepage.setOnClickListener(v -> navController.navigate(R.id.eventsPage));
188200
}
189201

@@ -195,6 +207,10 @@ public void setNavbarVisibility(boolean isVisible) {
195207
if (buttonYourEvents != null) buttonYourEvents.setVisibility(visibility);
196208
if (buttonHomepage != null) buttonHomepage.setVisibility(visibility);
197209
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);
198214
}
199215

200216
@Override
@@ -206,17 +222,14 @@ protected void onDestroy() {
206222

207223
/**
208224
* Method accordingly updates the UI based on Received cloud messages
225+
*
209226
* @param message the message that was sent
210227
*/
211228
private void updateUI(String message) {
212-
213229
if (buttonChat != null) {
214230
Log.d("msg", "MAKE RED: " + "message.getNotification().getBody())");
215-
216231
buttonChatColorFlag = 0;
217232
buttonChat.setColorFilter(getResources().getColor(R.color.button_alert));
218-
219233
}
220-
221234
}
222-
}
235+
}

app/src/main/res/layout/nav_host.xml

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
app:layout_constraintTop_toTopOf="parent"
1515
app:navGraph="@navigation/nav_graph" />
1616

17-
1817
<androidx.appcompat.widget.Toolbar
1918
android:id="@+id/app_bar"
2019
android:layout_width="match_parent"
@@ -38,6 +37,7 @@
3837
app:layout_constraintEnd_toEndOf="@+id/app_bar"
3938
app:layout_constraintStart_toStartOf="@+id/app_bar"
4039
app:layout_constraintTop_toTopOf="@+id/app_bar"
40+
app:layout_constraintVertical_bias="0"
4141
app:srcCompat="@drawable/camera_icon"
4242
app:tint="@color/white" />
4343

@@ -52,9 +52,24 @@
5252
app:layout_constraintBottom_toBottomOf="@id/app_bar"
5353
app:layout_constraintStart_toEndOf="@+id/button_scan"
5454
app:layout_constraintTop_toTopOf="@+id/app_bar"
55+
app:layout_constraintVertical_bias="0.15"
5556
app:srcCompat="@drawable/notification_icon"
5657
app:tint="#7f7f7f" />
5758

59+
<TextView
60+
android:id="@+id/text_chat"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:layout_marginTop="-5dp"
64+
android:alpha="0"
65+
android:elevation="15dp"
66+
android:text="Alerts"
67+
android:textColor="#7f7f7f"
68+
android:textSize="12sp"
69+
app:layout_constraintEnd_toEndOf="@id/button_chat"
70+
app:layout_constraintStart_toStartOf="@id/button_chat"
71+
app:layout_constraintTop_toBottomOf="@id/button_chat" />
72+
5873
<com.google.android.material.floatingactionbutton.FloatingActionButton
5974
android:id="@+id/button_profile"
6075
android:layout_width="wrap_content"
@@ -66,9 +81,24 @@
6681
app:layout_constraintBottom_toBottomOf="@+id/app_bar"
6782
app:layout_constraintStart_toEndOf="@+id/button_chat"
6883
app:layout_constraintTop_toTopOf="@+id/app_bar"
84+
app:layout_constraintVertical_bias="0.15"
6985
app:srcCompat="@drawable/profile_icon"
7086
app:tint="#7f7f7f" />
7187

88+
<TextView
89+
android:id="@+id/text_profile"
90+
android:layout_width="wrap_content"
91+
android:layout_height="wrap_content"
92+
android:layout_marginTop="-5dp"
93+
android:alpha="0"
94+
android:elevation="15dp"
95+
android:text="Profile"
96+
android:textColor="#7f7f7f"
97+
android:textSize="12sp"
98+
app:layout_constraintEnd_toEndOf="@id/button_profile"
99+
app:layout_constraintStart_toStartOf="@id/button_profile"
100+
app:layout_constraintTop_toBottomOf="@id/button_profile" />
101+
72102
<com.google.android.material.floatingactionbutton.FloatingActionButton
73103
android:id="@+id/button_your_events"
74104
android:layout_width="wrap_content"
@@ -80,9 +110,24 @@
80110
app:layout_constraintBottom_toBottomOf="@id/app_bar"
81111
app:layout_constraintEnd_toStartOf="@+id/button_scan"
82112
app:layout_constraintTop_toTopOf="@+id/app_bar"
113+
app:layout_constraintVertical_bias="0.15"
83114
app:srcCompat="@drawable/menu_fill"
84115
app:tint="#7f7f7f" />
85116

117+
<TextView
118+
android:id="@+id/text_your_events"
119+
android:layout_width="wrap_content"
120+
android:layout_height="wrap_content"
121+
android:layout_marginTop="-5dp"
122+
android:alpha="0"
123+
android:elevation="15dp"
124+
android:text="Events"
125+
android:textColor="#7f7f7f"
126+
android:textSize="12sp"
127+
app:layout_constraintEnd_toEndOf="@id/button_your_events"
128+
app:layout_constraintStart_toStartOf="@id/button_your_events"
129+
app:layout_constraintTop_toBottomOf="@id/button_your_events" />
130+
86131
<com.google.android.material.floatingactionbutton.FloatingActionButton
87132
android:id="@+id/button_homepage"
88133
android:layout_width="wrap_content"
@@ -94,7 +139,22 @@
94139
app:layout_constraintBottom_toBottomOf="@id/app_bar"
95140
app:layout_constraintEnd_toStartOf="@+id/button_your_events"
96141
app:layout_constraintTop_toTopOf="@+id/app_bar"
142+
app:layout_constraintVertical_bias="0.15"
97143
app:srcCompat="@drawable/home_icon"
98144
app:tint="#7f7f7f" />
99145

100-
</androidx.constraintlayout.widget.ConstraintLayout>
146+
<TextView
147+
android:id="@+id/text_homepage"
148+
android:layout_width="wrap_content"
149+
android:layout_height="wrap_content"
150+
android:layout_marginTop="-5dp"
151+
android:alpha="0"
152+
android:elevation="15dp"
153+
android:text="Home"
154+
android:textColor="#7f7f7f"
155+
android:textSize="12sp"
156+
app:layout_constraintEnd_toEndOf="@id/button_homepage"
157+
app:layout_constraintStart_toStartOf="@id/button_homepage"
158+
app:layout_constraintTop_toBottomOf="@id/button_homepage" />
159+
160+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)