diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-07-26 17:02:52 -0400 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-08-02 16:58:03 -0400 |
commit | 10b2cc60a7b274f71b46976b1e9e89031b9e44ca (patch) | |
tree | 8f3cccee03e5a4205c4754f7eb723ec73d19c8b5 /platform/android/src/style/conversion/function.hpp | |
parent | ed821c06d96e414b43db6fd1505389803cb022d4 (diff) | |
download | qtlocation-mapboxgl-10b2cc60a7b274f71b46976b1e9e89031b9e44ca.tar.gz |
[android] #5610 - Runtime style api - part 2
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 |