summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java110
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_reuse.xml24
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml1
5 files changed, 146 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index bf97749b9e..d6237bc161 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -377,6 +377,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
+ <activity android:name=".activity.snapshot.MapSnapshotterReuseActivity"
+ android:description="@string/description_map_snapshotter_reuse"
+ android:label="@string/activity_map_snapshotter_reuse">
+ <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"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
new file mode 100644
index 0000000000..ac51bd9d5f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
@@ -0,0 +1,110 @@
+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;
+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.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter;
+import com.mapbox.mapboxsdk.testapp.R;
+
+import java.util.Random;
+
+/**
+ * Test activity showing how to use a the {@link MapSnapshotter}
+ */
+public class MapSnapshotterReuseActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback {
+
+ private MapSnapshotter mapSnapshotter;
+ private View fab;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_map_snapshotter_reuse);
+
+ fab = findViewById(R.id.fab);
+ fab.setVisibility(View.INVISIBLE);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ fab.setVisibility(View.INVISIBLE);
+
+ mapSnapshotter.setStyleUrl(getRandomStyle());
+ if (random.nextInt(2) == 0) {
+ mapSnapshotter.setCameraPosition(getRandomCameraPosition());
+ } else {
+ mapSnapshotter.setRegion(getRandomBounds());
+ }
+ if (random.nextInt(2) == 0) {
+ mapSnapshotter.setSize(512, 512);
+ } else {
+ mapSnapshotter.setSize(256, 256);
+ }
+ mapSnapshotter.start(MapSnapshotterReuseActivity.this);
+ }
+ });
+
+ mapSnapshotter = new MapSnapshotter(
+ getApplicationContext(),
+ new MapSnapshotter.Options(512, 512)
+ );
+
+ mapSnapshotter.start(MapSnapshotterReuseActivity.this);
+ }
+
+ @Override
+ public void onSnapshotReady(Bitmap snapshot) {
+ fab.setVisibility(View.VISIBLE);
+ ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
+ imageView.setImageBitmap(snapshot);
+ }
+
+ private LatLngBounds getRandomBounds() {
+ return LatLngBounds.from(
+ randomInRange(-5, 5),
+ randomInRange(-5, 5),
+ randomInRange(5, 10),
+ randomInRange(5, 10)
+ );
+ }
+
+ private CameraPosition getRandomCameraPosition() {
+ return new CameraPosition.Builder()
+ .target(new LatLng(randomInRange(-80, 80), randomInRange(-160, 160)))
+ .zoom(randomInRange(2, 10))
+ .bearing(randomInRange(0, 90))
+ .build();
+ }
+
+ public String getRandomStyle() {
+ switch (random.nextInt(5)) {
+ case 0:
+ return Style.DARK;
+ case 1:
+ return Style.LIGHT;
+ case 2:
+ return Style.MAPBOX_STREETS;
+ case 3:
+ return Style.OUTDOORS;
+ case 4:
+ return Style.SATELLITE_STREETS;
+ default:
+ return Style.TRAFFIC_DAY;
+ }
+ }
+
+ private static Random random = new Random();
+
+ public static float randomInRange(float min, float max) {
+ return (random.nextFloat() * (max - min)) + min;
+ }
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_reuse.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_reuse.xml
new file mode 100644
index 0000000000..5ce25a69d0
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_snapshotter_reuse.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ 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=""/>
+
+ <android.support.design.widget.FloatingActionButton
+ android:id="@+id/fab"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentRight="true"
+ android:layout_gravity="end|bottom"
+ android:layout_margin="@dimen/fab_margin"
+ android:src="@drawable/ic_animate_coordinates"/>
+
+</RelativeLayout>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 4d1f7eac38..94dc669781 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -60,6 +60,7 @@
<string name="description_animated_image_source">Shows how to animate georeferenced images</string>
<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_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> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 8f394d0eb4..4942bcab36 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -60,6 +60,7 @@
<string name="activity_animated_image_source">Animated Image Source</string>
<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_camera_animator">Animator animation</string>
<string name="activity_symbol_generator">SymbolGenerator</string>
</resources> \ No newline at end of file