summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-08-17 22:23:32 +0200
committerTobrun <tobrun.van.nuland@gmail.com>2018-08-21 16:25:07 +0200
commitfe04abb93deed836d9ff3ebe9850416ff0d4514c (patch)
treea3955c36afcca78405aff7da7c10af0b005546bd
parent5ce64b786cfd2fbfdc28ccfbcf9c1a5216346281 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-style-json-mapboxmap-options.tar.gz
[android] - expose stylejsoon confiugration on MapboxMapOptions and MapView attributesupstream/tvn-style-json-mapboxmap-options
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java15
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java52
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java6
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.java36
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_transparent.xml11
7 files changed, 83 insertions, 39 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 97e2e50525..45e54a3d14 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -95,6 +95,7 @@ public final class MapboxMap {
setDebugActive(options.getDebugActive());
setApiBaseUrl(options);
setStyleUrl(options);
+ setStyleJson(options);
setPrefetchesTiles(options);
}
@@ -1058,7 +1059,7 @@ public final class MapboxMap {
* @param options the object containing the style url
*/
private void setStyleUrl(@NonNull MapboxMapOptions options) {
- String style = options.getStyle();
+ String style = options.getStyleUrl();
if (!TextUtils.isEmpty(style)) {
setStyleUrl(style, null);
}
@@ -1087,6 +1088,18 @@ public final class MapboxMap {
}
/**
+ * Loads a new map style json from MapboxMapOptions if available.
+ *
+ * @param options the object containing the style json
+ */
+ private void setStyleJson(@NonNull MapboxMapOptions options) {
+ String styleJson = options.getStyleJson();
+ if (!TextUtils.isEmpty(styleJson)) {
+ setStyleJson(styleJson);
+ }
+ }
+
+ /**
* Returns the map style json currently displayed in the map view.
*
* @return The json of the map style
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
index 0075199b1e..f48bd92327 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
@@ -77,7 +77,8 @@ public class MapboxMapOptions implements Parcelable {
@ColorInt
private int foregroundLoadColor;
- private String style;
+ private String styleUrl;
+ private String styleJson;
private float pixelRatio;
@@ -120,7 +121,8 @@ public class MapboxMapOptions implements Parcelable {
zoomGesturesEnabled = in.readByte() != 0;
doubleTapGesturesEnabled = in.readByte() != 0;
- style = in.readString();
+ styleUrl = in.readString();
+ styleJson = in.readString();
apiBaseUrl = in.readString();
textureMode = in.readByte() != 0;
translucentTextureSurface = in.readByte() != 0;
@@ -145,6 +147,7 @@ public class MapboxMapOptions implements Parcelable {
try {
mapboxMapOptions.camera(new CameraPosition.Builder(typedArray).build());
mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_styleUrl));
+ mapboxMapOptions.styleJson(typedArray.getString(R.styleable.mapbox_MapView_mapbox_styleJson));
mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_apiBaseUrl));
mapboxMapOptions.zoomGesturesEnabled(
@@ -258,13 +261,24 @@ public class MapboxMapOptions implements Parcelable {
}
/**
- * Specifies the style url associated with a map view.
+ * Specifies the styleUrl url associated with a map view.
*
- * @param styleUrl Url to be used to load a style
+ * @param styleUrl Url to be used to load a styleUrl
* @return This
*/
public MapboxMapOptions styleUrl(String styleUrl) {
- style = styleUrl;
+ this.styleUrl = styleUrl;
+ return this;
+ }
+
+ /**
+ * Specifies the styleJson associated with a map view.
+ *
+ * @param styleJson json to used as style
+ * @return This
+ */
+ public MapboxMapOptions styleJson(String styleJson) {
+ this.styleJson = styleJson;
return this;
}
@@ -716,12 +730,21 @@ public class MapboxMapOptions implements Parcelable {
}
/**
- * Get the current configured style url for a map view.
+ * Get the current configured styleUrl url for a map view.
*
* @return Style url to be used.
*/
- public String getStyle() {
- return style;
+ public String getStyleUrl() {
+ return styleUrl;
+ }
+
+ /**
+ * Get the current configured styleJson for a map view.
+ *
+ * @return Style json to be used.
+ */
+ public String getStyleJson() {
+ return styleJson;
}
/**
@@ -912,7 +935,8 @@ public class MapboxMapOptions implements Parcelable {
dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0));
dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0));
- dest.writeString(style);
+ dest.writeString(styleUrl);
+ dest.writeString(styleJson);
dest.writeString(apiBaseUrl);
dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (translucentTextureSurface ? 1 : 0));
@@ -1002,9 +1026,14 @@ public class MapboxMapOptions implements Parcelable {
if (!Arrays.equals(attributionMargins, options.attributionMargins)) {
return false;
}
- if (style != null ? !style.equals(options.style) : options.style != null) {
+ if (styleUrl != null ? !styleUrl.equals(options.styleUrl) : options.styleUrl != null) {
return false;
}
+
+ if (styleJson != null ? !styleJson.equals(options.styleJson) : options.styleJson != null) {
+ return false;
+ }
+
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) {
return false;
}
@@ -1055,7 +1084,8 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (translucentTextureSurface ? 1 : 0);
- result = 31 * result + (style != null ? style.hashCode() : 0);
+ result = 31 * result + (styleUrl != null ? styleUrl.hashCode() : 0);
+ result = 31 * result + (styleJson != null ? styleJson.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
result = 31 * result + (zMediaOverlay ? 1 : 0);
result = 31 * result + (localIdeographFontFamily != null ? localIdeographFontFamily.hashCode() : 0);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index 8acb0c27cc..1c3653479a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -10,6 +10,7 @@
<!-- Exposed attrs.xml -->
<!--Configuration-->
<public name="mapbox_styleUrl" type="attr" />
+ <public name="mapbox_styleJson" type="attr" />
<public name="mapbox_apiBaseUrl" type="attr" />
<public name="mapbox_localIdeographFontFamily" type="attr" />
<public name="mapbox_pixelRatio" type="float" />
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index 3a8fa74b34..053da80ade 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -4,6 +4,7 @@
<!--Configuration-->
<attr name="mapbox_styleUrl" format="string"/>
+ <attr name="mapbox_styleJson" format="string"/>
<attr name="mapbox_apiBaseUrl" format="string"/>
<attr name="mapbox_localIdeographFontFamily" format="string"/>
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
index 9dd0ca9285..b8a377604f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
@@ -155,9 +155,9 @@ public class MapboxMapOptionsTest {
@Test
public void testStyleUrl() {
- assertEquals(Style.DARK, new MapboxMapOptions().styleUrl(Style.DARK).getStyle());
- assertNotEquals(Style.LIGHT, new MapboxMapOptions().styleUrl(Style.DARK).getStyle());
- assertNull(new MapboxMapOptions().getStyle());
+ assertEquals(Style.DARK, new MapboxMapOptions().styleUrl(Style.DARK).getStyleUrl());
+ assertNotEquals(Style.LIGHT, new MapboxMapOptions().styleUrl(Style.DARK).getStyleUrl());
+ assertNull(new MapboxMapOptions().getStyleUrl());
}
@Test
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.java
index 15da018b0e..3a62e39173 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.java
@@ -2,10 +2,14 @@ package com.mapbox.mapboxsdk.testapp.activity.textureview;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import android.view.ViewGroup;
import android.widget.ImageView;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
@@ -30,23 +34,30 @@ public class TextureViewTransparentBackgroundActivity extends AppCompatActivity
}
private void setupBackground() {
- ImageView imageView = (ImageView) findViewById(R.id.imageView);
+ ImageView imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.water);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
private void setupMapView(Bundle savedInstanceState) {
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(map -> {
- mapboxMap = map;
-
- try {
- map.setStyleJson(ResourceUtils.readRawResource(getApplicationContext(), R.raw.no_bg_style));
- } catch (IOException exception) {
- Timber.e(exception);
- }
- });
+ try {
+ MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
+ mapboxMapOptions.styleJson(ResourceUtils.readRawResource(this, R.raw.no_bg_style));
+ mapboxMapOptions.translucentTextureSurface(true);
+ mapboxMapOptions.textureMode(true);
+ mapboxMapOptions.camera(new CameraPosition.Builder()
+ .zoom(2)
+ .target(new LatLng(48.507879, 8.363795))
+ .build()
+ );
+
+ mapView = new MapView(this, mapboxMapOptions);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(map -> mapboxMap = map);
+ ((ViewGroup) findViewById(R.id.coordinator_layout)).addView(mapView);
+ } catch (IOException exception) {
+ Timber.e(exception);
+ }
}
@Override
@@ -90,5 +101,4 @@ public class TextureViewTransparentBackgroundActivity extends AppCompatActivity
super.onLowMemory();
mapView.onLowMemory();
}
-
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_transparent.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_transparent.xml
index 1d99e61d74..096d44e223 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_transparent.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_textureview_transparent.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -13,15 +12,5 @@
android:layout_height="match_parent"
android:contentDescription="@null"/>
- <com.mapbox.mapboxsdk.maps.MapView
- android:id="@+id/mapView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:mapbox_cameraTargetLat="48.507879"
- app:mapbox_cameraTargetLng="8.363795"
- app:mapbox_cameraZoom="2"
- app:mapbox_renderTextureMode="true"
- app:mapbox_renderTextureTranslucentSurface="true"/>
-
</android.support.design.widget.CoordinatorLayout>