Skip to content

Commit

Permalink
mapbox#1856 - Adding Styles to Navigation View with separator
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Aug 7, 2015
1 parent f39f05d commit df1ceb8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Color;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
Expand Down Expand Up @@ -294,13 +295,37 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
// Toggle compass
mapView.setCompassEnabled(!mapView.isCompassEnabled());
break;

case R.id.actionStyleMapboxStreets:
changeMapStyle(getString(R.string.styleURLMapboxStreets));
break;

case R.id.actionStyleEmerald:
changeMapStyle(getString(R.string.styleURLEmerald));
break;

case R.id.actionStyleLight:
changeMapStyle(getString(R.string.styleURLLight));
break;

case R.id.actionStyleDark:
changeMapStyle(getString(R.string.styleURLDark));
break;

case R.id.actionStyleSatellite:
changeMapStyle(getString(R.string.styleURLSatellite));
break;
}

return true;
}
});
}

private void changeMapStyle(@NonNull String styleURL) {
mapView.setStyleUrl(styleURL);
}

/**
* 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 Expand Up @@ -400,70 +425,6 @@ private void removeAnnotations() {
mapView.removeAnnotations();
}

// This class handles style change events
private class StyleSpinnerListener implements AdapterView.OnItemSelectedListener {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {

// Mapbox Streets
case 0:
mapView.setStyleUrl("asset://styles/mapbox-streets-v7.json");
mapView.removeAllStyleClasses();
mClassSpinner.setVisibility(View.INVISIBLE);
mClassSpinner.setAdapter(null);
mClassSpinner.setOnItemSelectedListener(null);
break;

// Emerald
case 1:
mapView.setStyleUrl("asset://styles/emerald-v7.json");
mapView.removeAllStyleClasses();
mClassSpinner.setVisibility(View.INVISIBLE);
mClassSpinner.setAdapter(null);
mClassSpinner.setOnItemSelectedListener(null);
break;

// Light
case 2:
mapView.setStyleUrl("asset://styles/light-v7.json");
mapView.removeAllStyleClasses();
mClassSpinner.setVisibility(View.INVISIBLE);
mClassSpinner.setAdapter(null);
mClassSpinner.setOnItemSelectedListener(null);
break;

// Dark
case 3:
mapView.setStyleUrl("asset://styles/dark-v7.json");
mapView.removeAllStyleClasses();
mClassSpinner.setVisibility(View.INVISIBLE);
mClassSpinner.setAdapter(null);
mClassSpinner.setOnItemSelectedListener(null);
break;

// Outdoors
case 4:
mapView.setStyleUrl("asset://styles/outdoors-v7.json");
mapView.removeAllStyleClasses();
mClassSpinner.setVisibility(View.VISIBLE);
mClassSpinner.setAdapter(mOutdoorsClassAdapter);
mClassSpinner.setOnItemSelectedListener(new OutdoorClassSpinnerListener());
break;

default:
onNothingSelected(parent);
break;
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
mapView.setStyleUrl("");
}
}

// This class handles outdoor class change events
private class OutdoorClassSpinnerListener implements AdapterView.OnItemSelectedListener {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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"
Expand All @@ -19,4 +20,24 @@
android:title="@string/action_compass"
/>

<group android:id="@+id/stylesSeparator"/>

<group android:id="@+id/stylesGroup" android:checkableBehavior="single">
<item
android:id="@+id/actionStyleMapboxStreets"
android:title="@string/styleMapboxStreets" />
<item
android:id="@+id/actionStyleEmerald"
android:title="@string/styleEmerald" />
<item
android:id="@+id/actionStyleLight"
android:title="@string/styleLight" />
<item
android:id="@+id/actionStyleDark"
android:title="@string/styleDark" />
<item
android:id="@+id/actionStyleSatellite"
android:title="@string/styleSatellite" />
</group>

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@

<string name="action_gps">Toggle GPS location</string>
<string name="action_compass">Toggle Compass</string>

<string name="action_debug">Toggle debug mode</string>

<string name="action_point_annotations">Toggle point annotations</string>

<string name="label_fps">FPS:</string>

<string-array name="style_list">
<item>Mapbox Streets</item>
<item>Emerald</item>
<item>Light</item>
<item>Dark</item>
</string-array>
<string name="styleMapboxStreets">Mapbox Streets</string>
<string name="styleEmerald">Emerald</string>
<string name="styleLight">Light</string>
<string name="styleDark">Dark</string>
<string name="styleSatellite">Satellite</string>

<string name="styleURLMapboxStreets">asset://styles/mapbox-streets-v7.json</string>
<string name="styleURLEmerald">asset://styles/emerald-v7.json</string>
<string name="styleURLLight">asset://styles/light-v7.json</string>
<string name="styleURLDark">asset://styles/dark-v7.json</string>
<string name="styleURLSatellite">asset://styles/satellite-v7.json</string>

<string-array name="outdoors_class_list">
<item>Day</item>
Expand Down

0 comments on commit df1ceb8

Please sign in to comment.