[android] - Remove StyleInitializer class, obsolete with introduction MapboxAccountManager
This commit is contained in:
@@ -155,7 +155,7 @@ public class MapView extends FrameLayout {
|
||||
|
||||
private PointF mFocalPoint;
|
||||
|
||||
private StyleInitializer mStyleInitializer;
|
||||
private String mStyleUrl;
|
||||
|
||||
private List<OnMapReadyCallback> mOnMapReadyCallbackList;
|
||||
|
||||
@@ -189,7 +189,6 @@ public class MapView extends FrameLayout {
|
||||
mOnMapChangedListener = new CopyOnWriteArrayList<>();
|
||||
mMapboxMap = new MapboxMap(this);
|
||||
mIcons = new ArrayList<>();
|
||||
mStyleInitializer = new StyleInitializer(context);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this);
|
||||
|
||||
if (!isInEditMode()) {
|
||||
@@ -262,21 +261,22 @@ public class MapView extends FrameLayout {
|
||||
mMyLocationView.setTilt(position.tilt);
|
||||
}
|
||||
|
||||
String accessToken = null;
|
||||
// access token
|
||||
String accessToken;
|
||||
if (MapboxAccountManager.getInstance() != null) {
|
||||
accessToken = MapboxAccountManager.getInstance().getAccessToken();
|
||||
} else {
|
||||
accessToken = options.getAccessToken();
|
||||
}
|
||||
|
||||
String style = options.getStyle();
|
||||
if (!TextUtils.isEmpty(accessToken)) {
|
||||
mMapboxMap.setAccessToken(accessToken);
|
||||
if (style != null) {
|
||||
setStyleUrl(style);
|
||||
}
|
||||
} else {
|
||||
mStyleInitializer.setStyle(style, true);
|
||||
}
|
||||
|
||||
// style url
|
||||
String style = options.getStyle();
|
||||
if (!TextUtils.isEmpty(style)) {
|
||||
mMapboxMap.setStyleUrl(style);
|
||||
}
|
||||
|
||||
// MyLocationView
|
||||
@@ -481,7 +481,7 @@ public class MapView extends FrameLayout {
|
||||
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
|
||||
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition());
|
||||
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, mStyleInitializer.getStyle());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, mStyleUrl);
|
||||
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled());
|
||||
|
||||
// TrackingSettings
|
||||
@@ -563,9 +563,9 @@ public class MapView extends FrameLayout {
|
||||
mNativeMapView.update();
|
||||
mMyLocationView.onResume();
|
||||
|
||||
if (mStyleInitializer.isDefaultStyle()) {
|
||||
if (mStyleUrl == null) {
|
||||
// user has failed to supply a style url
|
||||
setStyleUrl(mStyleInitializer.getStyle());
|
||||
setStyleUrl(Style.MAPBOX_STREETS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -819,7 +819,7 @@ public class MapView extends FrameLayout {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mStyleInitializer.setStyle(url);
|
||||
mStyleUrl = url;
|
||||
mNativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
@@ -853,7 +853,7 @@ public class MapView extends FrameLayout {
|
||||
@UiThread
|
||||
@NonNull
|
||||
public String getStyleUrl() {
|
||||
return mStyleInitializer.getStyle();
|
||||
return mStyleUrl;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1137,7 +1137,7 @@ public class MapView extends FrameLayout {
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
idsList.add(ids[i]);
|
||||
}
|
||||
|
||||
|
||||
List<MarkerView> annotations = new ArrayList<>(ids.length);
|
||||
List<Annotation> annotationList = mMapboxMap.getAnnotations();
|
||||
int count = annotationList.size();
|
||||
@@ -2749,41 +2749,6 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class responsible for managing state of Style loading.
|
||||
*/
|
||||
static class StyleInitializer {
|
||||
|
||||
private String mStyle;
|
||||
private boolean mDefaultStyle;
|
||||
|
||||
StyleInitializer(@NonNull Context context) {
|
||||
mStyle = Style.MAPBOX_STREETS;
|
||||
mDefaultStyle = true;
|
||||
}
|
||||
|
||||
void setStyle(@NonNull String style) {
|
||||
setStyle(style, false);
|
||||
}
|
||||
|
||||
void setStyle(@NonNull String style, boolean defaultStyle) {
|
||||
if (style == null) {
|
||||
// don't override default style
|
||||
return;
|
||||
}
|
||||
mStyle = style;
|
||||
mDefaultStyle = defaultStyle;
|
||||
}
|
||||
|
||||
public String getStyle() {
|
||||
return mStyle;
|
||||
}
|
||||
|
||||
boolean isDefaultStyle() {
|
||||
return mDefaultStyle;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition of a map change event.
|
||||
*
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class StyleInitializerTest {
|
||||
|
||||
@InjectMocks
|
||||
Context context = mock(Context.class);
|
||||
|
||||
@InjectMocks
|
||||
Resources resources = mock(Resources.class);
|
||||
|
||||
MapView.StyleInitializer initializer;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
when(resources.getInteger(R.integer.style_version)).thenReturn(AppConstant.STYLE_VERSION);
|
||||
initializer = new MapView.StyleInitializer(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("initializer should not be null", initializer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultStyle() {
|
||||
assertTrue(initializer.isDefaultStyle());
|
||||
assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStyle() {
|
||||
String customStyle = "test";
|
||||
initializer.setStyle(customStyle);
|
||||
assertFalse(initializer.isDefaultStyle());
|
||||
assertEquals(customStyle, initializer.getStyle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStyleNull() {
|
||||
String customStyle = null;
|
||||
initializer.setStyle(customStyle);
|
||||
assertTrue(initializer.isDefaultStyle());
|
||||
assertEquals(String.format(Locale.US, "mapbox://styles/mapbox/streets-v%d", AppConstant.STYLE_VERSION), "mapbox://styles/mapbox/streets-v9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideDefaultStyle() {
|
||||
String customStyle = "test";
|
||||
initializer.setStyle(customStyle, true);
|
||||
assertTrue(initializer.isDefaultStyle());
|
||||
assertEquals(customStyle, initializer.getStyle());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user