This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new category, and created SnapshotListActivity, based on MapSnapshotterActivity in the TestApp * Added comments * Fixed crashes by removing added null, setting currentCategory and adding break * Added activity to manifest and added access token * Added SnapshotNotificationActivity which shows a notification with an image when the map is clicked on * Added text view to bottom to replace toast to alert user of how to use demo * Added PendingIntent so that clicking on notification re-opens app * Refactored names and changed list to grid to more accurately describe contents * Added screenshot image urls * Reverted changes to wrong layout file and created new layout file for SnapshotNotificationActivity * Re-added newline that I accidentally removed * Cleaned up code and removed array of snapshotters and instead replaced with one * Added more comments to SnapshotGridActivity * Changed indentation * Added new lines to ends of files and removed unnecessary line * checkstyle indentation * checkstyle line length * checkstyle var name * Added description box to offline maps so that users know that Snapshotter exists * Updated banner copy * Revert "Added description box to offline maps so that users know that Snapshotter exists" This reverts commit c08615b. * Added banner to top of list in layout for Downloading a static map * Added on click listener to banner for static maps to link to Snapshotter demos * consistency for end of sentence periodos * comment added to new public constant * edit comment for accuracy * initial setup * cleanup * checkstyle * removed snapshot grid stuff * refactored ig name to snapshot * added boolean check to block crash * tweaked intent settings
- Loading branch information
Langston Smith
authored
Dec 8, 2017
1 parent
16bc2b2
commit 7dda338
Showing
17 changed files
with
328 additions
and
98 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ples/ig/SnapshotNotificationActivity.java → ...napshot/SnapshotNotificationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
...o/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotShareActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package com.mapbox.mapboxandroiddemo.examples.snapshot; | ||
|
||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
import com.mapbox.mapboxsdk.geometry.LatLngBounds; | ||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshot; | ||
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
public class SnapshotShareActivity extends AppCompatActivity { | ||
private MapView mapView; | ||
private MapSnapshotter mapSnapshotter; | ||
private MapboxMap mapboxMap; | ||
private FloatingActionButton cameraFab; | ||
private boolean hasStartedSnapshotGeneration; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Mapbox access token is configured here. This needs to be called either in your application | ||
// object or in the same activity which contains the mapview. | ||
Mapbox.getInstance(this, getString(R.string.access_token)); | ||
|
||
// This contains the MapView in XML and needs to be called after the access token is configured. | ||
setContentView(R.layout.activity_snapshot_share); | ||
|
||
cameraFab = findViewById(R.id.camera_share_snapshot_image_fab); | ||
cameraFab.setImageResource(R.drawable.ic_camera); | ||
|
||
hasStartedSnapshotGeneration = false; | ||
|
||
mapView = findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
|
||
// Set a callback for when MapboxMap is ready to be used | ||
mapView.getMapAsync(new OnMapReadyCallback() { | ||
@Override | ||
public void onMapReady(final MapboxMap mapboxMap) { | ||
|
||
SnapshotShareActivity.this.mapboxMap = mapboxMap; | ||
|
||
// When user clicks the map, start the snapshotting process with the given parameters | ||
cameraFab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
|
||
if (!hasStartedSnapshotGeneration) { | ||
hasStartedSnapshotGeneration = true; | ||
Toast.makeText(SnapshotShareActivity.this, R.string.loading_snapshot_image, Toast.LENGTH_LONG).show(); | ||
startSnapShot( | ||
mapboxMap.getProjection().getVisibleRegion().latLngBounds, | ||
mapView.getMeasuredHeight(), | ||
mapView.getMeasuredWidth()); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Creates bitmap from given parameters, and creates a notification with that bitmap | ||
* | ||
* @param latLngBounds of map | ||
* @param height of map | ||
* @param width of map | ||
*/ | ||
private void startSnapShot(LatLngBounds latLngBounds, int height, int width) { | ||
if (mapSnapshotter == null) { | ||
// Initialize snapshotter with map dimensions and given bounds | ||
MapSnapshotter.Options options = | ||
new MapSnapshotter.Options(width, height).withRegion(latLngBounds).withStyle(mapboxMap.getStyleUrl()); | ||
|
||
mapSnapshotter = new MapSnapshotter(SnapshotShareActivity.this, options); | ||
} else { | ||
// Reuse pre-existing MapSnapshotter instance | ||
mapSnapshotter.setSize(width, height); | ||
mapSnapshotter.setRegion(latLngBounds); | ||
mapSnapshotter.setRegion(latLngBounds); | ||
} | ||
|
||
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() { | ||
@Override | ||
public void onSnapshotReady(MapSnapshot snapshot) { | ||
|
||
Bitmap bitmapOfMapSnapshotImage = snapshot.getBitmap(); | ||
|
||
Uri bmpUri = getLocalBitmapUri(bitmapOfMapSnapshotImage); | ||
|
||
Intent shareIntent = new Intent(); | ||
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); | ||
shareIntent.setType("image/png"); | ||
shareIntent.setAction(Intent.ACTION_SEND); | ||
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||
startActivity(Intent.createChooser(shareIntent, "Share map image")); | ||
|
||
hasStartedSnapshotGeneration = false; | ||
} | ||
}); | ||
} | ||
|
||
private Uri getLocalBitmapUri(Bitmap bmp) { | ||
Uri bmpUri = null; | ||
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), | ||
"share_image_" + System.currentTimeMillis() + ".png"); | ||
FileOutputStream out = null; | ||
try { | ||
out = new FileOutputStream(file); | ||
bmp.compress(Bitmap.CompressFormat.PNG, 90, out); | ||
try { | ||
out.close(); | ||
} catch (IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
bmpUri = Uri.fromFile(file); | ||
} catch (FileNotFoundException exception) { | ||
exception.printStackTrace(); | ||
} | ||
return bmpUri; | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
// Make sure to stop the snapshotter on pause if it exists | ||
if (mapSnapshotter != null) { | ||
mapSnapshotter.cancel(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
MapboxAndroidDemo/src/main/res/layout/activity_snapshot_share.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:fab="http://schemas.android.com/apk/res-auto" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
mapbox:mapbox_cameraTargetLat="37.536172" | ||
mapbox:mapbox_cameraTargetLng="126.916954" | ||
mapbox:mapbox_cameraTilt="60" | ||
mapbox:mapbox_cameraZoom="9" | ||
mapbox:mapbox_styleUrl="@string/mapbox_style_satellite_streets" /> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/camera_share_snapshot_image_fab" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="end|bottom" | ||
android:layout_margin="16dp" | ||
fab:fab_size="normal" /> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters