Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - make snapshot logo optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Oct 27, 2017
1 parent 4a89384 commit 8836d16
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ public class MapSnapshot {
private long nativePtr = 0;
private Bitmap bitmap;
private String[] attributions;
private boolean showLogo;

/**
* Created from native side
*/
private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions) {
private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions, boolean showLogo) {
this.nativePtr = nativePtr;
this.bitmap = bitmap;
this.attributions = attributions;
this.showLogo = showLogo;
}

/**
Expand All @@ -47,6 +49,13 @@ protected String[] getAttributions() {
return attributions;
}

/**
* @return Flag indicating to show the Mapbox logo.
*/
boolean isShowLogo() {
return showLogo;
}

// Unused, needed for peer binding
private native void initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static class Options {
private String styleUrl = Style.MAPBOX_STREETS;
private LatLngBounds region;
private CameraPosition cameraPosition;
private boolean showLogo = true;

/**
* @param width the width of the image
Expand Down Expand Up @@ -123,6 +124,15 @@ public Options withCameraPosition(CameraPosition cameraPosition) {
return this;
}

/**
* @param showLogo The flag indicating to show the Mapbox logo.
* @return the mutated {@link Options}
*/
public Options withLogo(boolean showLogo) {
this.showLogo = showLogo;
return this;
}

/**
* @return the width of the image
*/
Expand Down Expand Up @@ -182,7 +192,7 @@ public MapSnapshotter(@NonNull Context context, @NonNull Options options) {

nativeInitialize(this, fileSource, options.pixelRatio, options.width,
options.height, options.styleUrl, options.region, options.cameraPosition,
programCacheDir);
options.showLogo, programCacheDir);
}

/**
Expand Down Expand Up @@ -266,7 +276,9 @@ protected void addOverlay(Bitmap original) {
*/
protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
addOverlay(snapshot.getBitmap());
if (snapshot.isShowLogo()) {
addOverlay(snapshot.getBitmap());
}
callback.onSnapshotReady(snapshot);
reset();
}
Expand Down Expand Up @@ -294,7 +306,7 @@ protected native void nativeInitialize(MapSnapshotter mapSnapshotter,
FileSource fileSource, float pixelRatio,
int width, int height, String styleUrl,
LatLngBounds region, CameraPosition position,
String programCacheDir);
boolean showLogo, String programCacheDir);

protected native void nativeStart();

Expand Down
5 changes: 3 additions & 2 deletions platform/android/src/snapshotter/map_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
PremultipliedImage&& image,
float pixelRatio,
std::vector<std::string> attributions,
bool showLogo,
mbgl::MapSnapshotter::PointForFn pointForFn) {
// Create the bitmap
auto bitmap = Bitmap::CreateBitmap(env, std::move(image));

// Create the Mapsnapshot peers
static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>>(env);
static auto constructor = javaClass.GetConstructor<jni::jlong, jni::Object<Bitmap>, jni::Array<jni::String>, jni::jboolean>(env);
auto nativePeer = std::make_unique<MapSnapshot>(pixelRatio, pointForFn);
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions));
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, jni::Make<jni::Array<jni::String>>(env, attributions), (jni::jboolean) showLogo);
}

jni::Class<MapSnapshot> MapSnapshot::javaClass;
Expand Down
1 change: 1 addition & 0 deletions platform/android/src/snapshotter/map_snapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MapSnapshot {
PremultipliedImage&& image,
float pixelRatio,
std::vector<std::string> attributions,
bool showLogo,
PointForFn pointForFn);

MapSnapshot(jni::JNIEnv&) {};
Expand Down
7 changes: 5 additions & 2 deletions platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
jni::String styleURL,
jni::Object<LatLngBounds> region,
jni::Object<CameraPosition> position,
jni::jboolean _showLogo,
jni::String _programCacheDir)
: javaPeer(SeizeGenericWeakRef(_env, jni::Object<MapSnapshotter>(jni::NewWeakGlobalRef(_env, _obj.Get()).release())))
, pixelRatio(_pixelRatio)
Expand All @@ -41,6 +42,8 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
bounds = LatLngBounds::getLatLngBounds(_env, region);
}

showLogo = _showLogo;

// Create the core snapshotter
snapshotter = std::make_unique<mbgl::MapSnapshotter>(fileSource,
*threadPool,
Expand Down Expand Up @@ -70,7 +73,7 @@ void MapSnapshotter::start(JNIEnv&) {
javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
} else {
// Create the wrapper
auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, pointForFn);
auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn);

// invoke callback
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
Expand Down Expand Up @@ -117,7 +120,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {

// Register the peer
jni::RegisterNativePeer<MapSnapshotter>(env, MapSnapshotter::javaClass, "nativePtr",
std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::String>,
std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::jboolean, jni::String>,
"nativeInitialize",
"finalize",
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
Expand Down
2 changes: 2 additions & 0 deletions platform/android/src/snapshotter/map_snapshotter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MapSnapshotter {
jni::String styleURL,
jni::Object<LatLngBounds> region,
jni::Object<CameraPosition> position,
jni::jboolean showLogo,
jni::String programCacheDir);

~MapSnapshotter();
Expand All @@ -59,6 +60,7 @@ class MapSnapshotter {
GenericUniqueWeakObject<MapSnapshotter> javaPeer;

float pixelRatio;
bool showLogo;

std::shared_ptr<mbgl::ThreadPool> threadPool;
std::unique_ptr<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback;
Expand Down

0 comments on commit 8836d16

Please sign in to comment.