[android] #4516 - cleanup snapshot PR
This commit is contained in:
@@ -1469,11 +1469,22 @@ public class MapboxMap {
|
||||
mMapView.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a snapshot of the map.
|
||||
*
|
||||
* @param callback Callback method invoked when the snapshot is taken.
|
||||
* @param bitmap A pre-allocated bitmap.
|
||||
*/
|
||||
@UiThread
|
||||
public void snapshot(@NonNull SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
|
||||
mMapView.snapshot(callback, bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a snapshot of the map.
|
||||
*
|
||||
* @param callback Callback method invoked when the snapshot is taken.
|
||||
*/
|
||||
@UiThread
|
||||
public void snapshot(@NonNull SnapshotReadyCallback callback) {
|
||||
mMapView.snapshot(callback, null);
|
||||
@@ -1700,7 +1711,13 @@ public class MapboxMap {
|
||||
void onFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the snapshot has been taken.
|
||||
*/
|
||||
public interface SnapshotReadyCallback {
|
||||
/**
|
||||
* Invoked when the snapshot has been taken.
|
||||
**/
|
||||
void onSnapshotReady(Bitmap snapshot);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,16 @@ package com.mapbox.mapboxsdk.testapp.activity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
@@ -25,12 +21,10 @@ import com.mapbox.mapboxsdk.testapp.utils.ApiAccess;
|
||||
|
||||
public class SnapshotActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "SnapshotActivity";
|
||||
|
||||
private MapView mMapView;
|
||||
private MapView mapView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_snapshot);
|
||||
|
||||
@@ -43,21 +37,15 @@ public class SnapshotActivity extends AppCompatActivity {
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.cameraMapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.getMapAsync(new OnMapReadyCallback() {
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
|
||||
// set a style
|
||||
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
|
||||
@Override
|
||||
public void onCameraChange(CameraPosition position) {
|
||||
Log.v(MapboxConstants.TAG, position.toString());
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.makeSnapshotButton).setOnClickListener(new View.OnClickListener() {
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(SnapshotActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final long startTime = System.nanoTime();
|
||||
@@ -66,7 +54,7 @@ public class SnapshotActivity extends AppCompatActivity {
|
||||
public void onSnapshotReady(Bitmap snapshot) {
|
||||
long endTime = System.nanoTime();
|
||||
long duration = (long) ((endTime - startTime) / 1e6);
|
||||
ImageView snapshotView = (ImageView) findViewById(R.id.snapshotImageView);
|
||||
ImageView snapshotView = (ImageView) findViewById(R.id.imageView);
|
||||
snapshotView.setImageBitmap(snapshot);
|
||||
Toast.makeText(SnapshotActivity.this, String.format("Snapshot taken in %d ms", duration), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@@ -80,31 +68,31 @@ public class SnapshotActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M3,4L3,1h2v3h3v2L5,6v3L3,9L3,6L0,6L0,4h3zM6,10L6,7h3L9,4h7l1.83,2L21,6c1.1,0 2,0.9 2,2v12c0,1.1 -0.9,2 -2,2L5,22c-1.1,0 -2,-0.9 -2,-2L3,10h3zM13,19c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5 -5,2.24 -5,5 2.24,5 5,5zM9.8,14c0,1.77 1.43,3.2 3.2,3.2s3.2,-1.43 3.2,-3.2 -1.43,-3.2 -3.2,-3.2 -3.2,1.43 -3.2,3.2z"/>
|
||||
</vector>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
@@ -11,32 +12,37 @@
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/toolbar"
|
||||
android:orientation="vertical" >
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/cameraMapView"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
<ImageView
|
||||
android:id="@+id/snapshotImageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
android:layout_weight="1"
|
||||
android:background="@color/primary" />
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:style_url="@string/style_emerald" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_make_snapshot"
|
||||
android:id="@+id/makeSnapshotButton"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:background="@color/white"/>
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_add_a_photo_black_24dp"
|
||||
app:backgroundTint="@android:color/white" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="mapView" type="id"/>
|
||||
<item name="mapView" type="id" />
|
||||
<item name="fab" type="id" />
|
||||
<item name="imageView" type="id" />
|
||||
<item name="item_click_support" type="id" />
|
||||
</resources>
|
||||
Reference in New Issue
Block a user