summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2017-10-30 14:10:26 -0700
committerTobrun <tobrun.van.nuland@gmail.com>2017-10-31 15:52:39 -0700
commitf5a0523ab55f1368ec2b4bab21711c29718cc19a (patch)
treeb517cf0e3d361e249e3e6ce61e405bcf6e810b7d
parent56c2af5670852312f788f83ff86d80447c30b0fd (diff)
downloadqtlocation-mapboxgl-f5a0523ab55f1368ec2b4bab21711c29718cc19a.tar.gz
[android] - add attribution integrationupstream/tvn-snapshot-attr
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java48
2 files changed, 45 insertions, 4 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
index 6f63c2eba8..cc887a800d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
@@ -99,6 +99,7 @@ final class Transform implements MapView.OnMapChangedListener {
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
if (callback != null) {
+ this.cameraPosition = cameraPosition;
callback.onFinish();
}
cameraChangeDispatcher.onCameraIdle();
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 37d05fc328..29771cf8ab 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
@@ -7,6 +7,10 @@ import android.graphics.Canvas;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
+import android.text.Html;
+import android.text.Spanned;
+import android.view.View;
+import android.widget.TextView;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
@@ -14,6 +18,10 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.storage.FileSource;
+import java.util.List;
+
+import timber.log.Timber;
+
/**
* The map snapshotter creates a bitmap of the map, rendered
* off the UI thread. The snapshotter itself must be used on
@@ -251,11 +259,43 @@ public class MapSnapshotter {
nativeCancel();
}
- protected void addOverlay(Bitmap original) {
- float margin = context.getResources().getDisplayMetrics().density * LOGO_MARGIN_PX;
+ protected void addOverlay(MapSnapshot mapSnapshot) {
+ Bitmap original = mapSnapshot.getBitmap();
Canvas canvas = new Canvas(original);
+ addLogo(canvas, original.getHeight());
+ addAttribution(canvas, mapSnapshot);
+ }
+
+ private void addLogo(Canvas canvas, float snapshotHeight) {
+ float margin = context.getResources().getDisplayMetrics().density * LOGO_MARGIN_PX;
Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, null);
- canvas.drawBitmap(logo, margin, original.getHeight() - (logo.getHeight() + margin), null);
+ canvas.drawBitmap(logo, margin, snapshotHeight - (logo.getHeight() + margin), null);
+ }
+
+ private void addAttribution(Canvas canvas, MapSnapshot mapSnapshot) {
+ Bitmap original = mapSnapshot.getBitmap();
+ TextView textView = new TextView(context);
+ textView.setTextSize(14);
+ for (String attr : mapSnapshot.getAttributions()) {
+ Timber.e(attr);
+ textView.setText(fromHtml(attr));
+ int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(original.getWidth(), View.MeasureSpec.AT_MOST);
+ int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
+ textView.measure(widthMeasureSpec, heightMeasureSpec);
+ textView.layout(0, 0, original.getWidth(), original.getHeight());
+ textView.draw(canvas);
+ return;
+ }
+ }
+
+ public static Spanned fromHtml(String html) {
+ Spanned result;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
+ } else {
+ result = Html.fromHtml(html);
+ }
+ return result;
}
/**
@@ -266,7 +306,7 @@ public class MapSnapshotter {
*/
protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
- addOverlay(snapshot.getBitmap());
+ addOverlay(snapshot);
callback.onSnapshotReady(snapshot);
reset();
}