summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2017-11-08 14:15:20 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2017-11-13 18:57:55 +0100
commit8d17cad9a95a4519197af91e74270a8462e5f385 (patch)
tree13a1cc47df044daa42a4f157c79eb606c2cf3d73
parent2f58155cfd486c140c3081ade21ff47664870f37 (diff)
downloadqtlocation-mapboxgl-8d17cad9a95a4519197af91e74270a8462e5f385.tar.gz
[android] - refactor Attribution, add tests
-rw-r--r--platform/android/MapboxGLAndroidSDK/build.gradle1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/Attribution.java44
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java149
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Attribution.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java77
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java8
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AttributionUtils.java41
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java201
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/utils/AttributionDataTest.java23
9 files changed, 433 insertions, 131 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index d9d6c2f3fc..ce886b1001 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -129,7 +129,6 @@ android {
testOptions {
unitTests{
returnDefaultValues = true
- includeAndroidResources = true
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/Attribution.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/Attribution.java
new file mode 100644
index 0000000000..5bfee26bc1
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/Attribution.java
@@ -0,0 +1,44 @@
+package com.mapbox.mapboxsdk.attribution;
+
+public class Attribution {
+
+ private String title;
+ private String url;
+
+ Attribution(String title, String url) {
+ this.title = title;
+ this.url = url;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Attribution that = (Attribution) o;
+
+ if (title != null ? !title.equals(that.title) : that.title != null) {
+ return false;
+ }
+ return url != null ? url.equals(that.url) : that.url == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = title != null ? title.hashCode() : 0;
+ result = 31 * result + (url != null ? url.hashCode() : 0);
+ return result;
+ }
+}
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
new file mode 100644
index 0000000000..97f2dee053
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/attribution/AttributionParser.java
@@ -0,0 +1,149 @@
+package com.mapbox.mapboxsdk.attribution;
+
+import android.text.Html;
+import android.text.SpannableStringBuilder;
+import android.text.style.URLSpan;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class AttributionParser {
+
+ private final Set<Attribution> attributions = new LinkedHashSet<>();
+
+ private String attributionDataString;
+ private boolean withImproveMap;
+ private boolean withCopyrightSign;
+ private boolean withTelemetryAttribution;
+ private boolean withMapboxAttribution;
+
+ AttributionParser(String attributionDataString, boolean withImproveMap, boolean withCopyrightSign,
+ boolean withTelemetryAttribution, boolean withMapboxAttribution) {
+ this.attributionDataString = attributionDataString;
+ this.withImproveMap = withImproveMap;
+ this.withCopyrightSign = withCopyrightSign;
+ this.withTelemetryAttribution = withTelemetryAttribution;
+ this.withMapboxAttribution = withMapboxAttribution;
+ }
+
+ public Set<Attribution> getAttributions() {
+ return attributions;
+ }
+
+ void parse() {
+ parseAttributions();
+ addAdditionalAttributions();
+ }
+
+ private void parseAttributions() {
+ SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionDataString);
+ URLSpan[] urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class);
+ for (URLSpan urlSpan : urlSpans) {
+ parseUrlSpan(htmlBuilder, urlSpan);
+ }
+ }
+
+ private void parseUrlSpan(SpannableStringBuilder htmlBuilder, URLSpan urlSpan) {
+ String url = urlSpan.getURL();
+ if (isUrlSpanValid(url)) {
+ String title = parseAnchorValue(htmlBuilder, urlSpan);
+ attributions.add(new Attribution(title, url));
+ }
+ }
+
+ private boolean isUrlSpanValid(String url) {
+ return isValidForImproveThisMap(url) && isValidForMapbox(url);
+ }
+
+ private boolean isValidForImproveThisMap(String url) {
+ return withImproveMap || !url.equals("https://www.mapbox.com/map-feedback/");
+ }
+
+ private boolean isValidForMapbox(String url) {
+ return withMapboxAttribution || !url.equals("https://www.mapbox.com/about/maps/");
+ }
+
+ private String parseAnchorValue(SpannableStringBuilder htmlBuilder, URLSpan urlSpan) {
+ int start = htmlBuilder.getSpanStart(urlSpan);
+ int end = htmlBuilder.getSpanEnd(urlSpan);
+ int length = end - start;
+ char[] charKey = new char[length];
+ htmlBuilder.getChars(start, end, charKey, 0);
+ return stripCopyright(String.valueOf(charKey));
+ }
+
+ private String stripCopyright(String anchor) {
+ if (!withCopyrightSign && anchor.startsWith("© ")) {
+ anchor = anchor.substring(2, anchor.length());
+ }
+ return anchor;
+ }
+
+ private void addAdditionalAttributions() {
+ if (withTelemetryAttribution) {
+ String telemetryKey = "Telemetry Settings";
+ String telemetryLink = "https://www.mapbox.com/telemetry/";
+ attributions.add(new Attribution(telemetryKey, telemetryLink));
+ }
+ }
+
+ public static class Options {
+ private boolean withImproveMap = true;
+ private boolean withCopyrightSign = true;
+ private boolean withTelemetryAttribution = false;
+ private boolean withMapboxAttribution = true;
+ private String[] attributionDataStringArray;
+
+ public Options withAttributionData(String... attributionData) {
+ this.attributionDataStringArray = attributionData;
+ return this;
+ }
+
+ public Options withImproveMap(boolean withImproveMap) {
+ this.withImproveMap = withImproveMap;
+ return this;
+ }
+
+ public Options withCopyrightSign(boolean withCopyrightSign) {
+ this.withCopyrightSign = withCopyrightSign;
+ return this;
+ }
+
+ public Options withTelemetryAttribution(boolean withTelemetryAttribution) {
+ this.withTelemetryAttribution = withTelemetryAttribution;
+ return this;
+ }
+
+ public Options withMapboxAttribution(boolean withMapboxAttribution) {
+ this.withMapboxAttribution = withMapboxAttribution;
+ return this;
+ }
+
+ public AttributionParser build() {
+ if (attributionDataStringArray == null) {
+ throw new IllegalStateException("Using builder without providing attribution data");
+ }
+
+ String fullAttributionString = parseAttribution(attributionDataStringArray);
+ AttributionParser attributionParser = new AttributionParser(
+ fullAttributionString,
+ withImproveMap,
+ withCopyrightSign,
+ withTelemetryAttribution,
+ withMapboxAttribution
+ );
+ attributionParser.parse();
+ return attributionParser;
+ }
+
+ private String parseAttribution(String[] attribution) {
+ StringBuilder builder = new StringBuilder();
+ for (String attr : attribution) {
+ if (!attr.isEmpty()) {
+ builder.append(attr);
+ }
+ }
+ return builder.toString();
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Attribution.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Attribution.java
deleted file mode 100644
index 801bede00c..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Attribution.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.mapbox.mapboxsdk.maps;
-
-public class Attribution {
-
- private String title;
- private String url;
-
- public Attribution(String title, String url) {
- this.title = title;
- this.url = url;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getUrl() {
- return url;
- }
-}
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 9ccff387f5..2956d864e6 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
@@ -7,22 +7,20 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
-import android.text.Html;
-import android.text.SpannableStringBuilder;
-import android.text.TextUtils;
-import android.text.style.URLSpan;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;
-
import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.attribution.Attribution;
+import com.mapbox.mapboxsdk.attribution.AttributionParser;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
+import java.util.Set;
/**
* Responsible for managing attribution interactions on the map.
@@ -39,8 +37,8 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
private final Context context;
private final MapboxMap mapboxMap;
- private String[] attributionKeys;
- private HashMap<String, String> attributionMap;
+ private String[] attributionTitles;
+ private Set<Attribution> attributionSet;
AttributionDialogManager(@NonNull Context context, @NonNull MapboxMap mapboxMap) {
this.context = context;
@@ -50,18 +48,26 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
// Called when someone presses the attribution icon on the map
@Override
public void onClick(View view) {
- attributionMap = new AttributionBuilder(context, mapboxMap).build();
+ attributionSet = new AttributionBuilder(mapboxMap).build();
showAttributionDialog();
}
private void showAttributionDialog() {
- attributionKeys = attributionMap.keySet().toArray(new String[attributionMap.size()]);
+ attributionTitles = getAttributionTitles();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
- builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionKeys), this);
+ builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionTitles), this);
builder.show();
}
+ private String[] getAttributionTitles() {
+ List<String> titles = new ArrayList<>();
+ for (Attribution attribution : attributionSet) {
+ titles.add(attribution.getTitle());
+ }
+ return titles.toArray(new String[titles.size()]);
+ }
+
// Called when someone selects an attribution or telemetry settings from the dialog
@Override
public void onClick(DialogInterface dialog, int which) {
@@ -73,7 +79,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
}
private boolean isLatestEntry(int attributionKeyIndex) {
- return attributionKeyIndex == attributionKeys.length - 1;
+ return attributionKeyIndex == attributionTitles.length - 1;
}
private void showTelemetryDialog() {
@@ -105,7 +111,8 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
}
private void showMapFeedbackWebPage(int which) {
- String url = attributionMap.get(attributionKeys[which]);
+ Attribution[] attributions = attributionSet.toArray(new Attribution[attributionSet.size()]);
+ String url = attributions[which].getUrl();
if (url.contains(MAP_FEEDBACK_URL)) {
url = buildMapFeedbackMapUrl(mapboxMap.getCameraPosition());
}
@@ -132,46 +139,24 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
private static class AttributionBuilder {
- private final HashMap<String, String> map = new LinkedHashMap<>();
- private final Context context;
private final MapboxMap mapboxMap;
- AttributionBuilder(Context context, MapboxMap mapboxMap) {
- this.context = context.getApplicationContext();
+ AttributionBuilder(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
}
- private HashMap<String, String> build() {
+ private Set<Attribution> build() {
+ List<String> attributions = new ArrayList<>();
for (Source source : mapboxMap.getSources()) {
- parseAttribution(source.getAttribution());
- }
- addTelemetryEntryToAttributionMap();
- return map;
- }
-
- private void parseAttribution(String attributionSource) {
- if (!TextUtils.isEmpty(attributionSource)) {
- SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attributionSource);
- URLSpan[] urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class);
- for (URLSpan urlSpan : urlSpans) {
- map.put(resolveAnchorValue(htmlBuilder, urlSpan), urlSpan.getURL());
- }
+ attributions.add(source.getAttribution());
}
- }
-
- private String resolveAnchorValue(SpannableStringBuilder htmlBuilder, URLSpan urlSpan) {
- int start = htmlBuilder.getSpanStart(urlSpan);
- int end = htmlBuilder.getSpanEnd(urlSpan);
- int length = end - start;
- char[] charKey = new char[length];
- htmlBuilder.getChars(start, end, charKey, 0);
- return String.valueOf(charKey);
- }
- private void addTelemetryEntryToAttributionMap() {
- String telemetryKey = context.getString(R.string.mapbox_telemetrySettings);
- String telemetryLink = context.getString(R.string.mapbox_telemetryLink);
- map.put(telemetryKey, telemetryLink);
+ return new AttributionParser.Options()
+ .withCopyrightSign(true)
+ .withImproveMap(true)
+ .withTelemetryAttribution(true)
+ .withAttributionData(attributions.toArray(new String[attributions.size()]))
+ .build().getAttributions();
}
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 2e13130c13..f7353f500f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -17,10 +17,13 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.attribution.Attribution;
+import com.mapbox.mapboxsdk.attribution.AttributionParser;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.storage.FileSource;
+import timber.log.Timber;
import java.util.ArrayList;
import java.util.List;
@@ -312,6 +315,11 @@ public class MapSnapshotter {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int margin = (int) displayMetrics.density * LOGO_MARGIN_DP;
Bitmap original = mapSnapshot.getBitmap();
+
+ for (String s : mapSnapshot.getAttributions()) {
+ Timber.e(s);
+ }
+
TextView textView = new TextView(context);
textView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AttributionUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AttributionUtils.java
deleted file mode 100644
index 71fb89af82..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AttributionUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.mapbox.mapboxsdk.utils;
-
-import android.text.Html;
-import android.text.SpannableStringBuilder;
-import android.text.style.URLSpan;
-import com.mapbox.mapboxsdk.maps.Attribution;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class AttributionUtils {
-
- public static List<Attribution> parseAttribution(String[] attribution) {
- StringBuilder builder = new StringBuilder();
- for (String attr : attribution) {
- if (!attr.isEmpty()) {
- builder.append(attr);
- }
- }
- return parseAttribution(builder.toString());
- }
-
- public static List<Attribution> parseAttribution(String attribution) {
- List<Attribution> attributions = new ArrayList<>();
- SpannableStringBuilder htmlBuilder = (SpannableStringBuilder) Html.fromHtml(attribution);
- URLSpan[] urlSpans = htmlBuilder.getSpans(0, htmlBuilder.length(), URLSpan.class);
- for (URLSpan urlSpan : urlSpans) {
- attributions.add(new Attribution(resolveAnchorValue(htmlBuilder, urlSpan), urlSpan.getURL()));
- }
- return attributions;
- }
-
- private static String resolveAnchorValue(SpannableStringBuilder htmlBuilder, URLSpan urlSpan) {
- int start = htmlBuilder.getSpanStart(urlSpan);
- int end = htmlBuilder.getSpanEnd(urlSpan);
- int length = end - start;
- char[] charKey = new char[length];
- htmlBuilder.getChars(start, end, charKey, 0);
- return String.valueOf(charKey);
- }
-}
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
new file mode 100644
index 0000000000..4e68361e18
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/attribution/AttributionParseTest.java
@@ -0,0 +1,201 @@
+package com.mapbox.mapboxsdk.attribution;
+
+import com.mapbox.mapboxsdk.BuildConfig;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+import java.util.Set;
+
+import static junit.framework.Assert.assertEquals;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(constants = BuildConfig.class)
+public class AttributionParseTest {
+
+ private static final String STREETS_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a>\n";
+ private static final String SATELLITE_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">&copy; DigitalGlobe</a>\n";
+
+ @Test
+ public void testParseAttributionStringSatellite() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(SATELLITE_ATTRIBUTION)
+ .build();
+
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 4, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
+ assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
+ break;
+ case 2:
+ assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
+ assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ break;
+ case 3:
+ assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
+ assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+
+ @Test
+ public void testParseAttributionStringStreets() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(STREETS_ATTRIBUTION)
+ .build();
+
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 3, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
+ assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
+ break;
+ case 2:
+ assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
+ assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+
+ @Test
+ public void testParseAttributionWithoutMapbox() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(STREETS_ATTRIBUTION)
+ .withMapboxAttribution(false)
+ .build();
+
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 2, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
+ assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+
+ @Test
+ public void testParseAttributionArrayString() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
+ .build();
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 4, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
+ assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
+ break;
+ case 2:
+ assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
+ assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ break;
+ case 3:
+ assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
+ assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+
+ @Test
+ public void testHideImproveThisMapAttributionArrayString() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(SATELLITE_ATTRIBUTION)
+ .withImproveMap(false)
+ .build();
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 3, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
+ assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
+ break;
+ case 2:
+ assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
+ assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+
+ @Test
+ public void testParseHideCopyrightAttributionArrayString() throws Exception {
+ AttributionParser attributionParser = new AttributionParser.Options()
+ .withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
+ .withCopyrightSign(false)
+ .build();
+ Set<Attribution> attributionList = attributionParser.getAttributions();
+ assertEquals("Size of list should match", 4, attributionList.size());
+
+ int counter = 0;
+ for (Attribution attribution : attributionList) {
+ switch (counter) {
+ case 0:
+ assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
+ assertEquals("Title mapbox should match", "Mapbox", attribution.getTitle());
+ break;
+ case 1:
+ assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
+ assertEquals("Title openstreetmap should match", "OpenStreetMap", attribution.getTitle());
+ break;
+ case 2:
+ assertEquals("URL improve map should match", "https://www.mapbox.com/map-feedback/", attribution.getUrl());
+ assertEquals("Title improve map should match", "Improve this map", attribution.getTitle());
+ break;
+ case 3:
+ assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
+ assertEquals("Title digital globe should match", "DigitalGlobe", attribution.getTitle());
+ break;
+ }
+ counter++;
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/utils/AttributionDataTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/utils/AttributionDataTest.java
deleted file mode 100644
index a37086e11a..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/utils/AttributionDataTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.mapbox.mapboxsdk.utils;
-
-import com.mapbox.mapboxsdk.maps.Attribution;
-import org.junit.Test;
-
-import java.util.List;
-
-import static junit.framework.Assert.assertEquals;
-
-public class AttributionDataTest {
-
- private final static String SINGLE_ATTRIBUTION = "<a href=\"https://www.digitalglobe.com/\" target=\"_blank\">&copy; DigitalGlobe</a>";
-
-
- @Test
- public void testParseAttributionString() throws Exception {
- List<Attribution> attributionList = AttributionUtils.parseAttribution(SINGLE_ATTRIBUTION);
- assertEquals("Size of list should match", 1, attributionList.size());
- Attribution attribution = attributionList.get(0);
- assertEquals("URL should match", "https://www.digitalglobe.com/", attribution.getUrl());
- assertEquals("Title should match", "&copy; DigitalGlobe", attribution.getTitle());
- }
-}