From 53c3c327f0ebea276d977f58a59cdb9449165518 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 17 Aug 2018 13:43:07 -0700 Subject: [android] Upgrade to latest jni.hpp --- platform/android/src/style/sources/source.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'platform/android/src/style/sources/source.cpp') diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp index d2e2426c0b..c7968786ec 100644 --- a/platform/android/src/style/sources/source.cpp +++ b/platform/android/src/style/sources/source.cpp @@ -76,6 +76,7 @@ namespace android { if (ownedSource.get() == nullptr && javaPeer.get() != nullptr) { // Manually clear the java peer android::UniqueEnv env = android::AttachEnv(); + static auto javaClass = jni::Class::Singleton(*env); static auto nativePtrField = javaClass.GetField(*env, "nativePtr"); javaPeer->Set(*env, nativePtrField, (jlong) 0); javaPeer.reset(); @@ -140,16 +141,14 @@ namespace android { rendererFrontend = nullptr; } - jni::Class Source::javaClass; - void Source::registerNative(jni::JNIEnv& env) { // Lookup the class - Source::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); + static auto javaClass = jni::Class::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer - jni::RegisterNativePeer(env, Source::javaClass, "nativePtr", + jni::RegisterNativePeer(env, javaClass, "nativePtr", METHOD(&Source::getId, "nativeGetId"), METHOD(&Source::getAttribution, "nativeGetAttribution") ); -- cgit v1.2.1 From 79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 22 Aug 2018 12:27:43 -0700 Subject: [android] jni.hpp 4.0.0 --- platform/android/src/style/sources/source.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'platform/android/src/style/sources/source.cpp') diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp index c7968786ec..e13f55aff1 100644 --- a/platform/android/src/style/sources/source.cpp +++ b/platform/android/src/style/sources/source.cpp @@ -1,5 +1,6 @@ #include "source.hpp" #include "../android_conversion.hpp" +#include "../../attach_env.hpp" #include @@ -47,16 +48,16 @@ namespace android { } } - jni::Object Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) { + const jni::Object& Source::peerForCoreSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) { if (!coreSource.peer.has_value()) { coreSource.peer = createSourcePeer(env, coreSource, frontend); } - return *coreSource.peer.get>()->javaPeer; + return coreSource.peer.get>()->javaPeer; } - Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, jni::Object obj, AndroidRendererFrontend& frontend) + Source::Source(jni::JNIEnv& env, mbgl::style::Source& coreSource, const jni::Object& obj, AndroidRendererFrontend& frontend) : source(coreSource) - , javaPeer(obj.NewGlobalRef(env)) + , javaPeer(jni::NewGlobal(env, obj)) , rendererFrontend(&frontend) { } @@ -76,23 +77,23 @@ namespace android { if (ownedSource.get() == nullptr && javaPeer.get() != nullptr) { // Manually clear the java peer android::UniqueEnv env = android::AttachEnv(); - static auto javaClass = jni::Class::Singleton(*env); + static auto& javaClass = jni::Class::Singleton(*env); static auto nativePtrField = javaClass.GetField(*env, "nativePtr"); - javaPeer->Set(*env, nativePtrField, (jlong) 0); + javaPeer.Set(*env, nativePtrField, (jlong) 0); javaPeer.reset(); } } - jni::String Source::getId(jni::JNIEnv& env) { + jni::Local Source::getId(jni::JNIEnv& env) { return jni::Make(env, source.getID()); } - jni::String Source::getAttribution(jni::JNIEnv& env) { + jni::Local Source::getAttribution(jni::JNIEnv& env) { auto attribution = source.getAttribution(); return attribution ? jni::Make(env, attribution.value()) : jni::Make(env,""); } - void Source::addToMap(JNIEnv& env, jni::Object obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { + void Source::addToMap(JNIEnv& env, const jni::Object& obj, mbgl::Map& map, AndroidRendererFrontend& frontend) { // Check to see if we own the source first if (!ownedSource) { throw std::runtime_error("Cannot add source twice"); @@ -105,12 +106,12 @@ namespace android { source.peer = std::unique_ptr(this); // Add strong reference to java source - javaPeer = obj.NewGlobalRef(env); + javaPeer = jni::NewGlobal(env, obj); rendererFrontend = &frontend; } - bool Source::removeFromMap(JNIEnv&, jni::Object, mbgl::Map& map) { + bool Source::removeFromMap(JNIEnv&, const jni::Object&, mbgl::Map& map) { // Cannot remove if not attached yet if (ownedSource) { throw std::runtime_error("Cannot remove detached source"); @@ -143,7 +144,7 @@ namespace android { void Source::registerNative(jni::JNIEnv& env) { // Lookup the class - static auto javaClass = jni::Class::Singleton(env); + static auto& javaClass = jni::Class::Singleton(env); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) -- cgit v1.2.1