diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp')
4 files changed, 84 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index fb1d0ef8a2..b78fba0aae 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -345,6 +345,17 @@ android:value=".activity.FeatureOverviewActivity" /> </activity> <activity + android:name=".activity.snapshot.MapSnapshotterLocalStyleActivity" + android:description="@string/description_map_snapshotter_local_style" + android:label="@string/activity_map_snapshotter_local_style"> + <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" android:label="@string/activity_double_map"> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java new file mode 100644 index 0000000000..32c340b2ce --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterLocalStyleActivity.java @@ -0,0 +1,71 @@ +package com.mapbox.mapboxsdk.testapp.activity.snapshot; + +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.geometry.LatLng; +import com.mapbox.mapboxsdk.snapshotter.MapSnapshot; +import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils; +import timber.log.Timber; + +import java.io.IOException; + +/** + * Test activity showing how to use a the MapSnapshotter with a local style + */ +public class MapSnapshotterLocalStyleActivity extends AppCompatActivity + implements MapSnapshotter.SnapshotReadyCallback { + + private MapSnapshotter mapSnapshotter; + + @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); + + String styleJson; + try { + styleJson = ResourceUtils.readRawResource(MapSnapshotterLocalStyleActivity.this, R.raw.sat_style); + } catch (IOException exception) { + throw new RuntimeException(exception); + } + + Timber.i("Starting snapshot"); + mapSnapshotter = new MapSnapshotter( + getApplicationContext(), + new MapSnapshotter + .Options(Math.min(container.getMeasuredWidth(), 1024), Math.min(container.getMeasuredHeight(), 1024)) + .withStyleJson(styleJson) + .withCameraPosition(new CameraPosition.Builder().target(new LatLng(52.090737, 5.121420)).zoom(18).build()) + ); + mapSnapshotter.start(MapSnapshotterLocalStyleActivity.this, error -> Timber.e(error)); + } + }); + } + + @Override + protected void onStop() { + super.onStop(); + mapSnapshotter.cancel(); + } + + @Override + public void onSnapshotReady(MapSnapshot snapshot) { + Timber.i("Snapshot ready"); + ImageView imageView = (ImageView) findViewById(R.id.snapshot_image); + imageView.setImageBitmap(snapshot.getBitmap()); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index 17d6ad57c6..b515a4d3ae 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -57,6 +57,7 @@ <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_map_snapshotter_local_style">Show how to load a local style with 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> <string name="description_textureview_debug">Use TextureView to render the map</string> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 3f011bd3ed..114ff38a0e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -57,6 +57,7 @@ <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_map_snapshotter_local_style">Map Snapshot with local style</string> <string name="activity_camera_animator">Animator animation</string> <string name="activity_symbol_generator">SymbolGenerator</string> <string name="activity_textureview_debug">TextureView debug</string> |