diff --git a/MapboxAndroidDemo/build.gradle b/MapboxAndroidDemo/build.gradle index 65449e156..03d11643a 100644 --- a/MapboxAndroidDemo/build.gradle +++ b/MapboxAndroidDemo/build.gradle @@ -10,6 +10,11 @@ android { compileSdkVersion androidVersions.compileSdkVersion buildToolsVersion androidVersions.buildToolsVersion + compileOptions { + sourceCompatibility 1.8 + targetCompatibility 1.8 + } + playAccountConfigs { defaultAccountConfig { serviceAccountEmail = 'mapbox-android-demo-publish@android-gl-native.iam.gserviceaccount.com' @@ -127,6 +132,7 @@ dependencies { implementation dependenciesList.mapboxPluginLocalization implementation dependenciesList.mapboxPluginTraffic implementation dependenciesList.mapboxPluginMarkerView + implementation dependenciesList.mapboxPluginAnnotation // Firebase globalImplementation dependenciesList.firebaseCrash diff --git a/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java b/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java index c7d47e918..c064e9f12 100644 --- a/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java +++ b/MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java @@ -30,8 +30,6 @@ import com.mapbox.mapboxandroiddemo.adapter.ExampleAdapter; import com.mapbox.mapboxandroiddemo.commons.AnalyticsTracker; import com.mapbox.mapboxandroiddemo.commons.FirstTimeRunChecker; -import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedMarkerActivity; -import com.mapbox.mapboxandroiddemo.examples.dds.DrawPolygonActivity; import com.mapbox.mapboxandroiddemo.examples.basics.MapboxMapOptionActivity; import com.mapbox.mapboxandroiddemo.examples.basics.SimpleMapViewActivity; import com.mapbox.mapboxandroiddemo.examples.basics.SimpleMapViewActivityKotlin; @@ -46,6 +44,7 @@ import com.mapbox.mapboxandroiddemo.examples.dds.CircleLayerClusteringActivity; import com.mapbox.mapboxandroiddemo.examples.dds.CreateHotspotsActivity; import com.mapbox.mapboxandroiddemo.examples.dds.DrawGeojsonLineActivity; +import com.mapbox.mapboxandroiddemo.examples.dds.DrawPolygonActivity; import com.mapbox.mapboxandroiddemo.examples.dds.ExpressionIntegrationActivity; import com.mapbox.mapboxandroiddemo.examples.dds.HeatmapActivity; import com.mapbox.mapboxandroiddemo.examples.dds.ImageClusteringActivity; @@ -73,6 +72,7 @@ import com.mapbox.mapboxandroiddemo.examples.javaservices.StaticImageActivity; import com.mapbox.mapboxandroiddemo.examples.javaservices.TilequeryActivity; import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedImageGifActivity; +import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedMarkerActivity; import com.mapbox.mapboxandroiddemo.examples.labs.CalendarIntegrationActivity; import com.mapbox.mapboxandroiddemo.examples.labs.DashedLineDirectionsPickerActivity; import com.mapbox.mapboxandroiddemo.examples.labs.IndoorMapActivity; @@ -98,6 +98,7 @@ import com.mapbox.mapboxandroiddemo.examples.plugins.MarkerViewPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.PlaceSelectionPluginActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.PlacesPluginActivity; +import com.mapbox.mapboxandroiddemo.examples.plugins.SymbolListenerActivity; import com.mapbox.mapboxandroiddemo.examples.plugins.TrafficPluginActivity; import com.mapbox.mapboxandroiddemo.examples.query.BuildingOutlineActivity; import com.mapbox.mapboxandroiddemo.examples.query.ClickOnLayerActivity; @@ -666,6 +667,13 @@ private void initializeModels() { null, R.string.activity_plugins_places_plugin_url, false, BuildConfig.MIN_SDK_VERSION)); + exampleItemModels.add(new ExampleItemModel( + R.id.nav_plugins, + R.string.activity_plugins_symbol_listener_title, R.string.activity_plugins_symbol_listener_description, + new Intent(MainActivity.this, SymbolListenerActivity.class), + null, + R.string.activity_plugins_symbol_listener_url, false, BuildConfig.MIN_SDK_VERSION)); + exampleItemModels.add(new ExampleItemModel( R.id.nav_plugins, R.string.activity_plugins_localization_plugin_title, @@ -1011,12 +1019,12 @@ private void initializeModels() { )); exampleItemModels.add(new ExampleItemModel( - R.id.nav_lab, - R.string.activity_lab_fog_background_title, - R.string.activity_lab_fog_background_description, - new Intent(MainActivity.this, MapFogBackgroundActivity.class), - null, - R.string.activity_lab_fog_background_url, false, BuildConfig.MIN_SDK_VERSION + R.id.nav_lab, + R.string.activity_lab_fog_background_title, + R.string.activity_lab_fog_background_description, + new Intent(MainActivity.this, MapFogBackgroundActivity.class), + null, + R.string.activity_lab_fog_background_url, false, BuildConfig.MIN_SDK_VERSION )); exampleItemModels.add(new ExampleItemModel( @@ -1222,4 +1230,4 @@ private void initializeModels() { null, R.string.activity_basic_mapbox_options_url, false, BuildConfig.MIN_SDK_VERSION)); } -} +} \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/AndroidManifest.xml b/MapboxAndroidDemo/src/main/AndroidManifest.xml index f6a3b27a9..b60285a4f 100644 --- a/MapboxAndroidDemo/src/main/AndroidManifest.xml +++ b/MapboxAndroidDemo/src/main/AndroidManifest.xml @@ -642,6 +642,13 @@ android:name="android.support.PARENT_ACTIVITY" android:value="com.mapbox.mapboxandroiddemo.MainActivity" /> + + + diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/SymbolListenerActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/SymbolListenerActivity.java new file mode 100644 index 000000000..055623891 --- /dev/null +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/plugins/SymbolListenerActivity.java @@ -0,0 +1,155 @@ +package com.mapbox.mapboxandroiddemo.examples.plugins; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.widget.Toast; + +import com.mapbox.mapboxandroiddemo.R; +import com.mapbox.mapboxsdk.Mapbox; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener; +import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolLongClickListener; +import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager; +import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions; +import com.mapbox.mapboxsdk.plugins.annotation.Symbol; +import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener; + +/** + * Change symbol icon by pressing on icon + */ +public class SymbolListenerActivity extends AppCompatActivity implements + OnMapReadyCallback { + + private MapView mapView; + private static final String MAKI_ICON_CAFE = "cafe-15"; + private static final String MAKI_ICON_HARBOR = "harbor-15"; + private static final String MAKI_ICON_AIRPORT = "airport-15"; + private SymbolManager symbolManager; + private Symbol symbol; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Mapbox access token is configured here. This needs to be called either in your application + // object or in the same activity which contains the mapview. + Mapbox.getInstance(this, getString(R.string.access_token)); + + // This contains the MapView in XML and needs to be called after the access token is configured. + setContentView(R.layout.activity_annotation_plugin_symbol_activity); + + mapView = findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(@NonNull final MapboxMap mapboxMap) { + mapboxMap.setStyle(Style.DARK, new Style.OnStyleLoaded() { + @Override + public void onStyleLoaded(@NonNull Style style) { + + // Set up a SymbolManager instance + symbolManager = new SymbolManager(mapView, mapboxMap, style); + + symbolManager.setIconAllowOverlap(true); + symbolManager.setTextAllowOverlap(true); + + // Add symbol at specified lat/lon + symbol = symbolManager.create(new SymbolOptions() + .withLatLng(new LatLng(60.169091, 24.939876)) + .withIconImage(MAKI_ICON_HARBOR) + .withIconSize(2.0f) + .setDraggable(true)); + + // Add click listener and change the symbol to a cafe icon on click + symbolManager.addClickListener(new OnSymbolClickListener() { + @Override + public void onAnnotationClick(Symbol symbol) { + Toast.makeText(SymbolListenerActivity.this, + String.format("Symbol clicked"), + Toast.LENGTH_SHORT).show(); + symbol.setIconImage(MAKI_ICON_CAFE); + symbolManager.update(symbol); + } + }); + + // Add long click listener and change the symbol to an airport icon on long click + symbolManager.addLongClickListener((new OnSymbolLongClickListener() { + @Override + public void onAnnotationLongClick(Symbol symbol) { + Toast.makeText(SymbolListenerActivity.this, + String.format("Symbol long clicked"), + Toast.LENGTH_SHORT).show(); + symbol.setIconImage(MAKI_ICON_AIRPORT); + symbolManager.update(symbol); + } + })); + + symbolManager.addDragListener(new OnSymbolDragListener() { + @Override + // Left empty on purpose + public void onAnnotationDragStarted(Symbol annotation) { + } + + @Override + // Left empty on purpose + public void onAnnotationDrag(Symbol symbol) { + } + + @Override + // Left empty on purpose + public void onAnnotationDragFinished(Symbol annotation) { + } + }); + } + }); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @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); + } +} \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/layout/activity_annotation_plugin_symbol_activity.xml b/MapboxAndroidDemo/src/main/res/layout/activity_annotation_plugin_symbol_activity.xml new file mode 100644 index 000000000..5615c514f --- /dev/null +++ b/MapboxAndroidDemo/src/main/res/layout/activity_annotation_plugin_symbol_activity.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml index 3ced2960d..923f72164 100644 --- a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml @@ -81,6 +81,7 @@ Use the building plugin to easily display 3D building height Easily retrieve GeoJSON data from a url, asset, or path Add location search ("geocoding") functionality and UI to search for any place in the world + Listen for Symbol interaction using the Annotation plugin its and built-in listeners Use the plugin to automatically change map label text to the language set on the device. Use the place picker function of the Places Plugin to choose a specific location in the world. Create a marker with an Android-system View. diff --git a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml index d8a1f2693..3f1480001 100644 --- a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml @@ -81,6 +81,7 @@ Change map text to device language Load GeoJSON data Location search + Symbol listener Place picker MarkerView Show a user\'s location on a map fragment diff --git a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml index f15e32712..77dad4635 100644 --- a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml @@ -79,6 +79,7 @@ http://i.imgur.com/HRriOVR.png http://i.imgur.com/Vcu67UR.png https://i.imgur.com/oKHx3bv.png + https://i.imgur.com/r9fuJBJ.png http://i.imgur.com/kju0sKw.jpg https://i.imgur.com/tsOM1am.png https://i.imgur.com/fPZQg7z.png diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index d1afdd95f..326ac09e9 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -19,6 +19,7 @@ ext { mapboxPluginTraffic : '0.8.0', mapboxChinaPlugin : '2.1.0', mapboxPluginMarkerView : '0.2.0', + mapboxPluginAnnotation : '0.5.0', // Support supportLib : '28.0.0', @@ -73,6 +74,7 @@ ext { mapboxPluginTraffic : "com.mapbox.mapboxsdk:mapbox-android-plugin-traffic-v7:${version.mapboxPluginTraffic}", mapboxChinaPlugin : "com.mapbox.mapboxsdk:mapbox-android-plugin-china:${version.mapboxChinaPlugin}", mapboxPluginMarkerView : "com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:${version.mapboxPluginMarkerView}", + mapboxPluginAnnotation : "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:${version.mapboxPluginAnnotation}", // Support supportV4 : "com.android.support:support-v4:${version.supportLib}",