Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 1f2ca89

Browse files
authored
Add symbol listener activity (#1000)
* update gradle to include annotation plugin * add activity and layout * add strings * update manifest and main activity * add java 8 compatibility, annotatino plugin * fix up symbol listener activity * checkstyle spacing fix * MainActivity spacing fix * updates per langston's revie * spacing fix * add back java 8
1 parent 170d8ab commit 1f2ca89

File tree

9 files changed

+207
-9
lines changed

9 files changed

+207
-9
lines changed

MapboxAndroidDemo/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ android {
1010
compileSdkVersion androidVersions.compileSdkVersion
1111
buildToolsVersion androidVersions.buildToolsVersion
1212

13+
compileOptions {
14+
sourceCompatibility 1.8
15+
targetCompatibility 1.8
16+
}
17+
1318
playAccountConfigs {
1419
defaultAccountConfig {
1520
serviceAccountEmail = 'mapbox-android-demo-publish@android-gl-native.iam.gserviceaccount.com'
@@ -127,6 +132,7 @@ dependencies {
127132
implementation dependenciesList.mapboxPluginLocalization
128133
implementation dependenciesList.mapboxPluginTraffic
129134
implementation dependenciesList.mapboxPluginMarkerView
135+
implementation dependenciesList.mapboxPluginAnnotation
130136

131137
// Firebase
132138
globalImplementation dependenciesList.firebaseCrash

MapboxAndroidDemo/src/global/java/com/mapbox/mapboxandroiddemo/MainActivity.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import com.mapbox.mapboxandroiddemo.adapter.ExampleAdapter;
3131
import com.mapbox.mapboxandroiddemo.commons.AnalyticsTracker;
3232
import com.mapbox.mapboxandroiddemo.commons.FirstTimeRunChecker;
33-
import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedMarkerActivity;
34-
import com.mapbox.mapboxandroiddemo.examples.dds.DrawPolygonActivity;
3533
import com.mapbox.mapboxandroiddemo.examples.basics.MapboxMapOptionActivity;
3634
import com.mapbox.mapboxandroiddemo.examples.basics.SimpleMapViewActivity;
3735
import com.mapbox.mapboxandroiddemo.examples.basics.SimpleMapViewActivityKotlin;
@@ -46,6 +44,7 @@
4644
import com.mapbox.mapboxandroiddemo.examples.dds.CircleLayerClusteringActivity;
4745
import com.mapbox.mapboxandroiddemo.examples.dds.CreateHotspotsActivity;
4846
import com.mapbox.mapboxandroiddemo.examples.dds.DrawGeojsonLineActivity;
47+
import com.mapbox.mapboxandroiddemo.examples.dds.DrawPolygonActivity;
4948
import com.mapbox.mapboxandroiddemo.examples.dds.ExpressionIntegrationActivity;
5049
import com.mapbox.mapboxandroiddemo.examples.dds.HeatmapActivity;
5150
import com.mapbox.mapboxandroiddemo.examples.dds.ImageClusteringActivity;
@@ -73,6 +72,7 @@
7372
import com.mapbox.mapboxandroiddemo.examples.javaservices.StaticImageActivity;
7473
import com.mapbox.mapboxandroiddemo.examples.javaservices.TilequeryActivity;
7574
import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedImageGifActivity;
75+
import com.mapbox.mapboxandroiddemo.examples.labs.AnimatedMarkerActivity;
7676
import com.mapbox.mapboxandroiddemo.examples.labs.CalendarIntegrationActivity;
7777
import com.mapbox.mapboxandroiddemo.examples.labs.DashedLineDirectionsPickerActivity;
7878
import com.mapbox.mapboxandroiddemo.examples.labs.IndoorMapActivity;
@@ -98,6 +98,7 @@
9898
import com.mapbox.mapboxandroiddemo.examples.plugins.MarkerViewPluginActivity;
9999
import com.mapbox.mapboxandroiddemo.examples.plugins.PlaceSelectionPluginActivity;
100100
import com.mapbox.mapboxandroiddemo.examples.plugins.PlacesPluginActivity;
101+
import com.mapbox.mapboxandroiddemo.examples.plugins.SymbolListenerActivity;
101102
import com.mapbox.mapboxandroiddemo.examples.plugins.TrafficPluginActivity;
102103
import com.mapbox.mapboxandroiddemo.examples.query.BuildingOutlineActivity;
103104
import com.mapbox.mapboxandroiddemo.examples.query.ClickOnLayerActivity;
@@ -666,6 +667,13 @@ private void initializeModels() {
666667
null,
667668
R.string.activity_plugins_places_plugin_url, false, BuildConfig.MIN_SDK_VERSION));
668669

670+
exampleItemModels.add(new ExampleItemModel(
671+
R.id.nav_plugins,
672+
R.string.activity_plugins_symbol_listener_title, R.string.activity_plugins_symbol_listener_description,
673+
new Intent(MainActivity.this, SymbolListenerActivity.class),
674+
null,
675+
R.string.activity_plugins_symbol_listener_url, false, BuildConfig.MIN_SDK_VERSION));
676+
669677
exampleItemModels.add(new ExampleItemModel(
670678
R.id.nav_plugins,
671679
R.string.activity_plugins_localization_plugin_title,
@@ -1011,12 +1019,12 @@ private void initializeModels() {
10111019
));
10121020

10131021
exampleItemModels.add(new ExampleItemModel(
1014-
R.id.nav_lab,
1015-
R.string.activity_lab_fog_background_title,
1016-
R.string.activity_lab_fog_background_description,
1017-
new Intent(MainActivity.this, MapFogBackgroundActivity.class),
1018-
null,
1019-
R.string.activity_lab_fog_background_url, false, BuildConfig.MIN_SDK_VERSION
1022+
R.id.nav_lab,
1023+
R.string.activity_lab_fog_background_title,
1024+
R.string.activity_lab_fog_background_description,
1025+
new Intent(MainActivity.this, MapFogBackgroundActivity.class),
1026+
null,
1027+
R.string.activity_lab_fog_background_url, false, BuildConfig.MIN_SDK_VERSION
10201028
));
10211029

10221030
exampleItemModels.add(new ExampleItemModel(
@@ -1222,4 +1230,4 @@ private void initializeModels() {
12221230
null,
12231231
R.string.activity_basic_mapbox_options_url, false, BuildConfig.MIN_SDK_VERSION));
12241232
}
1225-
}
1233+
}

MapboxAndroidDemo/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@
642642
android:name="android.support.PARENT_ACTIVITY"
643643
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
644644
</activity>
645+
<activity
646+
android:name=".examples.plugins.SymbolListenerActivity"
647+
android:label="Listen for Symbol interaction">
648+
<meta-data
649+
android:name="android.support.PARENT_ACTIVITY"
650+
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
651+
</activity>
645652
<activity
646653
android:name=".examples.plugins.TrafficPluginActivity"
647654
android:label="@string/activity_plugins_traffic_plugin_title">
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package com.mapbox.mapboxandroiddemo.examples.plugins;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.NonNull;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.Toast;
7+
8+
import com.mapbox.mapboxandroiddemo.R;
9+
import com.mapbox.mapboxsdk.Mapbox;
10+
import com.mapbox.mapboxsdk.geometry.LatLng;
11+
import com.mapbox.mapboxsdk.maps.MapView;
12+
import com.mapbox.mapboxsdk.maps.MapboxMap;
13+
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
14+
import com.mapbox.mapboxsdk.maps.Style;
15+
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener;
16+
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolLongClickListener;
17+
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager;
18+
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions;
19+
import com.mapbox.mapboxsdk.plugins.annotation.Symbol;
20+
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener;
21+
22+
/**
23+
* Change symbol icon by pressing on icon
24+
*/
25+
public class SymbolListenerActivity extends AppCompatActivity implements
26+
OnMapReadyCallback {
27+
28+
private MapView mapView;
29+
private static final String MAKI_ICON_CAFE = "cafe-15";
30+
private static final String MAKI_ICON_HARBOR = "harbor-15";
31+
private static final String MAKI_ICON_AIRPORT = "airport-15";
32+
private SymbolManager symbolManager;
33+
private Symbol symbol;
34+
35+
@Override
36+
protected void onCreate(Bundle savedInstanceState) {
37+
super.onCreate(savedInstanceState);
38+
39+
// Mapbox access token is configured here. This needs to be called either in your application
40+
// object or in the same activity which contains the mapview.
41+
Mapbox.getInstance(this, getString(R.string.access_token));
42+
43+
// This contains the MapView in XML and needs to be called after the access token is configured.
44+
setContentView(R.layout.activity_annotation_plugin_symbol_activity);
45+
46+
mapView = findViewById(R.id.mapView);
47+
mapView.onCreate(savedInstanceState);
48+
mapView.getMapAsync(this);
49+
}
50+
51+
@Override
52+
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
53+
mapboxMap.setStyle(Style.DARK, new Style.OnStyleLoaded() {
54+
@Override
55+
public void onStyleLoaded(@NonNull Style style) {
56+
57+
// Set up a SymbolManager instance
58+
symbolManager = new SymbolManager(mapView, mapboxMap, style);
59+
60+
symbolManager.setIconAllowOverlap(true);
61+
symbolManager.setTextAllowOverlap(true);
62+
63+
// Add symbol at specified lat/lon
64+
symbol = symbolManager.create(new SymbolOptions()
65+
.withLatLng(new LatLng(60.169091, 24.939876))
66+
.withIconImage(MAKI_ICON_HARBOR)
67+
.withIconSize(2.0f)
68+
.setDraggable(true));
69+
70+
// Add click listener and change the symbol to a cafe icon on click
71+
symbolManager.addClickListener(new OnSymbolClickListener() {
72+
@Override
73+
public void onAnnotationClick(Symbol symbol) {
74+
Toast.makeText(SymbolListenerActivity.this,
75+
String.format("Symbol clicked"),
76+
Toast.LENGTH_SHORT).show();
77+
symbol.setIconImage(MAKI_ICON_CAFE);
78+
symbolManager.update(symbol);
79+
}
80+
});
81+
82+
// Add long click listener and change the symbol to an airport icon on long click
83+
symbolManager.addLongClickListener((new OnSymbolLongClickListener() {
84+
@Override
85+
public void onAnnotationLongClick(Symbol symbol) {
86+
Toast.makeText(SymbolListenerActivity.this,
87+
String.format("Symbol long clicked"),
88+
Toast.LENGTH_SHORT).show();
89+
symbol.setIconImage(MAKI_ICON_AIRPORT);
90+
symbolManager.update(symbol);
91+
}
92+
}));
93+
94+
symbolManager.addDragListener(new OnSymbolDragListener() {
95+
@Override
96+
// Left empty on purpose
97+
public void onAnnotationDragStarted(Symbol annotation) {
98+
}
99+
100+
@Override
101+
// Left empty on purpose
102+
public void onAnnotationDrag(Symbol symbol) {
103+
}
104+
105+
@Override
106+
// Left empty on purpose
107+
public void onAnnotationDragFinished(Symbol annotation) {
108+
}
109+
});
110+
}
111+
});
112+
}
113+
114+
@Override
115+
public void onResume() {
116+
super.onResume();
117+
mapView.onResume();
118+
}
119+
120+
@Override
121+
protected void onStart() {
122+
super.onStart();
123+
mapView.onStart();
124+
}
125+
126+
@Override
127+
protected void onStop() {
128+
super.onStop();
129+
mapView.onStop();
130+
}
131+
132+
@Override
133+
public void onPause() {
134+
super.onPause();
135+
mapView.onPause();
136+
}
137+
138+
@Override
139+
public void onLowMemory() {
140+
super.onLowMemory();
141+
mapView.onLowMemory();
142+
}
143+
144+
@Override
145+
protected void onDestroy() {
146+
super.onDestroy();
147+
mapView.onDestroy();
148+
}
149+
150+
@Override
151+
protected void onSaveInstanceState(Bundle outState) {
152+
super.onSaveInstanceState(outState);
153+
mapView.onSaveInstanceState(outState);
154+
}
155+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.mapbox.mapboxsdk.maps.MapView
9+
android:id="@+id/mapView"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
mapbox:mapbox_cameraTargetLng="24.939876"
13+
mapbox:mapbox_cameraTargetLat="60.169091"
14+
mapbox:mapbox_cameraZoom="12"
15+
/>
16+
17+
</android.support.design.widget.CoordinatorLayout>

MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<string name="activity_plugins_building_plugin_description">Use the building plugin to easily display 3D building height</string>
8282
<string name="activity_plugins_geojson_plugin_description">Easily retrieve GeoJSON data from a url, asset, or path</string>
8383
<string name="activity_plugins_places_plugin_description">Add location search ("geocoding") functionality and UI to search for any place in the world</string>
84+
<string name="activity_plugins_symbol_listener_description">Listen for Symbol interaction using the Annotation plugin its and built-in listeners</string>
8485
<string name="activity_plugins_localization_plugin_description">Use the plugin to automatically change map label text to the language set on the device.</string>
8586
<string name="activity_plugins_place_picker_plugin_description">Use the place picker function of the Places Plugin to choose a specific location in the world.</string>
8687
<string name="activity_plugins_markerview_plugin_description">Create a marker with an Android-system View.</string>

MapboxAndroidDemo/src/main/res/values/titles_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<string name="activity_plugins_localization_plugin_title">Change map text to device language</string>
8282
<string name="activity_plugins_geojson_plugin_title">Load GeoJSON data</string>
8383
<string name="activity_plugins_places_plugin_title">Location search</string>
84+
<string name="activity_plugins_symbol_listener_title">Symbol listener</string>
8485
<string name="activity_plugins_place_picker_plugin_title">Place picker</string>
8586
<string name="activity_plugins_markerview_plugin_title">MarkerView</string>
8687
<string name="activity_location_user_location_map_frag_title">Show a user\'s location on a map fragment</string>

MapboxAndroidDemo/src/main/res/values/urls_strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<string name="activity_plugins_traffic_plugin_url" translatable="false">http://i.imgur.com/HRriOVR.png</string>
8080
<string name="activity_plugins_building_plugin_url" translatable="false">http://i.imgur.com/Vcu67UR.png</string>
8181
<string name="activity_plugins_places_plugin_url" translatable="false">https://i.imgur.com/oKHx3bv.png</string>
82+
<string name="activity_plugins_symbol_listener_url" translatable="false">https://i.imgur.com/r9fuJBJ.png</string>
8283
<string name="activity_plugins_geojson_plugin_url" translatable="false">http://i.imgur.com/kju0sKw.jpg</string>
8384
<string name="activity_plugins_localization_plugin_url" translatable="false">https://i.imgur.com/tsOM1am.png</string>
8485
<string name="activity_plugins_place_picker_plugin_url" translatable="false">https://i.imgur.com/fPZQg7z.png</string>

gradle/dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ext {
1919
mapboxPluginTraffic : '0.8.0',
2020
mapboxChinaPlugin : '2.1.0',
2121
mapboxPluginMarkerView : '0.2.0',
22+
mapboxPluginAnnotation : '0.5.0',
2223

2324
// Support
2425
supportLib : '28.0.0',
@@ -73,6 +74,7 @@ ext {
7374
mapboxPluginTraffic : "com.mapbox.mapboxsdk:mapbox-android-plugin-traffic-v7:${version.mapboxPluginTraffic}",
7475
mapboxChinaPlugin : "com.mapbox.mapboxsdk:mapbox-android-plugin-china:${version.mapboxChinaPlugin}",
7576
mapboxPluginMarkerView : "com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v7:${version.mapboxPluginMarkerView}",
77+
mapboxPluginAnnotation : "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:${version.mapboxPluginAnnotation}",
7678

7779
// Support
7880
supportV4 : "com.android.support:support-v4:${version.supportLib}",

0 commit comments

Comments
 (0)