[android] Upgrade to latest jni.hpp
This commit is contained in:
@@ -7,15 +7,14 @@ namespace android {
|
||||
namespace gson {
|
||||
|
||||
jni::Object<JsonArray> JsonArray::New(jni::JNIEnv& env, const std::vector<mapbox::geometry::value>& values){
|
||||
static auto constructor = JsonArray::javaClass.GetConstructor(env);
|
||||
static auto addMethod = JsonArray::javaClass.GetMethod<void (jni::Object<JsonElement>)>(env, "add");
|
||||
static auto javaClass = jni::Class<JsonArray>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor(env);
|
||||
static auto addMethod = javaClass.GetMethod<void (jni::Object<JsonElement>)>(env, "add");
|
||||
|
||||
auto jsonArray = JsonArray::javaClass.New(env, constructor);
|
||||
auto jsonArray = javaClass.New(env, constructor);
|
||||
|
||||
for (const auto &v : values) {
|
||||
auto jsonElement = JsonElement::New(env, v);
|
||||
jsonArray.Call(env, addMethod, jsonElement);
|
||||
jni::DeleteLocalRef(env, jsonElement);
|
||||
jsonArray.Call(env, addMethod, *jni::SeizeLocal(env, JsonElement::New(env, v)));
|
||||
}
|
||||
|
||||
return jsonArray;
|
||||
@@ -25,18 +24,18 @@ std::vector<mapbox::geometry::value> JsonArray::convert(jni::JNIEnv& env, const
|
||||
std::vector<mapbox::geometry::value> values;
|
||||
|
||||
if (jsonArray) {
|
||||
static auto getMethod = JsonArray::javaClass.GetMethod<jni::Object<JsonElement> (jni::jint)>(env, "get");
|
||||
static auto sizeMethod = JsonArray::javaClass.GetMethod<jni::jint ()>(env, "size");
|
||||
static auto javaClass = jni::Class<JsonArray>::Singleton(env);
|
||||
static auto getMethod = javaClass.GetMethod<jni::Object<JsonElement> (jni::jint)>(env, "get");
|
||||
static auto sizeMethod = javaClass.GetMethod<jni::jint ()>(env, "size");
|
||||
|
||||
int size = jsonArray.Call(env, sizeMethod);
|
||||
values.reserve(uint(size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
auto entry = jsonArray.Call(env, getMethod, i);
|
||||
if (entry) {
|
||||
values.push_back(JsonElement::convert(env, entry));
|
||||
auto entry = jni::SeizeLocal(env, jsonArray.Call(env, getMethod, i));
|
||||
if (*entry) {
|
||||
values.push_back(JsonElement::convert(env, *entry));
|
||||
}
|
||||
jni::DeleteLocalRef(env, entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +43,9 @@ std::vector<mapbox::geometry::value> JsonArray::convert(jni::JNIEnv& env, const
|
||||
}
|
||||
|
||||
void JsonArray::registerNative(jni::JNIEnv& env) {
|
||||
// Lookup the class
|
||||
javaClass = *jni::Class<JsonArray>::Find(env).NewGlobalRef(env).release();
|
||||
jni::Class<JsonArray>::Singleton(env);
|
||||
}
|
||||
|
||||
jni::Class<JsonArray> JsonArray::javaClass;
|
||||
|
||||
} // namespace gson
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user