[android] - don't load default style if style json string was set (#11519)
This commit is contained in:
@@ -111,7 +111,7 @@ public final class MapboxMap {
|
||||
void onStart() {
|
||||
nativeMapView.update();
|
||||
trackingSettings.onStart();
|
||||
if (TextUtils.isEmpty(nativeMapView.getStyleUrl())) {
|
||||
if (TextUtils.isEmpty(nativeMapView.getStyleUrl()) && TextUtils.isEmpty(nativeMapView.getStyleJson())) {
|
||||
// if user hasn't loaded a Style yet
|
||||
nativeMapView.setStyleUrl(Style.MAPBOX_STREETS);
|
||||
}
|
||||
@@ -1882,7 +1882,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the map is scrolled.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
* @deprecated Use {@link #addOnScrollListener(OnScrollListener)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -1895,7 +1894,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the map is scrolled.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
*/
|
||||
public void addOnScrollListener(@Nullable OnScrollListener listener) {
|
||||
onRegisterTouchListener.onAddScrollListener(listener);
|
||||
@@ -1906,7 +1904,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the map is scrolled.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
*/
|
||||
public void removeOnScrollListener(@Nullable OnScrollListener listener) {
|
||||
onRegisterTouchListener.onRemoveScrollListener(listener);
|
||||
@@ -1917,7 +1914,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the map is flinged.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
* @deprecated Use {@link #addOnFlingListener(OnFlingListener)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -1950,7 +1946,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the user clicks on the map view.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
* @deprecated Use {@link #addOnMapClickListener(OnMapClickListener)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -1983,7 +1978,6 @@ public final class MapboxMap {
|
||||
*
|
||||
* @param listener The callback that's invoked when the user long clicks on the map view.
|
||||
* To unset the callback, use null.
|
||||
*
|
||||
* @deprecated Use {@link #addOnMapLongClickListener(OnMapLongClickListener)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
|
||||
import android.support.test.espresso.UiController;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests around style loading
|
||||
*/
|
||||
public class StyleLoaderTest extends BaseActivityTest {
|
||||
|
||||
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return EspressoTestActivity.class;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGetStyleJsonString() throws Exception {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultStyleLoadWithActivityLifecycleChange() throws Exception {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
|
||||
// fake activity stop/start
|
||||
MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
|
||||
mapView.onPause();
|
||||
mapView.onStop();
|
||||
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl());
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user