[android] map snapshotter - wrap snapshot in native peer for access to the pointFor functionality
This commit is contained in:
committed by
Ivo van Dongen
parent
87b735aaf7
commit
dde1a92291
@@ -387,6 +387,16 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity android:name=".activity.snapshot.MapSnapshotterMarkerActivity"
|
||||
android:description="@string/description_map_snapshotter_marker"
|
||||
android:label="@string/activity_map_snapshotter_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DoubleMapActivity"
|
||||
android:description="@string/description_doublemap"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.ViewTreeObserver;
|
||||
@@ -11,7 +10,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
@@ -96,12 +95,12 @@ public class MapSnapshotterActivity extends AppCompatActivity {
|
||||
|
||||
MapSnapshotter snapshotter = new MapSnapshotter(MapSnapshotterActivity.this, options);
|
||||
|
||||
snapshotter.start(new MapboxMap.SnapshotReadyCallback() {
|
||||
snapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
|
||||
@Override
|
||||
public void onSnapshotReady(Bitmap snapshot) {
|
||||
public void onSnapshotReady(MapSnapshot snapshot) {
|
||||
Timber.i("Got the snapshot");
|
||||
ImageView imageView = new ImageView(MapSnapshotterActivity.this);
|
||||
imageView.setImageBitmap(snapshot);
|
||||
imageView.setImageBitmap(snapshot.getBitmap());
|
||||
grid.addView(
|
||||
imageView,
|
||||
new GridLayout.LayoutParams(GridLayout.spec(row), GridLayout.spec(column))
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Test activity showing how to use a the {@link MapSnapshotter} and overlay
|
||||
* {@link android.graphics.Bitmap}s on top.
|
||||
*/
|
||||
public class MapSnapshotterMarkerActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_snapshotter_marker);
|
||||
|
||||
final View container = findViewById(R.id.container);
|
||||
container.getViewTreeObserver()
|
||||
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
//noinspection deprecation
|
||||
container.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
|
||||
Timber.i("Starting snapshot");
|
||||
|
||||
MapSnapshotter mapSnapshotter = new MapSnapshotter(
|
||||
getApplicationContext(),
|
||||
new MapSnapshotter
|
||||
.Options(Math.min(container.getMeasuredWidth(), 1024), Math.min(container.getMeasuredHeight(), 1024))
|
||||
.withStyle(Style.TRAFFIC_DAY)
|
||||
.withCameraPosition(new CameraPosition.Builder().target(new LatLng(52.090737, 5.121420)).zoom(15).build())
|
||||
);
|
||||
mapSnapshotter.start(MapSnapshotterMarkerActivity.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSnapshotReady(MapSnapshot snapshot) {
|
||||
Timber.i("Snapshot ready");
|
||||
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
|
||||
Bitmap image = addMarker(snapshot);
|
||||
imageView.setImageBitmap(image);
|
||||
}
|
||||
|
||||
private Bitmap addMarker(MapSnapshot snapshot) {
|
||||
Canvas canvas = new Canvas(snapshot.getBitmap());
|
||||
Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default, null);
|
||||
// Dom toren
|
||||
PointF markerLocation = snapshot.pixelForLatLng(new LatLng(52.090649433011315, 5.121310651302338));
|
||||
canvas.drawBitmap(marker,
|
||||
markerLocation.x,
|
||||
/* Subtract height (in dp) so the bottom of the marker aligns correctly */
|
||||
markerLocation.y - (marker.getHeight() / getResources().getDisplayMetrics().density),
|
||||
null
|
||||
);
|
||||
return snapshot.getBitmap();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.snapshot;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
@@ -10,7 +9,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot;
|
||||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
@@ -19,7 +18,7 @@ import java.util.Random;
|
||||
/**
|
||||
* Test activity showing how to use a the {@link MapSnapshotter}
|
||||
*/
|
||||
public class MapSnapshotterReuseActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback {
|
||||
public class MapSnapshotterReuseActivity extends AppCompatActivity implements MapSnapshotter.SnapshotReadyCallback {
|
||||
|
||||
private MapSnapshotter mapSnapshotter;
|
||||
private View fab;
|
||||
@@ -61,10 +60,10 @@ public class MapSnapshotterReuseActivity extends AppCompatActivity implements Ma
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSnapshotReady(Bitmap snapshot) {
|
||||
public void onSnapshotReady(MapSnapshot snapshot) {
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
|
||||
imageView.setImageBitmap(snapshot);
|
||||
imageView.setImageBitmap(snapshot.getBitmap());
|
||||
}
|
||||
|
||||
private LatLngBounds getRandomBounds() {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/snapshot_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:contentDescription=""/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -61,6 +61,7 @@
|
||||
<string name="description_bottom_sheet">Show 2 MapView on screen with a bottom sheet</string>
|
||||
<string name="description_map_snapshotter">Show a static bitmap taken with the MapSnapshotter</string>
|
||||
<string name="description_map_snapshotter_reuse">Show how to reuse a MapSnapshotter instance</string>
|
||||
<string name="description_map_snapshotter_marker">Show how to add a marker to a Snapshot</string>
|
||||
<string name="description_camera_animator">Use Android SDK Animators to animate camera position changes</string>
|
||||
<string name="description_symbol_generator">Use Android SDK Views as symbols</string>
|
||||
</resources>
|
||||
@@ -61,6 +61,7 @@
|
||||
<string name="activity_bottom_sheet">Bottom sheet</string>
|
||||
<string name="activity_map_snapshotter">Map Snapshotter</string>
|
||||
<string name="activity_map_snapshotter_reuse">Map Snapshotter Reuse</string>
|
||||
<string name="activity_map_snapshotter_marker">Map Snapshot with marker</string>
|
||||
<string name="activity_camera_animator">Animator animation</string>
|
||||
<string name="activity_symbol_generator">SymbolGenerator</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user