<% const type = locals.type; const properties = locals.properties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. #include "<%- type.replace('-', '_') %>_layer.hpp" #include #include "../conversion/property_value.hpp" #include "../conversion/transition_options.hpp" namespace mbgl { namespace android { <% if (type === 'background') { -%> /** * Creates an owning peer object (for layers not attached to the map) from the JVM side */ <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId) : Layer(env, std::make_uniqueLayer>(jni::Make(env, layerId))) { <% } else { -%> /** * Creates an owning peer object (for layers not attached to the map) from the JVM side */ <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(jni::JNIEnv& env, jni::String layerId, jni::String sourceId) : Layer(env, std::make_uniqueLayer>(jni::Make(env, layerId), jni::Make(env, sourceId))) { <% } -%> } /** * Creates a non-owning peer object (for layers currently attached to the map) */ <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::Map& map, mbgl::style::<%- camelize(type) %>Layer& coreLayer) : Layer(map, coreLayer) { } /** * Creates an owning peer object (for layers not attached to the map) */ <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(mbgl::Map& map, std::unique_ptrLayer> coreLayer) : Layer(map, std::move(coreLayer)) { } <%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default; // Property getters <% for (const property of properties) { -%> jni::Object <%- camelize(type) %>Layer::get<%- camelize(property.name) %>(jni::JNIEnv& env) { using namespace mbgl::android::conversion; Result converted = convert(env, layer.asLayer>()-><%- camelize(type) %>Layer::get<%- camelize(property.name) %>()); return jni::Object(*converted); } <% if (property.transition) { -%> jni::Object <%- camelize(type) %>Layer::get<%- camelize(property.name) %>Transition(jni::JNIEnv& env) { using namespace mbgl::android::conversion; mbgl::style::TransitionOptions options = layer.asLayer>()-><%- camelize(type) %>Layer::get<%- camelize(property.name) %>Transition(); return *convert>(env, options); } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>Transition(jni::JNIEnv&, jlong duration, jlong delay) { mbgl::style::TransitionOptions options; options.duration.emplace(mbgl::Milliseconds(duration)); options.delay.emplace(mbgl::Milliseconds(delay)); layer.asLayer>()-><%- camelize(type) %>Layer::set<%- camelize(property.name) %>Transition(options); } <% } -%> <% } -%> jni::Class<<%- camelize(type) %>Layer> <%- camelize(type) %>Layer::javaClass; jni::jobject* <%- camelize(type) %>Layer::createJavaPeer(jni::JNIEnv& env) { static auto constructor = <%- camelize(type) %>Layer::javaClass.template GetConstructor(env); return <%- camelize(type) %>Layer::javaClass.New(env, constructor, reinterpret_cast(this)); } void <%- camelize(type) %>Layer::registerNative(jni::JNIEnv& env) { // Lookup the class <%- camelize(type) %>Layer::javaClass = *jni::Class<<%- camelize(type) %>Layer>::Find(env).NewGlobalRef(env).release(); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer jni::RegisterNativePeer<<%- camelize(type) %>Layer>( env, <%- camelize(type) %>Layer::javaClass, "nativePtr", <% if (type === 'background') { -%> std::make_unique<<%- camelize(type) %>Layer, JNIEnv&, jni::String>, <% } else { -%> std::make_unique<<%- camelize(type) %>Layer, JNIEnv&, jni::String, jni::String>, <% } -%> "initialize", "finalize",<% for(var i = 0; i < properties.length; i++) {%> <% if (properties[i].transition) { -%> METHOD(&<%- camelize(type) %>Layer::get<%- camelize(properties[i].name) %>Transition, "nativeGet<%- camelize(properties[i].name) %>Transition"), METHOD(&<%- camelize(type) %>Layer::set<%- camelize(properties[i].name) %>Transition, "nativeSet<%- camelize(properties[i].name) %>Transition"), <% } -%> METHOD(&<%- camelize(type) %>Layer::get<%- camelize(properties[i].name) %>, "nativeGet<%- camelize(properties[i].name) %>")<% if(i != (properties.length -1)) {-%>,<% } -%><% } -%>); } } // namespace android } // namespace mbgl