Add bottom navigation
Change-Id: I7309e65e8873df877c1cd09a52de6d9b2e3dcb75
diff --git a/app/src/main/java/net/named_data/nfd/DrawerFragment.java b/app/src/main/java/net/named_data/nfd/DrawerFragment.java
index 6efe23d..8fc6856 100644
--- a/app/src/main/java/net/named_data/nfd/DrawerFragment.java
+++ b/app/src/main/java/net/named_data/nfd/DrawerFragment.java
@@ -28,6 +28,7 @@
import android.view.MenuItem;
import android.view.View;
+import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import net.named_data.nfd.utils.G;
@@ -96,7 +97,8 @@
// Initialize and set up the navigation drawer UI
initializeDrawerFragment(getActivity().findViewById(R.id.navigation_drawer),
- getActivity().findViewById(R.id.drawer_layout));
+ getActivity().findViewById(R.id.drawer_layout),
+ getActivity().findViewById(R.id.bottom_navigation_view));
if (savedInstanceState == null) {
// when restoring (e.g., after rotation), rely on system to restore previous state of
@@ -109,6 +111,12 @@
else {
G.Log("Logic problem: there should always be some menu item found");
}
+
+ item = m_bottomNav.getMenu().findItem(m_drawerSelectedPosition);
+ if (item != null) {
+ item.setChecked(true);
+ }
+ // if not found, nothing to worry about
}
}
@@ -119,10 +127,12 @@
* @param drawerLayout DrawerLayout of the drawer in the host Activity
*/
private void initializeDrawerFragment(NavigationView drawerFragmentViewContainer,
- DrawerLayout drawerLayout)
+ DrawerLayout drawerLayout,
+ BottomNavigationView bottomNavigationView)
{
m_drawerFragmentViewContainer = drawerFragmentViewContainer;
m_drawerLayout = drawerLayout;
+ m_bottomNav = bottomNavigationView;
m_drawerFragmentViewContainer.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@@ -135,6 +145,32 @@
m_callbacks.onDrawerItemSelected(item.getItemId(), item.getTitle());
m_drawerSelectedPosition = item.getItemId();
+ MenuItem bottomItem = m_bottomNav.getMenu().findItem(item.getItemId());
+ if (bottomItem != null) {
+ bottomItem.setChecked(true);
+ }
+ else {
+ MenuItem selectedBottomItem = m_bottomNav.getMenu().getItem(m_bottomNav.getSelectedItemId());
+ if (selectedBottomItem != null) {
+ selectedBottomItem.setChecked(false);
+ }
+ }
+
+ return true;
+ }
+ }
+ );
+
+ m_bottomNav.setOnNavigationItemSelectedListener(
+ new BottomNavigationView.OnNavigationItemSelectedListener() {
+ @Override
+ public boolean onNavigationItemSelected(@NonNull MenuItem item)
+ {
+ m_callbacks.onDrawerItemSelected(item.getItemId(), item.getTitle());
+ m_drawerSelectedPosition = item.getItemId();
+
+ m_drawerFragmentViewContainer.setCheckedItem(item.getItemId());
+
return true;
}
}
@@ -308,6 +344,8 @@
/** Drawer's fragment container in the host activity */
private NavigationView m_drawerFragmentViewContainer;
+ private BottomNavigationView m_bottomNav;
+
/** Current position of the Drawer's selection */
private int m_drawerSelectedPosition = R.id.nav_general;
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index fe3c704..dd76227 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -9,11 +9,22 @@
tools:context=".MainActivity">
<!-- Main container for fragments to be presented in -->
- <FrameLayout
- android:id="@+id/main_fragment_container"
+ <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- />
+ android:id="@+id/main_fragment_container"
+ >
+
+ <com.google.android.material.bottomnavigation.BottomNavigationView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
+ android:id="@+id/bottom_navigation_view"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ app:menu="@menu/bottom_menu"/>
+ </RelativeLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_drawer"
@@ -23,5 +34,4 @@
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_menu"
/>
-
</androidx.drawerlayout.widget.DrawerLayout>
diff --git a/app/src/main/res/menu/bottom_menu.xml b/app/src/main/res/menu/bottom_menu.xml
new file mode 100644
index 0000000..0875a9a
--- /dev/null
+++ b/app/src/main/res/menu/bottom_menu.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <group android:checkableBehavior="single">
+ <item
+ android:id="@+id/nav_general"
+ android:icon="@drawable/ic_status"
+ android:title="@string/drawer_item_general" />
+ <item
+ android:id="@+id/nav_faces"
+ android:icon="@drawable/ic_faces"
+ android:title="@string/drawer_item_faces" />
+ <item
+ android:id="@+id/nav_routes"
+ android:icon="@drawable/ic_route"
+ android:title="@string/drawer_item_routes" />
+ <!--<item-->
+ <!--android:id="@+id/nav_strategies"-->
+ <!--android:icon="@drawable/ic_strategy"-->
+ <!--android:title="@string/drawer_item_strategies" />-->
+ </group>
+</menu>
\ No newline at end of file
diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml
index 7499683..dfc2e8f 100644
--- a/app/src/main/res/menu/drawer_menu.xml
+++ b/app/src/main/res/menu/drawer_menu.xml
@@ -13,6 +13,10 @@
android:id="@+id/nav_routes"
android:icon="@drawable/ic_route"
android:title="@string/drawer_item_routes" />
+ <!--<item-->
+ <!--android:id="@+id/nav_strategies"-->
+ <!--android:icon="@drawable/ic_strategy"-->
+ <!--android:title="@string/drawer_item_strategies" />-->
<item
android:id="@+id/nav_ping"
android:icon="@drawable/ic_ping"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2f735a8..43dbab0 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -18,7 +18,7 @@
<string name="checking_on_nfd">Checking on NFD Service …</string>
<string name="accessibility_open_drawer">Open NFD Navigation Drawer</string>
<string name="accessibility_close_drawer">Close NFD Navigation Drawer</string>
- <string name="drawer_item_general">General</string>
+ <string name="drawer_item_general">Status</string>
<string name="drawer_item_faces">Faces</string>
<string name="drawer_item_routes">Routes</string>
<string name="drawer_item_ping">Ping</string>