summaryrefslogtreecommitdiff
path: root/platform/android/src/style/layers/custom_layer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/style/layers/custom_layer.cpp')
-rw-r--r--platform/android/src/style/layers/custom_layer.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/platform/android/src/style/layers/custom_layer.cpp b/platform/android/src/style/layers/custom_layer.cpp
index 61e74a9cf5..f6f3bb249c 100644
--- a/platform/android/src/style/layers/custom_layer.cpp
+++ b/platform/android/src/style/layers/custom_layer.cpp
@@ -7,7 +7,7 @@
namespace mbgl {
namespace android {
- CustomLayer::CustomLayer(jni::JNIEnv& env, jni::String layerId, jni::jlong host)
+ CustomLayer::CustomLayer(jni::JNIEnv& env, const jni::String& layerId, jni::jlong host)
: Layer(env, std::make_unique<mbgl::style::CustomLayer>(
jni::Make<std::string>(env, layerId),
std::unique_ptr<mbgl::style::CustomLayerHost>(reinterpret_cast<mbgl::style::CustomLayerHost*>(host)))
@@ -33,23 +33,22 @@ namespace android {
}
}
- jni::Class<CustomLayer> CustomLayer::javaClass;
-
- jni::jobject* CustomLayer::createJavaPeer(jni::JNIEnv& env) {
- static auto constructor = CustomLayer::javaClass.template GetConstructor<jni::jlong>(env);
- return CustomLayer::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
+ jni::Local<jni::Object<Layer>> CustomLayer::createJavaPeer(jni::JNIEnv& env) {
+ static auto& javaClass = jni::Class<CustomLayer>::Singleton(env);
+ static auto constructor = javaClass.GetConstructor<jni::jlong>(env);
+ return javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this));
}
void CustomLayer::registerNative(jni::JNIEnv& env) {
// Lookup the class
- CustomLayer::javaClass = *jni::Class<CustomLayer>::Find(env).NewGlobalRef(env).release();
+ static auto& javaClass = jni::Class<CustomLayer>::Singleton(env);
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
// Register the peer
jni::RegisterNativePeer<CustomLayer>(
- env, CustomLayer::javaClass, "nativePtr",
- std::make_unique<CustomLayer, JNIEnv&, jni::String, jni::jlong>,
+ env, javaClass, "nativePtr",
+ jni::MakePeer<CustomLayer, const jni::String&, jni::jlong>,
"initialize",
"finalize",
METHOD(&CustomLayer::update, "nativeUpdate"));