Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
#1856 - Setting up Navigation Drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Aug 7, 2015
1 parent d3ba9e2 commit 440ae9d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.graphics.Color;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -92,6 +94,11 @@ protected void onCreate(Bundle savedInstanceState) {

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
setupDrawerContent(navigationView);
}

mapView = (MapView) findViewById(R.id.mainMapView);
// Load the access token
try {
Expand Down Expand Up @@ -241,6 +248,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START);
return true;

case R.id.action_gps:
// Toggle GPS position updates
toggleGps(!mapView.isMyLocationEnabled());
Expand Down Expand Up @@ -275,6 +286,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
return true;
}
});
}

/**
* Enabled / Disable GPS location updates along with updating the UI
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
Expand Down Expand Up @@ -86,7 +85,6 @@
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
tools:headerLayout="@layout/nav_header"
tools:menu="@menu/drawer_view"/>
mapbox:menu="@menu/menu_drawer"/>

</android.support.v4.widget.DrawerLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_debug"
android:icon="@drawable/ic_action_about"
android:title="@string/action_debug"
/>
<item
android:id="@+id/action_markers"
android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/action_point_annotations"
/>

</menu>
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_debug"
android:icon="@drawable/ic_action_about"
android:title="@string/action_debug"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_markers"
android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/action_point_annotations"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_gps"
android:icon="@drawable/ic_action_location_searching"
android:title="@string/action_gps"
Expand Down

0 comments on commit 440ae9d

Please sign in to comment.