summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2015-01-30 10:52:00 +1100
committerLeith Bade <leith@mapbox.com>2015-01-30 11:44:38 +1100
commit9e3311f48a8a423b6bb2fe37f957a2bb510f212b (patch)
treecedcb68de3a04f669367ada165f11ec3bfcbd6be /android
parent0953b215abf0dc2987c6ab695db492b00efb2632 (diff)
downloadqtlocation-mapboxgl-9e3311f48a8a423b6bb2fe37f957a2bb510f212b.tar.gz
Add class picker to Android UI
Diffstat (limited to 'android')
-rw-r--r--android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java109
-rw-r--r--android/java/app/src/main/res/layout/activity_main.xml6
-rw-r--r--android/java/app/src/main/res/values/strings.xml15
-rw-r--r--android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java24
4 files changed, 151 insertions, 3 deletions
diff --git a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java
index f503ed0ba9..93029c6f51 100644
--- a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java
+++ b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java
@@ -22,6 +22,9 @@ import com.mapzen.android.lost.LocationClient;
import com.mapzen.android.lost.LocationListener;
import com.mapzen.android.lost.LocationRequest;
+import java.util.ArrayList;
+import java.util.LinkedList;
+
public class MainActivity extends ActionBarActivity {
//
@@ -50,6 +53,11 @@ public class MainActivity extends ActionBarActivity {
private LocationListener mLocationListener;
private LocationRequest mLocationRequest;
+ // Used for the class spinner
+ Spinner mClassSpinner;
+ ArrayAdapter mOutdoorsClassAdapter;
+ ArrayAdapter mSatelliteClassAdapter;
+
//
// Lifecycle events
//
@@ -84,6 +92,13 @@ public class MainActivity extends ActionBarActivity {
styleSpinner.setAdapter(styleAdapter);
styleSpinner.setOnItemSelectedListener(new StyleSpinnerListener());
+ // Add the spinner to select class styles
+ mClassSpinner = (Spinner)findViewById(R.id.spinner_class);
+ mOutdoorsClassAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
+ R.array.outdoors_class_list, android.R.layout.simple_spinner_dropdown_item);
+ mSatelliteClassAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
+ R.array.satellite_class_list, android.R.layout.simple_spinner_dropdown_item);
+
// Prepare for GPS
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(0);
@@ -202,31 +217,55 @@ public class MainActivity extends ActionBarActivity {
// Bright
case 0:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/bright-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.INVISIBLE);
+ mClassSpinner.setAdapter(null);
+ mClassSpinner.setOnItemSelectedListener(null);
break;
// Basic
case 1:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/basic-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.INVISIBLE);
+ mClassSpinner.setAdapter(null);
+ mClassSpinner.setOnItemSelectedListener(null);
break;
// Outdoors
case 2:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/outdoors-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.VISIBLE);
+ mClassSpinner.setAdapter(mOutdoorsClassAdapter);
+ mClassSpinner.setOnItemSelectedListener(new OutdoorClassSpinnerListener());
break;
// Satellite
case 3:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/satellite-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.VISIBLE);
+ mClassSpinner.setAdapter(mSatelliteClassAdapter);
+ mClassSpinner.setOnItemSelectedListener(new SatelliteClassSpinnerListener());
break;
// Pencil
case 4:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/pencil-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.INVISIBLE);
+ mClassSpinner.setAdapter(null);
+ mClassSpinner.setOnItemSelectedListener(null);
break;
// Empty
case 5:
mMapFragment.getMap().setStyleUrl("asset://styles/styles/empty-v7.json");
+ mMapFragment.getMap().removeAllClasses();
+ mClassSpinner.setVisibility(View.INVISIBLE);
+ mClassSpinner.setAdapter(null);
+ mClassSpinner.setOnItemSelectedListener(null);
break;
default:
@@ -241,6 +280,76 @@ public class MainActivity extends ActionBarActivity {
}
}
+ // This class handles outdoor class change events
+ private class OutdoorClassSpinnerListener implements AdapterView.OnItemSelectedListener {
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ ArrayList<String> classes = new ArrayList<String>(1);
+
+ switch(position) {
+ // Day
+ case 0:
+ classes.add("day");
+ mMapFragment.getMap().setClasses(classes);
+ break;
+
+ // Night
+ case 1:
+ classes.add("night");
+ mMapFragment.getMap().setClasses(classes);
+ break;
+
+ default:
+ onNothingSelected(parent);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ mMapFragment.getMap().removeAllClasses();
+ }
+ }
+
+ // This class handles satellite class change events
+ private class SatelliteClassSpinnerListener implements AdapterView.OnItemSelectedListener {
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ ArrayList<String> classes = new ArrayList<String>(2);
+
+ switch(position) {
+ // Labels + Contours
+ case 0:
+ classes.add("labels");
+ classes.add("contours");
+ mMapFragment.getMap().setClasses(classes);
+ break;
+
+ // Labels Only
+ case 1:
+ classes.add("labels");
+ mMapFragment.getMap().setClasses(classes);
+ break;
+
+ // No Labels
+ case 2:
+ mMapFragment.getMap().setClasses(classes);
+ break;
+
+ default:
+ onNothingSelected(parent);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ mMapFragment.getMap().removeAllClasses();
+ }
+ }
+
// Called when FPS changes
public class MyOnFpsChangedListener implements MapView.OnFpsChangedListener {
diff --git a/android/java/app/src/main/res/layout/activity_main.xml b/android/java/app/src/main/res/layout/activity_main.xml
index d03aae6af6..5376ee2d24 100644
--- a/android/java/app/src/main/res/layout/activity_main.xml
+++ b/android/java/app/src/main/res/layout/activity_main.xml
@@ -15,6 +15,12 @@
android:id="@+id/spinner_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+
+ <Spinner
+ android:id="@+id/spinner_class"
+ android:visibility="invisible"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
<FrameLayout
diff --git a/android/java/app/src/main/res/values/strings.xml b/android/java/app/src/main/res/values/strings.xml
index 7f7e63cfbb..7b4e51b473 100644
--- a/android/java/app/src/main/res/values/strings.xml
+++ b/android/java/app/src/main/res/values/strings.xml
@@ -16,8 +16,19 @@
<item>Basic</item>
<item>Outdoors</item>
<item>Satellite</item>
- <!--<item>Pencil</item>-->
- <!--<item>Empty</item>-->
+ <item>Pencil</item>
+ <item>Empty</item>
+ </string-array>
+
+ <string-array name="outdoors_class_list">
+ <item>Day</item>
+ <item>Night</item>
+ </string-array>
+
+ <string-array name="satellite_class_list">
+ <item>Labels + Contours</item>
+ <item>Labels Only</item>
+ <item>No Labels</item>
</string-array>
</resources>
diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
index 9a3a646138..36e530a179 100644
--- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
+++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
@@ -24,6 +24,7 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewConfiguration;
+import android.widget.ArrayAdapter;
import android.widget.ZoomButtonsController;
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
@@ -358,6 +359,28 @@ public class MapView extends SurfaceView {
mNativeMapView.setClasses(classes);
}
+ public void addClass(String clazz) {
+ mNativeMapView.addClass(clazz);
+ }
+
+ public void removeClass(String clazz) {
+ mNativeMapView.removeClass(clazz);
+ }
+
+ public boolean hasClass(String clazz) {
+ return mNativeMapView.hasClass(clazz);
+ }
+
+ public void removeAllClasses() {
+ removeAllClasses(0);
+ }
+
+ public void removeAllClasses(long transitionDuration) {
+ mNativeMapView.setDefaultTransitionDuration(transitionDuration);
+ ArrayList<String> classes = new ArrayList<String>(0);
+ setClasses(classes);
+ }
+
//
// Lifecycle events
//
@@ -1145,7 +1168,6 @@ public class MapView extends SurfaceView {
}
}
-
// Called when our Internet connectivity has changed
private void onConnectivityChanged(boolean isConnected) {
Log.v(TAG, "onConnectivityChanged: " + isConnected);