[android] #4702 - upgrade default styles, deprecate Style string definition in favour versioned styling methods.

This commit is contained in:
Tobrun
2016-04-23 08:19:00 +02:00
committed by Minh Nguyễn
parent 2a4eeadb29
commit da422ff44d
17 changed files with 246 additions and 41 deletions

View File

@@ -1,11 +1,14 @@
package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntRange;
import android.support.annotation.StringDef;
import com.mapbox.mapboxsdk.maps.MapView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Locale;
/**
* <p>
* Style provides URLs to several professional styles designed by Mapbox.
@@ -16,11 +19,147 @@ import java.lang.annotation.RetentionPolicy;
*/
public class Style {
/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data.
*/
private static final String MAPBOX_STREETS_BASE = "mapbox://styles/mapbox/streets-v%d";
/**
* Outdoors: A rugged style that emphasizes physical terrain and outdoor activities.
*/
private static final String OUTDOORS_BASE = "mapbox://styles/mapbox/outdoors-v%d";
/**
* Light: Subtle light backdrop for data visualizations.
*/
private static final String LIGHT_BASE = "mapbox://styles/mapbox/light-v%d";
/**
* Dark: Subtle dark backdrop for data visualizations.
*/
private static final String DARK_BASE = "mapbox://styles/mapbox/dark-v%d";
/**
* Satellite: A beautiful global satellite and aerial imagery layer.
*/
private static final String SATELLITE_BASE = "mapbox://styles/mapbox/satellite-v%d";
/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels.
*/
private static final String SATELLITE_STREETS_BASE = "mapbox://styles/mapbox/satellite-hybrid-v%d";
/**
* Get versioned url of Mapbox streets style.
* <p>
* <ul>
* <li>Current default version is 9.</li>
* </ul
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getMapboxStreetsUrl(int version) {
return String.format(Locale.US, MAPBOX_STREETS_BASE, version);
}
/**
* Get versioned url of Outdoors streets style.
* <p>
* <ul>
* <li>Current version is 9.</li>
* </ul>
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getOutdoorsStyleUrl(int version) {
return String.format(Locale.US, OUTDOORS_BASE, version);
}
/**
* Get versioned url of Light style.
* <p>
* <ul>
* <li>Current default version is 9.</li>
* </ul>
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getLightStyleUrl(int version) {
return String.format(Locale.US, LIGHT_BASE, version);
}
/**
* Get versioned url of Dark style.
* <p>
* <ul>
* <li>Current default version is 9.</li>
* </ul>
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getDarkStyleUrl(int version) {
return String.format(Locale.US, DARK_BASE, version);
}
/**
* Get versioned url of Satellite style.
* <p>
* <ul>
* <li>Current version is 9.</li>
* </ul>
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getSatelliteStyleUrl(int version) {
return String.format(Locale.US, SATELLITE_BASE, version);
}
/**
* Get versioned url of Satellite streets style.
* <p>
* <ul>
* <li>Current version is 9.</li>
* </ul>
* </p>
* <p>
* More information on the Mapbox styles API can be found on https://www.mapbox.com/api-documentation/#styles
* </p>
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getSatelliteStreetsStyleUrl(int version) {
return String.format(Locale.US, SATELLITE_STREETS_BASE, version);
}
/**
* Indicates the parameter accepts one of the values from {@link Style}.
*
* @deprecated use dedicated versioned methods in {@link Style} instead.
*/
@StringDef({MAPBOX_STREETS, EMERALD, LIGHT, DARK, SATELLITE, SATELLITE_STREETS})
@Retention(RetentionPolicy.SOURCE)
@Deprecated
public @interface StyleUrl {
}
@@ -28,28 +167,49 @@ public class Style {
/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data.
*
* @deprecated use {@link #getMapboxStreetsUrl(int)} instead.
*/
public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v8";
@Deprecated
public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v9";
/**
* Emerald: A versatile style, with emphasis on road networks and public transit.
*
* @deprecated this style has been deprecated and will be removed in future versions.
*/
@Deprecated
public static final String EMERALD = "mapbox://styles/mapbox/emerald-v8";
/**
* Light: Subtle light backdrop for data visualizations.
*
* @deprecated use {@link #getLightStyleUrl(int)} instead.
*/
public static final String LIGHT = "mapbox://styles/mapbox/light-v8";
@Deprecated
public static final String LIGHT = "mapbox://styles/mapbox/light-v9";
/**
* Dark: Subtle dark backdrop for data visualizations.
*
* @deprecated use {@link #getDarkStyleUrl(int)} (int)} instead.
*/
public static final String DARK = "mapbox://styles/mapbox/dark-v8";
@Deprecated
public static final String DARK = "mapbox://styles/mapbox/dark-v9";
/**
* Satellite: A beautiful global satellite and aerial imagery layer.
*
* @deprecated use {@link #getSatelliteStyleUrl(int)} instead.
*/
public static final String SATELLITE = "mapbox://styles/mapbox/satellite-v8";
@Deprecated
public static final String SATELLITE = "mapbox://styles/mapbox/satellite-v9";
/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels.
*
* @deprecated use {@link #getSatelliteStreetsStyleUrl(int)} (int)} instead.
*/
public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-hybrid-v8";
@Deprecated
public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-hybrid-v9";
}

View File

@@ -779,7 +779,7 @@ public class MapView extends FrameLayout {
* <li>{@code asset://...}:
* reads the style from the APK {@code assets/} directory.
* This is used to load a style bundled with your app.</li>
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
* <li>{@code null}: loads the default {@link Style#getMapboxStreetsUrl(int)} style.</li>
* </ul>
* <p>
* This method is asynchronous and will return immediately before the style finishes loading.
@@ -2679,7 +2679,7 @@ public class MapView extends FrameLayout {
private boolean mDefaultStyle;
public StyleInitializer() {
mStyle = Style.MAPBOX_STREETS;
mStyle = Style.getMapboxStreetsUrl(getResources().getInteger(R.integer.style_version));
mDefaultStyle = true;
}

View File

@@ -523,7 +523,7 @@ public class MapboxMap {
* <li>{@code asset://...}:
* reads the style from the APK {@code assets/} directory.
* This is used to load a style bundled with your app.</li>
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
* <li>{@code null}: loads the default {@link Style#getMapboxStreetsUrl(int)} style.</li>
* </ul>
* <p>
* This method is asynchronous and will return immediately before the style finishes loading.
@@ -553,8 +553,10 @@ public class MapboxMap {
*
* @param style The bundled style. Accepts one of the values from {@link Style}.
* @see Style
* @deprecated use {@link #setStyleUrl(String)} instead with versioned url methods from {@link Style}
*/
@UiThread
@Deprecated
public void setStyle(@Style.StyleUrl String style) {
setStyleUrl(style);
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="style_version">9</integer>
</resources>

View File

@@ -11,10 +11,11 @@
<string name="infoWindowAddress">Address</string>
<!-- these are public -->
<string name="style_mapbox_streets">mapbox://styles/mapbox/streets-v8</string>
<!-- {@deprecated Use Style.getXStyleUrl(int version) instead.} -->
<string name="style_mapbox_streets">mapbox://styles/mapbox/streets-v9</string>
<string name="style_emerald">mapbox://styles/mapbox/emerald-v8</string>
<string name="style_light">mapbox://styles/mapbox/light-v8</string>
<string name="style_dark">mapbox://styles/mapbox/dark-v8</string>
<string name="style_satellite">mapbox://styles/mapbox/satellite-v8</string>
<string name="style_satellite_streets">mapbox://styles/mapbox/satellite-hybrid-v8</string>
<string name="style_light">mapbox://styles/mapbox/light-v9</string>
<string name="style_dark">mapbox://styles/mapbox/dark-v9</string>
<string name="style_satellite">mapbox://styles/mapbox/satellite-v9</string>
<string name="style_satellite_streets">mapbox://styles/mapbox/satellite-hybrid-v9</string>
</resources>

View File

@@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
import java.util.ArrayList;
import java.util.List;
@@ -43,7 +44,7 @@ public class PolygonActivity extends AppCompatActivity {
MapboxMapOptions options = new MapboxMapOptions()
.attributionTintColor(Color.RED)
.accessToken(getString(R.string.mapbox_access_token))
.styleUrl(Style.MAPBOX_STREETS)
.styleUrl(Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION))
.camera(new CameraPosition.Builder()
.target(new LatLng(45.520486, -122.673541))
.zoom(12)

View File

@@ -19,6 +19,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class LatLngBoundsActivity extends AppCompatActivity {
@@ -43,7 +44,7 @@ public class LatLngBoundsActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(getString(R.string.mapbox_access_token));
mMapView.setStyle(Style.DARK);
mMapView.setStyleUrl(Style.getDarkStyleUrl(AppConstant.STYLE_VERSION));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
@@ -78,8 +79,6 @@ public class LatLngBoundsActivity extends AppCompatActivity {
Log.v(MapboxConstants.TAG, mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString());
}
});
}
@Override

View File

@@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class ManualZoomActivity extends AppCompatActivity {
@@ -39,7 +40,7 @@ public class ManualZoomActivity extends AppCompatActivity {
mMapView = (MapView) findViewById(R.id.manualZoomMapView);
mMapView.setAccessToken(getString(R.string.mapbox_access_token));
mMapView.setStyleUrl(Style.SATELLITE_STREETS);
mMapView.setStyleUrl(Style.getSatelliteStyleUrl(AppConstant.STYLE_VERSION));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override

View File

@@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class MapFragmentActivity extends AppCompatActivity {
@@ -40,7 +41,7 @@ public class MapFragmentActivity extends AppCompatActivity {
MapboxMapOptions options = new MapboxMapOptions();
options.accessToken(getString(R.string.mapbox_access_token));
options.styleUrl(Style.EMERALD);
options.styleUrl(Style.getOutdoorsStyleUrl(AppConstant.STYLE_VERSION));
options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);

View File

@@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class SupportMapFragmentActivity extends AppCompatActivity {
@@ -40,7 +41,7 @@ public class SupportMapFragmentActivity extends AppCompatActivity {
MapboxMapOptions options = new MapboxMapOptions();
options.accessToken(getString(R.string.mapbox_access_token));
options.styleUrl(Style.SATELLITE_STREETS);
options.styleUrl(Style.getSatelliteStreetsStyleUrl(AppConstant.STYLE_VERSION));
options.scrollGesturesEnabled(false);
options.zoomGesturesEnabled(false);

View File

@@ -27,6 +27,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Projection;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
import java.util.List;
@@ -60,7 +61,7 @@ public class GeocoderActivity extends AppCompatActivity {
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(getString(R.string.mapbox_access_token));
mapView.setStyle(Style.MAPBOX_STREETS);
mapView.setStyleUrl(Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION));
mapView.onCreate(savedInstanceState);
final ImageView dropPinView = new ImageView(this);

View File

@@ -9,20 +9,31 @@ import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class DebugModeActivity extends AppCompatActivity {
public class DebugModeActivity extends AppCompatActivity {
private static final String TAG = "DebugModeActivity";
private MapView mapView;
private MapboxMap mapboxMap;
private String currentStyle = Style.MAPBOX_STREETS;
private int currentStyleIndex = 0;
private static final String[] STYLES = new String[]{
Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION),
Style.getOutdoorsStyleUrl(AppConstant.STYLE_VERSION),
Style.getLightStyleUrl(AppConstant.STYLE_VERSION),
Style.getDarkStyleUrl(AppConstant.STYLE_VERSION),
Style.getSatelliteStyleUrl(AppConstant.STYLE_VERSION),
Style.getSatelliteStreetsStyleUrl(AppConstant.STYLE_VERSION)
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -41,6 +52,7 @@ public class DebugModeActivity extends AppCompatActivity {
mapView = (MapView) findViewById(R.id.mapView);
mapView.setTag(true);
mapView.setAccessToken(getString(R.string.mapbox_access_token));
mapView.setStyleUrl(STYLES[currentStyleIndex]);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@@ -65,20 +77,13 @@ public class DebugModeActivity extends AppCompatActivity {
fabStyles.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (currentStyle.equals(Style.MAPBOX_STREETS)) {
currentStyle = Style.EMERALD;
} else if (currentStyle.equals(Style.EMERALD)) {
currentStyle = Style.DARK;
} else if (currentStyle.equals(Style.DARK)) {
currentStyle = Style.LIGHT;
} else if (currentStyle.equals(Style.LIGHT)) {
currentStyle = Style.SATELLITE;
} else if (currentStyle.equals(Style.SATELLITE)) {
currentStyle = Style.SATELLITE_STREETS;
} else {
currentStyle = Style.MAPBOX_STREETS;
if (mapboxMap != null) {
currentStyleIndex++;
if (currentStyleIndex == STYLES.length) {
currentStyleIndex = 0;
}
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
}
mapboxMap.setStyle(currentStyle);
}
});
}

View File

@@ -23,6 +23,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class DoubleMapActivity extends AppCompatActivity {
@@ -72,7 +73,7 @@ public class DoubleMapActivity extends AppCompatActivity {
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.DARK);
mapboxMap.setStyleUrl(Style.getDarkStyleUrl(AppConstant.STYLE_VERSION));
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18));
try {
@@ -91,7 +92,7 @@ public class DoubleMapActivity extends AppCompatActivity {
mMapViewMini.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.LIGHT);
mapboxMap.setStyleUrl(Style.getLightStyleUrl(AppConstant.STYLE_VERSION));
mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
UiSettings uiSettings = mapboxMap.getUiSettings();

View File

@@ -27,6 +27,7 @@ import com.mapbox.mapboxsdk.offline.OfflineRegionError;
import com.mapbox.mapboxsdk.offline.OfflineRegionStatus;
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
import com.mapbox.mapboxsdk.testapp.model.other.OfflineDownloadRegionDialog;
import com.mapbox.mapboxsdk.testapp.model.other.OfflineListRegionsDialog;
@@ -77,7 +78,7 @@ public class OfflineActivity extends AppCompatActivity
// Set up map
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(getString(R.string.mapbox_access_token));
mMapView.setStyle(Style.MAPBOX_STREETS);
mMapView.setStyleUrl(Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION));
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override

View File

@@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
public class MyLocationCustomizationActivity extends AppCompatActivity implements LocationListener {
@@ -48,7 +49,7 @@ public class MyLocationCustomizationActivity extends AppCompatActivity implement
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
mapboxMapOptions.accessToken(getString(R.string.mapbox_access_token));
mapboxMapOptions.styleUrl(Style.MAPBOX_STREETS);
mapboxMapOptions.styleUrl(Style.getMapboxStreetsUrl(AppConstant.STYLE_VERSION));
mapboxMapOptions.locationEnabled(true);
mapboxMapOptions.camera(new CameraPosition.Builder()
.target(location != null ? new LatLng(location) : new LatLng(0, 0))

View File

@@ -0,0 +1,6 @@
package com.mapbox.mapboxsdk.testapp.model.constants;
public class AppConstant {
public final static int STYLE_VERSION = 9;
}

View File

@@ -0,0 +1,20 @@
package com.mapbox.mapboxsdk.constants;
import com.mapbox.mapboxsdk.testapp.model.constants.AppConstant;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class StyleVersionTest {
private static final double DELTA = 1e-15;
@Test
public void testSanity() {
assertEquals("Style version should match, when upgrading, verify that integers.xml is updated",
AppConstant.STYLE_VERSION,
9,
DELTA);
}
}