summaryrefslogtreecommitdiff
path: root/platform/android/src/style/sources/source.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <ivovandongen@users.noreply.github.com>2016-09-21 11:04:32 +0200
committerGitHub <noreply@github.com>2016-09-21 11:04:32 +0200
commiteb97dbe383ca7697feab5860995b97181c39c607 (patch)
tree70bdd7b6ebea32aec132413fa703e92a2a0f63d0 /platform/android/src/style/sources/source.cpp
parent3b546b964609d0f596dac32e155b1489bb85645e (diff)
downloadqtlocation-mapboxgl-eb97dbe383ca7697feab5860995b97181c39c607.tar.gz
[android] Sources: peer model, mutability (#6054)
Diffstat (limited to 'platform/android/src/style/sources/source.cpp')
-rw-r--r--platform/android/src/style/sources/source.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp
new file mode 100644
index 0000000000..4f306e7c54
--- /dev/null
+++ b/platform/android/src/style/sources/source.cpp
@@ -0,0 +1,72 @@
+#include "source.hpp"
+#include "../android_conversion.hpp"
+
+#include <jni/jni.hpp>
+
+#include <mbgl/platform/log.hpp>
+
+//Java -> C++ conversion
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/conversion/source.hpp>
+
+//C++ -> Java conversion
+#include "../conversion/property_value.hpp"
+
+#include <string>
+
+namespace mbgl {
+namespace android {
+
+ /**
+ * Invoked when the construction is initiated from the jvm through a subclass
+ */
+ Source::Source(jni::JNIEnv&, std::unique_ptr<mbgl::style::Source> coreSource)
+ : ownedSource(std::move(coreSource))
+ , source(*ownedSource) {
+ }
+
+ Source::Source(mbgl::Map& coreMap, mbgl::style::Source& coreSource) : source(coreSource) , map(&coreMap) {
+ }
+
+ Source::~Source() {
+ }
+
+ jni::String Source::getId(jni::JNIEnv& env) {
+ return jni::Make<jni::String>(env, source.getID());
+ }
+
+ void Source::updateStyle(jni::jboolean updateClasses) {
+ //Update the style only if attached
+ if (ownedSource == nullptr) {
+ Update flags = mbgl::Update::RecalculateStyle;
+ if(updateClasses) {
+ flags = flags | mbgl::Update::Classes;
+ }
+ map->update(flags);
+ } else {
+ mbgl::Log::Debug(mbgl::Event::JNI, "Not updating as source is not attached to map (yet)");
+ }
+ }
+
+ std::unique_ptr<mbgl::style::Source> Source::releaseCoreSource() {
+ assert(ownedSource != nullptr);
+ return std::move(ownedSource);
+ }
+
+ jni::Class<Source> Source::javaClass;
+
+ void Source::registerNative(jni::JNIEnv& env) {
+ //Lookup the class
+ Source::javaClass = *jni::Class<Source>::Find(env).NewGlobalRef(env).release();
+
+ #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
+
+ //Register the peer
+ jni::RegisterNativePeer<Source>(env, Source::javaClass, "nativePtr",
+ METHOD(&Source::getId, "nativeGetId")
+ );
+
+ }
+
+} //android
+} //mbgl \ No newline at end of file