1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-22 16:23:09 +02:00

added navigation bottom drawer

This commit is contained in:
OliE
2018-02-04 10:57:07 +01:00
parent a8eb24eb37
commit 77486eb859
4 changed files with 129 additions and 34 deletions

View File

@@ -16,6 +16,7 @@
package com.health.openscale.gui;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
@@ -31,6 +32,10 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@@ -57,6 +62,8 @@ import com.health.openscale.gui.fragments.OverviewFragment;
import com.health.openscale.gui.fragments.StatisticsFragment;
import com.health.openscale.gui.fragments.TableFragment;
import java.lang.reflect.Field;
import cat.ereza.customactivityoncrash.config.CaocConfig;
@@ -69,6 +76,7 @@ public class MainActivity extends AppCompatActivity {
private DrawerLayout drawerLayout;
private Toolbar toolbar;
private NavigationView navDrawer;
private BottomNavigationView navBottomDrawer;
private ActionBarDrawerToggle drawerToggle;
@Override
@@ -100,6 +108,17 @@ public class MainActivity extends AppCompatActivity {
// Find our drawer view
navDrawer = (NavigationView) findViewById(R.id.navigation_view);
navBottomDrawer = (BottomNavigationView) findViewById(R.id.navigation_bottom_view);
navBottomDrawer.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
selectDrawerItem(item.getItemId());
return true;
}
});
disableShiftMode(navBottomDrawer);
//Create Drawer Toggle
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open_drawer, R.string.close_drawer){
@Override
@@ -122,6 +141,8 @@ public class MainActivity extends AppCompatActivity {
selectDrawerItem(prefs.getInt("lastFragmentId", R.id.nav_overview));
navBottomDrawer.setSelectedItemId(prefs.getInt("lastFragmentId", R.id.nav_overview));
if (prefs.getBoolean("firstStart", true)) {
Intent intent = new Intent(this, UserSettingsActivity.class);
intent.putExtra(UserSettingsActivity.EXTRA_MODE, UserSettingsActivity.ADD_USER_REQUEST);
@@ -219,8 +240,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
selectDrawerItem(menuItem.getItemId());
// Highlight the selected item has been done by NavigationView
menuItem.setChecked(true);
navBottomDrawer.setSelectedItemId(menuItem.getItemId());
return true;
}
@@ -282,6 +302,9 @@ public class MainActivity extends AppCompatActivity {
// Set action bar title
setTitle(fragmentTitle);
// Set checked item
navDrawer.setCheckedItem(menuItemId);
// Close the navigation drawer
drawerLayout.closeDrawers();
}
@@ -432,4 +455,28 @@ public class MainActivity extends AppCompatActivity {
bluetoothStatusIcon = iconRessource;
bluetoothStatus.setIcon(getResources().getDrawable(bluetoothStatusIcon));
}
@SuppressLint("RestrictedApi")
public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
//noinspection RestrictedApi
item.setShiftingMode(false);
item.setPadding(0, 15, 0, 0);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@android:color/white" />
<item android:color="#80FFFFFF" />
</selector>

View File

@@ -1,45 +1,62 @@
<android.support.v4.widget.DrawerLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<!-- The ActionBar displayed at the top -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
</android.support.v7.widget.Toolbar>
android:layout_height="match_parent"
android:weightSum="100"
android:orientation="vertical">
<!-- action_menumain content view where fragments are loaded -->
<!-- The ActionBar displayed at the top -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/fragment_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- action_menumain content view where fragments are loaded -->
<FrameLayout
android:id="@+id/fragment_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="90"/>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_view" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:background="?attr/colorPrimaryDark"
app:itemIconTint="@drawable/nav_item_colors"
app:itemTextColor="@android:color/transparent"
app:menu="@menu/drawer_bottom_view" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/menu_top"
android:checkableBehavior="single">
<item
android:id="@+id/nav_overview"
android:icon="@drawable/ic_preferences_home"
android:title="@string/title_overview" />
<item
android:id="@+id/nav_graph"
android:icon="@drawable/ic_preferences_graph"
android:title="@string/title_graph" />
<item
android:id="@+id/nav_table"
android:icon="@drawable/ic_preferences_table"
android:title="@string/title_table" />
<item
android:id="@+id/nav_statistic"
android:icon="@drawable/ic_preferences_statistics"
android:title="@string/title_statistics" />
</group>
</menu>