Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #4702 - upgrade default styles, deprecate Style string defi…
Browse files Browse the repository at this point in the history
…nition in favour versioned styling methods.
  • Loading branch information
tobrun committed Apr 23, 2016
1 parent c2dee9b commit 81ddb5a
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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.
Expand All @@ -16,40 +18,149 @@
*/
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.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getMapboxStreetsUrl(int version) {
return String.format(Locale.getDefault(), MAPBOX_STREETS_BASE, version);
}

/**
* Get versioned url of Light style.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getLightStyleUrl(int version) {
return String.format(Locale.getDefault(), LIGHT_BASE, version);
}

/**
* Get versioned url of Dark style.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getDarkStyleUrl(int version) {
return String.format(Locale.getDefault(), DARK_BASE, version);
}

/**
* Get versioned url of Satellite style.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getSatelliteStyleUrl(int version) {
return String.format(Locale.getDefault(), SATELLITE_BASE, version);
}

/**
* Get versioned url of Satellite streets style.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getSatelliteStreetsStyleUrl(int version) {
return String.format(Locale.getDefault(), SATELLITE_STREETS_BASE, version);
}

/**
* Get versioned url of Outdoors streets style.
*
* @param version the version of the style.
* @return uri to load style from
*/
public static String getOutdoorsStyleUrl(int version) {
return String.format(Locale.getDefault(), OUTDOORS_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 {
}

// IMPORTANT: If you change any of these you also need to edit them in strings.xml

/**
* 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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public void onResume() {

if (mStyleUrl == null) {
// user has failed to supply a style url
setStyleUrl(Style.MAPBOX_STREETS);
setStyleUrl(Style.getMapboxStreetsUrl(getResources().getInteger(R.integer.style_version)));
}
}

Expand Down Expand Up @@ -759,7 +759,7 @@ void cycleDebugOptions() {
* <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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public void cycleDebugOptions() {
* <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.
Expand Down Expand Up @@ -539,8 +539,10 @@ public void setStyleUrl(@NonNull String url) {
*
* @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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="style_version">9</integer>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand All @@ -42,7 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
// configure inital map state
MapboxMapOptions options = new MapboxMapOptions()
.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 {

Expand All @@ -43,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {

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
Expand Down Expand Up @@ -78,8 +79,6 @@ public void onMapReady(@NonNull final MapboxMap mapboxMap) {
Log.v(MapboxConstants.TAG, mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString());
}
});


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 {

Expand All @@ -39,7 +40,7 @@ protected void onCreate(Bundle savedInstanceState) {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 {

Expand All @@ -40,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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 {

Expand All @@ -40,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;

Expand Down Expand Up @@ -60,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {

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);
Expand Down
Loading

0 comments on commit 81ddb5a

Please sign in to comment.