summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java24
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java16
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java14
3 files changed, 48 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
index 90bb23429f..3e75a34b4a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.attribution;
+import android.content.Context;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.URLSpan;
+import com.mapbox.mapboxsdk.R;
+import java.lang.ref.WeakReference;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -17,6 +20,7 @@ import java.util.Set;
*/
public class AttributionParser {
+ private final WeakReference<Context> context;
private final Set<Attribution> attributions = new LinkedHashSet<>();
private final String attributionData;
private final boolean withImproveMap;
@@ -24,8 +28,9 @@ public class AttributionParser {
private final boolean withTelemetryAttribution;
private final boolean withMapboxAttribution;
- AttributionParser(String attributionData, boolean withImproveMap, boolean withCopyrightSign,
- boolean withTelemetryAttribution, boolean withMapboxAttribution) {
+ AttributionParser(WeakReference<Context> context, String attributionData, boolean withImproveMap,
+ boolean withCopyrightSign, boolean withTelemetryAttribution, boolean withMapboxAttribution) {
+ this.context = context;
this.attributionData = attributionData;
this.withImproveMap = withImproveMap;
this.withCopyrightSign = withCopyrightSign;
@@ -167,7 +172,13 @@ public class AttributionParser {
*/
private void addAdditionalAttributions() {
if (withTelemetryAttribution) {
- attributions.add(new Attribution(Attribution.TELEMETRY, Attribution.TELEMETRY_URL));
+ Context context = this.context.get();
+ attributions.add(
+ new Attribution(
+ context != null ? context.getString(R.string.mapbox_telemetrySettings) : Attribution.TELEMETRY,
+ Attribution.TELEMETRY_URL
+ )
+ );
}
}
@@ -196,6 +207,7 @@ public class AttributionParser {
* </p>
*/
public static class Options {
+ private WeakReference<Context> context;
private boolean withImproveMap = true;
private boolean withCopyrightSign = true;
private boolean withTelemetryAttribution = false;
@@ -227,6 +239,11 @@ public class AttributionParser {
return this;
}
+ public Options withContext(Context context) {
+ this.context = new WeakReference<>(context);
+ return this;
+ }
+
public AttributionParser build() {
if (attributionDataStringArray == null) {
throw new IllegalStateException("Using builder without providing attribution data");
@@ -234,6 +251,7 @@ public class AttributionParser {
String fullAttributionString = parseAttribution(attributionDataStringArray);
AttributionParser attributionParser = new AttributionParser(
+ context,
fullAttributionString,
withImproveMap,
withCopyrightSign,
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
index 546ee62804..c2114f458e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
@@ -17,10 +17,12 @@ import com.mapbox.mapboxsdk.attribution.AttributionParser;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.style.sources.Source;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
+import java.util.Locale;
/**
* Responsible for managing attribution interactions on the map.
@@ -47,7 +49,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
// Called when someone presses the attribution icon on the map
@Override
public void onClick(View view) {
- attributionSet = new AttributionBuilder(mapboxMap).build();
+ attributionSet = new AttributionBuilder(mapboxMap, view.getContext()).build();
boolean isActivityFinishing = false;
if (context instanceof Activity) {
@@ -148,12 +150,19 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
private static class AttributionBuilder {
private final MapboxMap mapboxMap;
+ private final WeakReference<Context> context;
- AttributionBuilder(MapboxMap mapboxMap) {
+ AttributionBuilder(MapboxMap mapboxMap, Context context) {
this.mapboxMap = mapboxMap;
+ this.context = new WeakReference<>(context);
}
private Set<Attribution> build() {
+ Context context = this.context.get();
+ if (context == null) {
+ return Collections.emptySet();
+ }
+
List<String> attributions = new ArrayList<>();
for (Source source : mapboxMap.getSources()) {
attributions.add(source.getAttribution());
@@ -162,6 +171,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
return new AttributionParser.Options()
.withCopyrightSign(true)
.withImproveMap(true)
+ .withContext(context)
.withTelemetryAttribution(true)
.withAttributionData(attributions.toArray(new String[attributions.size()]))
.build().getAttributions();
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
index f25cf1b7d8..7eacda43c3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
@@ -4,6 +4,7 @@ import com.mapbox.mapboxsdk.BuildConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.Set;
@@ -21,6 +22,7 @@ public class AttributionParseTest {
public void testParseAttributionStringSatellite() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(SATELLITE_ATTRIBUTION)
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -54,6 +56,7 @@ public class AttributionParseTest {
public void testParseAttributionStringStreets() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(STREETS_ATTRIBUTION)
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -84,6 +87,7 @@ public class AttributionParseTest {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(STREETS_ATTRIBUTION)
.withMapboxAttribution(false)
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
@@ -109,6 +113,7 @@ public class AttributionParseTest {
public void testParseAttributionArrayString() throws Exception {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
@@ -142,6 +147,7 @@ public class AttributionParseTest {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(SATELLITE_ATTRIBUTION)
.withImproveMap(false)
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 3, attributionList.size());
@@ -171,6 +177,7 @@ public class AttributionParseTest {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
.withCopyrightSign(false)
+ .withContext(RuntimeEnvironment.application)
.build();
Set<Attribution> attributionList = attributionParser.getAttributions();
assertEquals("Size of list should match", 4, attributionList.size());
@@ -205,6 +212,7 @@ public class AttributionParseTest {
.withAttributionData(STREETS_ATTRIBUTION)
.withCopyrightSign(false)
.withImproveMap(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -220,6 +228,7 @@ public class AttributionParseTest {
AttributionParser attributionParser = new AttributionParser.Options()
.withAttributionData(STREETS_ATTRIBUTION)
.withImproveMap(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -236,6 +245,7 @@ public class AttributionParseTest {
.withCopyrightSign(false)
.withImproveMap(false)
.withMapboxAttribution(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -251,6 +261,7 @@ public class AttributionParseTest {
.withAttributionData(STREETS_ATTRIBUTION)
.withImproveMap(false)
.withMapboxAttribution(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -267,6 +278,7 @@ public class AttributionParseTest {
.withImproveMap(false)
.withCopyrightSign(false)
.withMapboxAttribution(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -283,6 +295,7 @@ public class AttributionParseTest {
.withImproveMap(false)
.withCopyrightSign(false)
.withMapboxAttribution(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(
@@ -298,6 +311,7 @@ public class AttributionParseTest {
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
.withImproveMap(false)
.withCopyrightSign(false)
+ .withContext(RuntimeEnvironment.application)
.build();
assertEquals(