diff --git a/MapboxAndroidDemo/build.gradle b/MapboxAndroidDemo/build.gradle index 9aa009182..dea98c2cf 100644 --- a/MapboxAndroidDemo/build.gradle +++ b/MapboxAndroidDemo/build.gradle @@ -46,6 +46,7 @@ dependencies { compile "com.android.support:cardview-v7:${supportLibVersion}" compile "com.android.support:recyclerview-v7:${supportLibVersion}" compile 'com.github.javiersantos:MaterialStyledDialogs:1.5.1' + compile 'com.getbase:floatingactionbutton:1.10.1' compile 'com.squareup.picasso:picasso:2.5.2' compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0-beta.1@aar'){ transitive=true diff --git a/MapboxAndroidDemo/src/main/AndroidManifest.xml b/MapboxAndroidDemo/src/main/AndroidManifest.xml index eb73b1072..f318d1682 100644 --- a/MapboxAndroidDemo/src/main/AndroidManifest.xml +++ b/MapboxAndroidDemo/src/main/AndroidManifest.xml @@ -314,5 +314,13 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity" /> + + + + diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java index d40433274..446198332 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java @@ -53,6 +53,7 @@ import com.mapbox.mapboxandroiddemo.examples.styles.ShowHideLayersActivity; import com.mapbox.mapboxandroiddemo.examples.styles.VectorSourceActivity; import com.mapbox.mapboxandroiddemo.examples.styles.ZoomDependentFillColorActivity; +import com.mapbox.mapboxandroiddemo.labs.LandUseStylingActivity; import com.mapbox.mapboxandroiddemo.labs.LocationPickerActivity; import com.mapbox.mapboxandroiddemo.labs.MarkerFollowingRouteActivity; import com.mapbox.mapboxandroiddemo.labs.SpaceStationLocationActivity; @@ -218,6 +219,7 @@ private void listItems(int id) { break; case R.id.nav_lab: exampleItemModel.add(null); + exampleItemModel.add(new ExampleItemModel(R.string.activity_lab_land_use_stying_title, R.string.activity_lab_land_use_stying_description, new Intent(MainActivity.this, LandUseStylingActivity.class), R.string.activity_lab_land_use_stying_url, true)); exampleItemModel.add(new ExampleItemModel(R.string.activity_lab_location_picker_title, R.string.activity_lab_location_picker_description, new Intent(MainActivity.this, LocationPickerActivity.class), R.string.activity_lab_location_picker_url)); exampleItemModel.add(new ExampleItemModel(R.string.activity_lab_marker_following_route_title, R.string.activity_lab_marker_following_route_description, new Intent(MainActivity.this, MarkerFollowingRouteActivity.class), R.string.activity_lab_marker_following_route_url, true)); exampleItemModel.add(new ExampleItemModel(R.string.activity_lab_space_station_location_title, R.string.activity_lab_space_station_location_description, new Intent(MainActivity.this, SpaceStationLocationActivity.class), R.string.activity_lab_space_station_location_url)); diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/LandUseStylingActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/LandUseStylingActivity.java new file mode 100644 index 000000000..085eb1bf2 --- /dev/null +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/LandUseStylingActivity.java @@ -0,0 +1,161 @@ +package com.mapbox.mapboxandroiddemo.labs; + +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; + +import com.getbase.floatingactionbutton.FloatingActionButton; +import com.mapbox.mapboxandroiddemo.R; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.style.layers.FillLayer; + +import static com.mapbox.mapboxsdk.style.layers.Filter.eq; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; + +public class LandUseStylingActivity extends AppCompatActivity { + private static final String TAG = LandUseStylingActivity.class.getSimpleName(); + + private MapView mapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_lab_land_use_styling); + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(final MapboxMap mapboxMap) { + + FillLayer schoolLayer = new FillLayer("school-layer", "composite"); + schoolLayer.setSourceLayer("landuse"); + schoolLayer.setProperties( + fillColor(Color.parseColor("#f6f6f4")) + ); + schoolLayer.setFilter(eq("class", "school")); + mapboxMap.addLayer(schoolLayer); + + FillLayer hospitalLayer = new FillLayer("hospital-layer", "composite"); + hospitalLayer.setSourceLayer("landuse"); + hospitalLayer.setProperties( + fillColor(Color.parseColor("#eceeed")) + ); + hospitalLayer.setFilter(eq("class", "hospital")); + mapboxMap.addLayer(hospitalLayer); + + FloatingActionButton toggleParks = (FloatingActionButton) findViewById(R.id.fab_toggle_parks); + toggleParks.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FillLayer parks = mapboxMap.getLayerAs("parks"); + if (parks != null) { + + if (!colorsEqual(parks.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxGreen))) { + parks.setProperties( + fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxGreen)) + ); + } else { + parks.setProperties( + fillColor(Color.parseColor("#eceeed")) + ); + } + } + } + }); + + FloatingActionButton toggleSchools = (FloatingActionButton) findViewById(R.id.fab_toggle_schools); + toggleSchools.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FillLayer schools = mapboxMap.getLayerAs("school-layer"); + if (schools != null) { + if (schools.getFillColor().isValue() && + !colorsEqual(schools.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxYellow))) { + schools.setProperties( + fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxYellow)) + ); + } else { + schools.setProperties( + fillColor(Color.parseColor("#f6f6f4")) + ); + } + } + } + }); + + FloatingActionButton toggleHospital = (FloatingActionButton) findViewById(R.id.fab_toggle_hospital); + toggleHospital.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FillLayer hospital = mapboxMap.getLayerAs("hospital-layer"); + if (hospital != null) { + if (hospital.getFillColor().isValue() && + !colorsEqual(hospital.getFillColorAsInt(), ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxPurple))) { + hospital.setProperties( + fillColor(ContextCompat.getColor(LandUseStylingActivity.this, R.color.mapboxPurple)) + ); + } else { + hospital.setProperties( + fillColor(Color.parseColor("#eceeed")) + ); + } + } + } + }); + + } + }); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + private boolean colorsEqual(int a, int b) { + boolean equal = Math.abs(Color.red(a) - Color.red(b)) <= 10 && + Math.abs(Color.green(a) - Color.green(b)) <= 10 && + Math.abs(Color.blue(a) - Color.blue(b)) <= 10; + + Log.i(TAG, String.format("Comparing colors: %s, %s (%s, %s ,%s => %s)", + a, + b, + Math.abs(Color.red(a) - Color.red(b)), + Math.abs(Color.green(a) - Color.green(b)), + Math.abs(Color.blue(a) - Color.blue(b)), + equal) + ); + return equal; + } +} diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/SpaceStationLocationActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/SpaceStationLocationActivity.java index 15dbf4331..793337920 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/SpaceStationLocationActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/labs/SpaceStationLocationActivity.java @@ -51,7 +51,7 @@ public class SpaceStationLocationActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_space_station_location); + setContentView(R.layout.activity_lab_space_station_location); // Initialize the map view mapView = (MapView) findViewById(R.id.mapView); diff --git a/MapboxAndroidDemo/src/main/res/drawable/fab_label_background.xml b/MapboxAndroidDemo/src/main/res/drawable/fab_label_background.xml new file mode 100644 index 000000000..0d8c05b11 --- /dev/null +++ b/MapboxAndroidDemo/src/main/res/drawable/fab_label_background.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/layout/activity_lab_land_use_styling.xml b/MapboxAndroidDemo/src/main/res/layout/activity_lab_land_use_styling.xml new file mode 100644 index 000000000..a333270e3 --- /dev/null +++ b/MapboxAndroidDemo/src/main/res/layout/activity_lab_land_use_styling.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/layout/activity_space_station_location.xml b/MapboxAndroidDemo/src/main/res/layout/activity_lab_space_station_location.xml similarity index 100% rename from MapboxAndroidDemo/src/main/res/layout/activity_space_station_location.xml rename to MapboxAndroidDemo/src/main/res/layout/activity_lab_space_station_location.xml diff --git a/MapboxAndroidDemo/src/main/res/values/colors.xml b/MapboxAndroidDemo/src/main/res/values/colors.xml index 0423690bd..a0dc31bf6 100644 --- a/MapboxAndroidDemo/src/main/res/values/colors.xml +++ b/MapboxAndroidDemo/src/main/res/values/colors.xml @@ -1,9 +1,10 @@ + @color/mapboxBlue @color/mapboxBlueDark @color/mapboxRed - + #F5F5F5 #DFDFDF @@ -15,14 +16,19 @@ #8A8ACB #7171b2 #A4A4E5 - + #50667F #41AFA5 #F9886C #E55E5E #ED6498 + #f1f075 #FBB03B #28353D #222B30 + + #B2000000 + #808080 + #f1f1f1 diff --git a/MapboxAndroidDemo/src/main/res/values/strings.xml b/MapboxAndroidDemo/src/main/res/values/strings.xml index bcc8c79ad..3b3429754 100644 --- a/MapboxAndroidDemo/src/main/res/values/strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/strings.xml @@ -74,6 +74,7 @@ Location picker Marker following route Space station current location + Land use styling Show a map in your app using the Mapbox Android SDK. @@ -112,6 +113,7 @@ Drop a marker at a specific location and then perform reverse geocoding. Using a map matched GeoJSON route, the marker travels along the route at consistent speed. See the International Space Station location in real time. + Use the style api to allow toggleable highlighting of parks, hospitals, and schools. @@ -152,5 +154,6 @@ http://i.imgur.com/0JTVwaa.png http://i.imgur.com/spsZu9X.png http://i.imgur.com/PxuB1T8.png + http://i.imgur.com/x1i4qEw.png diff --git a/MapboxAndroidDemo/src/main/res/values/styles.xml b/MapboxAndroidDemo/src/main/res/values/styles.xml index 545b9c6d2..efd356e9e 100644 --- a/MapboxAndroidDemo/src/main/res/values/styles.xml +++ b/MapboxAndroidDemo/src/main/res/values/styles.xml @@ -17,4 +17,9 @@ +