[android] map snapshotter - add mutators

This commit is contained in:
Ivo van Dongen
2017-10-02 17:22:56 +03:00
committed by Fabian Guerra Soto
parent 31873725d7
commit fd3587608b
9 changed files with 210 additions and 4 deletions

View File

@@ -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"

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>