diff options
Diffstat (limited to 'platform/android/src/style/conversion/function.hpp')
-rw-r--r-- | platform/android/src/style/conversion/function.hpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/platform/android/src/style/conversion/function.hpp b/platform/android/src/style/conversion/function.hpp new file mode 100644 index 0000000000..ad09ce02d2 --- /dev/null +++ b/platform/android/src/style/conversion/function.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include <mbgl/style/property_value.hpp> +#include "../../conversion/conversion.hpp" +#include "../../conversion/constant.hpp" +#include "types.hpp" +#include "function.hpp" + +#include <jni/jni.hpp> + +#include <tuple> +#include <vector> + +namespace mbgl { +namespace android { +namespace conversion { + +template <class T> +inline jni::jobject* toFunctionStopJavaArray(jni::JNIEnv& env, std::vector<std::pair<float, T>> value) { + static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function$Stop")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/Object;Ljava/lang/Object;)V"); + + jni::jarray<jni::jobject>& jarray = jni::NewObjectArray(env, value.size(), *javaClass); + + for(size_t i = 0; i < value.size(); i = i + 1) { + jni::SetObjectArrayElement(env, jarray, i, &jni::NewObject(env, *javaClass, *constructor, value[i].first, *convert<jni::jobject*, T>(env, value[i].second))); + } + + return &jarray; +} + +template <class T> +struct Converter<jni::jobject*, mbgl::style::Function<T>> { + + Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::Function<T>& value) const { + static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "([Lcom/mapbox/mapboxsdk/style/layers/Function$Stop;)V"); + static jni::jmethodID* withBase = &jni::GetMethodID(env, *javaClass, "withBase", "(F)Lcom/mapbox/mapboxsdk/style/layers/Function;"); + + //Create object + jni::jobject* jfunction = &jni::NewObject(env, *javaClass, *constructor, *toFunctionStopJavaArray(env, value.getStops())); + + //Set base + jni::CallMethod<jni::jobject*>(env, jfunction, *withBase, value.getBase()); + + return {jfunction}; + } +}; + +} // namespace conversion +} // namespace android +} // namespace mbgl
\ No newline at end of file |