[android] jni.hpp 4.0.0
This commit is contained in:
@@ -16,18 +16,18 @@ MapSnapshot::MapSnapshot(float pixelRatio_, MapSnapshot::PointForFn pointForFn_,
|
||||
|
||||
MapSnapshot::~MapSnapshot() = default;
|
||||
|
||||
jni::Object<PointF> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng> jLatLng) {
|
||||
jni::Local<jni::Object<PointF>> MapSnapshot::pixelForLatLng(jni::JNIEnv& env, jni::Object<LatLng>& jLatLng) {
|
||||
ScreenCoordinate point = pointForFn(LatLng::getLatLng(env, jLatLng));
|
||||
return PointF::New(env, point.x * pixelRatio, point.y * pixelRatio);
|
||||
}
|
||||
|
||||
jni::Object<LatLng> MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::Object<PointF>jPoint) {
|
||||
jni::Local<jni::Object<LatLng>> MapSnapshot::latLngForPixel(jni::JNIEnv& env, jni::Object<PointF>& jPoint) {
|
||||
return LatLng::New(env, latLngForFn(PointF::getScreenCoordinate(env, jPoint)));
|
||||
}
|
||||
|
||||
// Static methods //
|
||||
|
||||
jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
|
||||
jni::Local<jni::Object<MapSnapshot>> MapSnapshot::New(JNIEnv& env,
|
||||
PremultipliedImage&& image,
|
||||
float pixelRatio,
|
||||
std::vector<std::string> attributions,
|
||||
@@ -38,7 +38,7 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
|
||||
auto bitmap = Bitmap::CreateBitmap(env, std::move(image));
|
||||
|
||||
// Create the Mapsnapshot peers
|
||||
static auto javaClass = jni::Class<MapSnapshot>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<MapSnapshot>::Singleton(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, latLngForFn);
|
||||
return javaClass.New(env, constructor, reinterpret_cast<jlong>(nativePeer.release()), bitmap, conversion::toArray(env, attributions), (jni::jboolean) showLogo);
|
||||
@@ -46,7 +46,7 @@ jni::Object<MapSnapshot> MapSnapshot::New(JNIEnv& env,
|
||||
|
||||
void MapSnapshot::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<MapSnapshot>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<MapSnapshot>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
static jni::Object<MapSnapshot> New(JNIEnv& env,
|
||||
static jni::Local<jni::Object<MapSnapshot>> New(JNIEnv& env,
|
||||
PremultipliedImage&& image,
|
||||
float pixelRatio,
|
||||
std::vector<std::string> attributions,
|
||||
@@ -35,8 +35,8 @@ public:
|
||||
MapSnapshot(float pixelRatio, PointForFn, LatLngForFn);
|
||||
~MapSnapshot();
|
||||
|
||||
jni::Object<PointF> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>);
|
||||
jni::Object<LatLng> latLngForPixel(jni::JNIEnv&, jni::Object<PointF>);
|
||||
jni::Local<jni::Object<PointF>> pixelForLatLng(jni::JNIEnv&, jni::Object<LatLng>&);
|
||||
jni::Local<jni::Object<LatLng>> latLngForPixel(jni::JNIEnv&, jni::Object<PointF>&);
|
||||
|
||||
private:
|
||||
float pixelRatio;
|
||||
|
||||
@@ -14,18 +14,18 @@ namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
|
||||
jni::Object<MapSnapshotter> _obj,
|
||||
jni::Object<FileSource> _jFileSource,
|
||||
const jni::Object<MapSnapshotter>& _obj,
|
||||
const jni::Object<FileSource>& _jFileSource,
|
||||
jni::jfloat _pixelRatio,
|
||||
jni::jint width,
|
||||
jni::jint height,
|
||||
jni::String styleURL,
|
||||
jni::String styleJSON,
|
||||
jni::Object<LatLngBounds> region,
|
||||
jni::Object<CameraPosition> position,
|
||||
const jni::String& styleURL,
|
||||
const jni::String& styleJSON,
|
||||
const jni::Object<LatLngBounds>& region,
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean _showLogo,
|
||||
jni::String _programCacheDir)
|
||||
: javaPeer(SeizeGenericWeak(_obj.NewWeakGlobalRef(_env).release()))
|
||||
const jni::String& _programCacheDir)
|
||||
: javaPeer(_env, _obj)
|
||||
, pixelRatio(_pixelRatio)
|
||||
, threadPool(sharedThreadPool()) {
|
||||
|
||||
@@ -80,20 +80,19 @@ void MapSnapshotter::start(JNIEnv& env) {
|
||||
[this](std::exception_ptr err, PremultipliedImage image, std::vector<std::string> attributions, mbgl::MapSnapshotter::PointForFn pointForFn, mbgl::MapSnapshotter::LatLngForFn latLngForFn) {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
static auto javaClass = jni::Class<MapSnapshotter>::Singleton(*_env);
|
||||
static auto& javaClass = jni::Class<MapSnapshotter>::Singleton(*_env);
|
||||
|
||||
if (err) {
|
||||
// error handler callback
|
||||
static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed");
|
||||
javaPeer->Call(*_env, onSnapshotFailed,
|
||||
*jni::SeizeLocal(*_env, jni::Make<jni::String>(*_env, util::toString(err))));
|
||||
javaPeer.get(*_env).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, showLogo, pointForFn, latLngForFn);
|
||||
|
||||
// invoke callback
|
||||
static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady");
|
||||
javaPeer->Call(*_env, onSnapshotReady, mapSnapshot);
|
||||
javaPeer.get(*_env).Call(*_env, onSnapshotReady, mapSnapshot);
|
||||
}
|
||||
|
||||
deactivateFilesource(*_env);
|
||||
@@ -108,11 +107,11 @@ void MapSnapshotter::cancel(JNIEnv& env) {
|
||||
deactivateFilesource(env);
|
||||
}
|
||||
|
||||
void MapSnapshotter::setStyleUrl(JNIEnv& env, jni::String styleURL) {
|
||||
void MapSnapshotter::setStyleUrl(JNIEnv& env, const jni::String& styleURL) {
|
||||
snapshotter->setStyleURL(jni::Make<std::string>(env, styleURL));
|
||||
}
|
||||
|
||||
void MapSnapshotter::setStyleJson(JNIEnv& env, jni::String styleJSON) {
|
||||
void MapSnapshotter::setStyleJson(JNIEnv& env, const jni::String& styleJSON) {
|
||||
snapshotter->setStyleJSON(jni::Make<std::string>(env, styleJSON));
|
||||
}
|
||||
|
||||
@@ -121,12 +120,12 @@ void MapSnapshotter::setSize(JNIEnv&, jni::jint width, jni::jint height) {
|
||||
snapshotter->setSize(size);
|
||||
}
|
||||
|
||||
void MapSnapshotter::setCameraPosition(JNIEnv& env, jni::Object<CameraPosition> position) {
|
||||
void MapSnapshotter::setCameraPosition(JNIEnv& env, const jni::Object<CameraPosition>& position) {
|
||||
auto options = CameraPosition::getCameraOptions(env, position);
|
||||
snapshotter->setCameraOptions(options);
|
||||
}
|
||||
|
||||
void MapSnapshotter::setRegion(JNIEnv& env, jni::Object<LatLngBounds> region) {
|
||||
void MapSnapshotter::setRegion(JNIEnv& env, const jni::Object<LatLngBounds>& region) {
|
||||
snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region));
|
||||
}
|
||||
|
||||
@@ -151,13 +150,13 @@ void MapSnapshotter::deactivateFilesource(JNIEnv& env) {
|
||||
|
||||
void MapSnapshotter::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
static auto javaClass = jni::Class<MapSnapshotter>::Singleton(env);
|
||||
static auto& javaClass = jni::Class<MapSnapshotter>::Singleton(env);
|
||||
|
||||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
|
||||
|
||||
// Register the peer
|
||||
jni::RegisterNativePeer<MapSnapshotter>(env, javaClass, "nativePtr",
|
||||
std::make_unique<MapSnapshotter, JNIEnv&, jni::Object<MapSnapshotter>, jni::Object<FileSource>, jni::jfloat, jni::jint, jni::jint, jni::String, jni::String, jni::Object<LatLngBounds>, jni::Object<CameraPosition>, jni::jboolean, jni::String>,
|
||||
jni::MakePeer<MapSnapshotter, const jni::Object<MapSnapshotter>&, const jni::Object<FileSource>&, jni::jfloat, jni::jint, jni::jint, const jni::String&, const jni::String&, const jni::Object<LatLngBounds>&, const jni::Object<CameraPosition>&, jni::jboolean, const jni::String&>,
|
||||
"nativeInitialize",
|
||||
"finalize",
|
||||
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "../map/camera_position.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
#include "../jni/generic_global_ref_deleter.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -26,29 +25,29 @@ public:
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
MapSnapshotter(jni::JNIEnv&,
|
||||
jni::Object<MapSnapshotter>,
|
||||
jni::Object<FileSource>,
|
||||
const jni::Object<MapSnapshotter>&,
|
||||
const jni::Object<FileSource>&,
|
||||
jni::jfloat pixelRatio,
|
||||
jni::jint width,
|
||||
jni::jint height,
|
||||
jni::String styleURL,
|
||||
jni::String styleJSON,
|
||||
jni::Object<LatLngBounds> region,
|
||||
jni::Object<CameraPosition> position,
|
||||
const jni::String& styleURL,
|
||||
const jni::String& styleJSON,
|
||||
const jni::Object<LatLngBounds>& region,
|
||||
const jni::Object<CameraPosition>& position,
|
||||
jni::jboolean showLogo,
|
||||
jni::String programCacheDir);
|
||||
const jni::String& programCacheDir);
|
||||
|
||||
~MapSnapshotter();
|
||||
|
||||
void setStyleUrl(JNIEnv&, jni::String styleURL);
|
||||
void setStyleUrl(JNIEnv&, const jni::String& styleURL);
|
||||
|
||||
void setStyleJson(JNIEnv&, jni::String styleJSON);
|
||||
void setStyleJson(JNIEnv&, const jni::String& styleJSON);
|
||||
|
||||
void setSize(JNIEnv&, jni::jint width, jni::jint height);
|
||||
|
||||
void setCameraPosition(JNIEnv&, jni::Object<CameraPosition> position);
|
||||
void setCameraPosition(JNIEnv&, const jni::Object<CameraPosition>& position);
|
||||
|
||||
void setRegion(JNIEnv&, jni::Object<LatLngBounds> region);
|
||||
void setRegion(JNIEnv&, const jni::Object<LatLngBounds>& region);
|
||||
|
||||
void start(JNIEnv&);
|
||||
|
||||
@@ -58,7 +57,7 @@ private:
|
||||
MBGL_STORE_THREAD(tid);
|
||||
|
||||
JavaVM *vm = nullptr;
|
||||
GenericWeak<jni::Object<MapSnapshotter>> javaPeer;
|
||||
jni::WeakReference<jni::Object<MapSnapshotter>, jni::EnvAttachingDeleter> javaPeer;
|
||||
|
||||
float pixelRatio;
|
||||
bool showLogo;
|
||||
|
||||
Reference in New Issue
Block a user