Skip to content

Commit fc0e604

Browse files
Merge pull request #39 from D4rK7355608/codex/add-new-lessons-to-the-app
Add Bottom Navigation lesson
2 parents 4e230ad + 586a2c5 commit fc0e604

File tree

10 files changed

+169
-0
lines changed

10 files changed

+169
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@
311311
android:exported="false"
312312
android:label="@string/rating_bar"
313313
android:parentActivityName=".ui.screens.android.lessons.reviews.ratingbar.RatingBarActivity" />
314+
<activity
315+
android:name=".ui.screens.android.lessons.navigation.bottomnavigation.BottomNavigationActivity"
316+
android:exported="false"
317+
android:label="@string/bottom_navigation"
318+
android:parentActivityName=".ui.screens.android.lessons.navigation.bottomnavigation.BottomNavigationActivity" />
314319

315320
<service
316321
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.d4rk.androidtutorials.java.ui.screens.android.lessons.navigation.bottomnavigation;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.os.Handler;
6+
7+
import androidx.appcompat.app.AppCompatActivity;
8+
import com.d4rk.androidtutorials.java.R;
9+
10+
import com.d4rk.androidtutorials.java.databinding.ActivityBottomNavigationBinding;
11+
import com.d4rk.androidtutorials.java.ui.screens.android.CodeActivity;
12+
import com.d4rk.androidtutorials.java.utils.EdgeToEdgeDelegate;
13+
14+
public class BottomNavigationActivity extends AppCompatActivity {
15+
private final Handler handler = new Handler();
16+
private ActivityBottomNavigationBinding binding;
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
binding = ActivityBottomNavigationBinding.inflate(getLayoutInflater());
22+
setContentView(binding.getRoot());
23+
24+
EdgeToEdgeDelegate edgeToEdgeDelegate = new EdgeToEdgeDelegate(this);
25+
edgeToEdgeDelegate.applyEdgeToEdgeBottomBar(binding.container, binding.bottomNav);
26+
27+
binding.bottomNav.setOnItemSelectedListener(item -> {
28+
binding.textView.setText(getString(R.string.selected) + " " + item.getTitle());
29+
return true;
30+
});
31+
32+
binding.floatingButtonShowSyntax.setOnClickListener(v -> {
33+
Intent intent = new Intent(this, CodeActivity.class);
34+
intent.putExtra("lesson_name", "BottomNavigation");
35+
startActivity(intent);
36+
});
37+
handler.postDelayed(() -> binding.floatingButtonShowSyntax.shrink(), 5000);
38+
}
39+
}

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/android/repository/LessonRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public Lesson getLesson(String lessonName) {
4040
new Lesson(R.string.grid_view, R.raw.text_grid_view_java, R.raw.text_grid_view_xml);
4141
case "WebView" ->
4242
new Lesson(R.string.web_view, R.raw.text_webview_java, R.raw.text_webview_xml);
43+
case "BottomNavigation" ->
44+
new Lesson(R.string.bottom_navigation, R.raw.text_bottom_navigation_java, R.raw.text_bottom_navigation_xml);
4345
default -> throw new IllegalArgumentException("Unknown lesson: " + lessonName);
4446
};
4547
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960">
6+
<path
7+
android:fillColor="?attr/colorSecondary"
8+
android:pathData="M120,720L120,640L840,640L840,720L120,720ZM120,520L120,440L840,440L840,520L120,520ZM120,320L120,240L840,240L840,320L120,320Z" />
9+
</vector>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/container"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.google.android.material.textview.MaterialTextView
9+
android:id="@+id/text_view"
10+
style="@style/TextAppearance.Material3.HeadlineSmall"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="@string/home"
14+
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
18+
19+
<com.google.android.material.bottomnavigation.BottomNavigationView
20+
android:id="@+id/bottom_nav"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
app:layout_constraintBottom_toBottomOf="parent"
24+
app:menu="@menu/bottom_nav_lesson_menu" />
25+
26+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
27+
android:id="@+id/floating_button_show_syntax"
28+
style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_margin="24dp"
32+
android:contentDescription="@string/tooltip_show_code"
33+
android:text="@string/show_code"
34+
android:tooltipText="@string/tooltip_show_code"
35+
app:icon="@drawable/ic_code"
36+
app:layout_constraintBottom_toBottomOf="parent"
37+
app:layout_constraintEnd_toEndOf="parent" />
38+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:id="@+id/navigation_home"
5+
android:icon="@drawable/ic_home"
6+
android:title="@string/home" />
7+
<item
8+
android:id="@+id/navigation_dashboard"
9+
android:icon="@drawable/ic_android"
10+
android:title="@string/dashboard" />
11+
<item
12+
android:id="@+id/navigation_notifications"
13+
android:icon="@drawable/ic_notification_important"
14+
android:title="@string/notifications" />
15+
</menu>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Import the necessary classes and libraries
2+
import android.os.Bundle;
3+
import androidx.appcompat.app.AppCompatActivity;
4+
import com.google.android.material.bottomnavigation.BottomNavigationView;
5+
6+
public class MainActivity extends AppCompatActivity {
7+
private ActivityMainBinding binding;
8+
9+
@Override
10+
protected void onCreate(Bundle savedInstanceState) {
11+
super.onCreate(savedInstanceState);
12+
13+
// Inflate the layout and set it as the content view for this activity
14+
binding = ActivityMainBinding.inflate(getLayoutInflater());
15+
setContentView(binding.getRoot());
16+
17+
// Update the text when a navigation item is selected
18+
binding.bottomNav.setOnItemSelectedListener(item -> {
19+
binding.textView.setText(item.getTitle());
20+
return true;
21+
});
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<androidx.constraintlayout.widget.ConstraintLayout
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
<TextView
7+
android:id="@+id/text_view"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:text="@string/home"
11+
app:layout_constraintBottom_toTopOf="@id/bottom_nav"
12+
app:layout_constraintEnd_toEndOf="parent"
13+
app:layout_constraintStart_toStartOf="parent"
14+
app:layout_constraintTop_toTopOf="parent" />
15+
<com.google.android.material.bottomnavigation.BottomNavigationView
16+
android:id="@+id/bottom_nav"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
app:layout_constraintBottom_toBottomOf="parent"
20+
app:menu="@menu/bottom_nav_lesson_menu" />
21+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@
242242
<string name="labeled">Labeled</string>
243243
<string name="selected">Selected</string>
244244
<string name="unlabeled">Unlabeled</string>
245+
<string name="navigation">Navigation</string>
246+
<string name="bottom_navigation">Bottom Navigation</string>
247+
<string name="dashboard">Dashboard</string>
245248
<string name="code_font">Code font</string>
246249
<string name="language">Language</string>
247250
<string name="notifications">Notifications</string>
@@ -356,6 +359,7 @@
356359
<string name="summary_preference_android_studio_progress_bar">A progress bar is a visual indicator of the progress of a task. In this lesson, you’ll learn how to use both horizontal and circular progress bars in Android. </string>
357360
<string name="summary_preference_android_studio_simple_notifications">Learn how to use notifications in your Android app with this lesson. Discover how to create a notification channel and builder, and how to show notifications to your users. Explore the different options available for customizing your notifications.</string>
358361
<string name="summary_preference_android_studio_inbox_notifications">Learn how to use inbox style notifications in your Android app with this lesson. Discover how to create a notification channel and builder, and how to set the style of your notifications to an InboxStyle with multiple lines of text and a summary text. Explore the different options available for customizing your inbox style notifications.</string>
362+
<string name="summary_preference_android_studio_bottom_navigation">A bottom navigation bar lets you quickly switch between top-level views in your app.</string>
359363
<string name="summary_alert_dialog_close">Are you sure you want to exit?</string>
360364
<string name="summary_alert_dialog_message">This will be the message you will see on screen!</string>
361365
<string name="summary_alert_dialog_require_restart">To take effect please restart the app!</string>

app/src/main/res/xml/preferences_android_studio.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,17 @@
334334
android:targetPackage="com.d4rk.androidtutorials.java" />
335335
</androidx.preference.Preference>
336336
</androidx.preference.PreferenceCategory>
337+
<androidx.preference.PreferenceCategory
338+
app:icon="@drawable/ic_category_navigation_tinted"
339+
app:title="@string/navigation">
340+
<androidx.preference.Preference
341+
app:icon="@drawable/ic_menu"
342+
app:summary="@string/summary_preference_android_studio_bottom_navigation"
343+
app:title="@string/bottom_navigation">
344+
<intent
345+
android:action="android.intent.action.VIEW"
346+
android:targetClass="com.d4rk.androidtutorials.java.ui.screens.android.lessons.navigation.bottomnavigation.BottomNavigationActivity"
347+
android:targetPackage="com.d4rk.androidtutorials.java" />
348+
</androidx.preference.Preference>
349+
</androidx.preference.PreferenceCategory>
337350
</androidx.preference.PreferenceScreen>

0 commit comments

Comments
 (0)