Skip to content

Commit 61e0e5b

Browse files
authored
Update test app to v5.0 of the SDK (#300)
* update test app to 5.0 snapshot * add remaining onStart/onStop method calls * add missing prefix xml namespace app * fix issue with duplicated layers (different layers must have different ids)
1 parent 89a6b54 commit 61e0e5b

31 files changed

Lines changed: 247 additions & 72 deletions

mapbox/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ dependencies {
4141
compile "com.android.support:recyclerview-v7:25.1.0"
4242

4343
// Mapbox SDK
44-
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.1@aar') {
45-
transitive = true
46-
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-java-services'
44+
compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.0-SNAPSHOT@aar') {
45+
transitive=true
46+
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-java-geojson'
4747
}
4848

4949
// Leak Canary

mapbox/app/src/main/java/com/mapbox/services/android/testapp/MasApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import android.text.TextUtils;
55
import android.util.Log;
66

7-
import com.mapbox.mapboxsdk.MapboxAccountManager;
7+
import com.mapbox.mapboxsdk.Mapbox;
88
import com.squareup.leakcanary.LeakCanary;
99

1010
public class MasApplication extends Application {
@@ -26,6 +26,6 @@ public void onCreate() {
2626
if (TextUtils.isEmpty(mapboxAccessToken)) {
2727
Log.w(LOG_TAG, "Warning: access token isn't set.");
2828
}
29-
MapboxAccountManager.start(getApplicationContext(), mapboxAccessToken);
29+
Mapbox.getInstance(getApplicationContext(), mapboxAccessToken);
3030
}
3131
}

mapbox/app/src/main/java/com/mapbox/services/android/testapp/Utils.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
package com.mapbox.services.android.testapp;
22

33
import android.content.Context;
4-
import android.content.pm.ApplicationInfo;
5-
import android.content.pm.PackageManager;
64
import android.support.annotation.NonNull;
75

8-
import com.mapbox.mapboxsdk.constants.MapboxConstants;
6+
import com.mapbox.mapboxsdk.Mapbox;
97

108
public class Utils {
119

1210
/**
1311
* <p>
1412
* Returns the Mapbox access token set in the app resources.
1513
* </p>
16-
* It will first search the application manifest for a {@link MapboxConstants#KEY_META_DATA_MANIFEST}
17-
* meta-data value. If not found it will then attempt to load the access token from the
14+
* It will first search for a token in the Mapbox object. If not found it
15+
* will then attempt to load the access token from the
1816
* {@code res/values/dev.xml} development file.
1917
*
2018
* @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}.
2119
* @return The Mapbox access token or null if not found.
22-
* @see MapboxConstants#KEY_META_DATA_MANIFEST
2320
*/
2421
public static String getMapboxAccessToken(@NonNull Context context) {
2522
try {
2623
// Read out AndroidManifest
27-
PackageManager packageManager = context.getPackageManager();
28-
ApplicationInfo appInfo = packageManager
29-
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
30-
String token = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
24+
String token = Mapbox.getAccessToken();
3125
if (token == null || token.isEmpty()) {
3226
throw new IllegalArgumentException();
3327
}

mapbox/app/src/main/java/com/mapbox/services/android/testapp/directions/DirectionsV5Activity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ private void showMessage(String message) {
158158
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
159159
}
160160

161+
@Override
162+
protected void onStart() {
163+
super.onStart();
164+
mapView.onStart();
165+
}
166+
161167
@Override
162168
public void onResume() {
163169
super.onResume();
@@ -176,6 +182,12 @@ protected void onSaveInstanceState(Bundle outState) {
176182
mapView.onSaveInstanceState(outState);
177183
}
178184

185+
@Override
186+
protected void onStop() {
187+
super.onStop();
188+
mapView.onStop();
189+
}
190+
179191
@Override
180192
protected void onDestroy() {
181193
super.onDestroy();

mapbox/app/src/main/java/com/mapbox/services/android/testapp/directions/RouteUtilsV5Activity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ private void showMessage(String message) {
255255
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
256256
}
257257

258+
@Override
259+
protected void onStart() {
260+
super.onStart();
261+
mapView.onStart();
262+
}
263+
258264
@Override
259265
public void onResume() {
260266
super.onResume();
@@ -273,6 +279,12 @@ protected void onSaveInstanceState(Bundle outState) {
273279
mapView.onSaveInstanceState(outState);
274280
}
275281

282+
@Override
283+
protected void onStop() {
284+
super.onStop();
285+
mapView.onStop();
286+
}
287+
276288
@Override
277289
protected void onDestroy() {
278290
super.onDestroy();

mapbox/app/src/main/java/com/mapbox/services/android/testapp/distance/DistanceActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void onFailure(Call<DistanceResponse> call, Throwable throwable) {
177177
private void addMarkers() {
178178
for (int i = 0; i < restaurants.size(); i++) {
179179
CircleLayer circleLayer = new CircleLayer(
180-
"circle-layer",
180+
restaurants.get(i).getStringProperty("name") + "-circle-layer",
181181
restaurants.get(i).getStringProperty("name") + "-source"
182182
).withProperties(
183183
circleColor(Color.parseColor("#e55e5e")),
@@ -233,6 +233,12 @@ private void updateLayers() {
233233
}
234234
}
235235

236+
@Override
237+
protected void onStart() {
238+
super.onStart();
239+
mapView.onStart();
240+
}
241+
236242
@Override
237243
public void onResume() {
238244
super.onResume();
@@ -251,6 +257,12 @@ public void onLowMemory() {
251257
mapView.onLowMemory();
252258
}
253259

260+
@Override
261+
protected void onStop() {
262+
super.onStop();
263+
mapView.onStop();
264+
}
265+
254266
@Override
255267
protected void onDestroy() {
256268
super.onDestroy();

mapbox/app/src/main/java/com/mapbox/services/android/testapp/geocoding/GeocodingReverseActivity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public void onMapClick(@NonNull LatLng point) {
6767
});
6868
}
6969

70+
@Override
71+
protected void onStart() {
72+
super.onStart();
73+
mapView.onStart();
74+
}
75+
7076
@Override
7177
public void onResume() {
7278
super.onResume();
@@ -85,6 +91,12 @@ protected void onSaveInstanceState(Bundle outState) {
8591
mapView.onSaveInstanceState(outState);
8692
}
8793

94+
@Override
95+
protected void onStop() {
96+
super.onStop();
97+
mapView.onStop();
98+
}
99+
88100
@Override
89101
protected void onDestroy() {
90102
super.onDestroy();

mapbox/app/src/main/java/com/mapbox/services/android/testapp/geocoding/GeocodingWidgetActivity.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ private void updateMap(double latitude, double longitude) {
104104
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 5000, null);
105105
}
106106

107+
@Override
108+
protected void onStart() {
109+
super.onStart();
110+
mapView.onStart();
111+
}
112+
107113
@Override
108114
public void onResume() {
109115
super.onResume();
@@ -122,6 +128,12 @@ protected void onSaveInstanceState(Bundle outState) {
122128
mapView.onSaveInstanceState(outState);
123129
}
124130

131+
@Override
132+
protected void onStop() {
133+
super.onStop();
134+
mapView.onStop();
135+
}
136+
125137
@Override
126138
protected void onDestroy() {
127139
super.onDestroy();

mapbox/app/src/main/java/com/mapbox/services/android/testapp/nav/OffRouteDetectionActivity.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ public void onMapClick(@NonNull LatLng point) {
122122
});
123123
} // End onCreate
124124

125+
@Override
126+
protected void onStart() {
127+
super.onStart();
128+
mapView.onStart();
129+
}
130+
125131
@Override
126132
public void onResume() {
127133
super.onResume();
@@ -144,6 +150,12 @@ public void onLowMemory() {
144150
mapView.onLowMemory();
145151
}
146152

153+
@Override
154+
protected void onStop() {
155+
super.onStop();
156+
mapView.onStop();
157+
}
158+
147159
@Override
148160
protected void onDestroy() {
149161
super.onDestroy();
@@ -329,7 +341,7 @@ public void run() {
329341
// and starts outside the current user view. Without this, the user must
330342
// intentionally execute a gesture before the view marker reappears on
331343
// the map.
332-
map.getMarkerViewManager().scheduleViewMarkerInvalidation();
344+
map.getMarkerViewManager().update();
333345

334346
// Rotate the car (marker) to the correct orientation.
335347
car.setRotation((float) computeHeading(car.getPosition(), routePoints.get(count)));

mapbox/app/src/main/java/com/mapbox/services/android/testapp/nav/SnapToRouteActivity.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import android.view.View;
1010
import android.widget.Toast;
1111

12-
import com.mapbox.mapboxsdk.MapboxAccountManager;
12+
import com.mapbox.mapboxsdk.Mapbox;
1313
import com.mapbox.mapboxsdk.annotations.Marker;
1414
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
1515
import com.mapbox.mapboxsdk.annotations.Polyline;
@@ -230,7 +230,7 @@ private void getRoute(Position origin, Position destination) throws ServicesExce
230230
.setOverview(DirectionsCriteria.OVERVIEW_FULL)
231231
.setSteps(true)
232232
.setProfile(DirectionsCriteria.PROFILE_DRIVING)
233-
.setAccessToken(MapboxAccountManager.getInstance().getAccessToken())
233+
.setAccessToken(Mapbox.getAccessToken())
234234
.build();
235235

236236
Log.i(TAG, "Request: " + client.cloneCall().request());
@@ -311,6 +311,12 @@ private void drawStepPolyline() {
311311
.width(5));
312312
}
313313

314+
@Override
315+
protected void onStart() {
316+
super.onStart();
317+
mapView.onStart();
318+
}
319+
314320
@Override
315321
public void onResume() {
316322
super.onResume();
@@ -329,6 +335,13 @@ public void onLowMemory() {
329335
mapView.onLowMemory();
330336
}
331337

338+
@Override
339+
protected void onStop() {
340+
super.onStop();
341+
mapView.onStop();
342+
}
343+
344+
332345
@Override
333346
protected void onDestroy() {
334347
super.onDestroy();

0 commit comments

Comments
 (0)