#1856 - Adding Styles to Navigation View with separator
This commit is contained in:
@@ -3,6 +3,7 @@ package com.mapbox.mapboxgl.testapp;
|
||||
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;
|
||||
@@ -294,6 +295,26 @@ public class MainActivity extends AppCompatActivity {
|
||||
// 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;
|
||||
@@ -301,6 +322,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
@@ -400,70 +425,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
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 {
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user