<% const properties = locals.properties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. #include #include "light.hpp" #include "conversion/transition_options.hpp" #include "conversion/position.hpp" namespace mbgl { namespace android { Light::Light(mbgl::Map& coreMap, mbgl::style::Light& coreLight) : light(coreLight) , map(&coreMap) { } static Light* initializeLightPeer(mbgl::Map& map, mbgl::style::Light& coreLight) { return new Light(map, coreLight); } jni::jobject* Light::createJavaLightPeer(jni::JNIEnv& env, Map& map, mbgl::style::Light& coreLight) { std::unique_ptr peerLight = std::unique_ptr(initializeLightPeer(map, coreLight)); jni::jobject* result = peerLight->createJavaPeer(env); peerLight.release(); return result; } jni::Class Light::javaClass; jni::jobject* Light::createJavaPeer(jni::JNIEnv& env) { static auto constructor = Light::javaClass.template GetConstructor(env); return Light::javaClass.New(env, constructor, reinterpret_cast(this)); } <% for (const property of properties) { -%> <% if (property.name == "position") { -%> void Light::set<%- camelize(property.name) %>(jni::JNIEnv& env, jni::Object<<%- camelize(property.name) %>> j<%- property.name %>) { using namespace mbgl::android::conversion; auto position = *convert>(env, jposition); light.set<%- camelize(property.name) %>(<%- property.name %>); } jni::Object Light::get<%- camelize(property.name) %>(jni::JNIEnv& env) { using namespace mbgl::android::conversion; mbgl::style::<%- camelize(property.name) %> <%- property.name %> = light.get<%- camelize(property.name) %>().asConstant(); return *convert>>(env, <%- property.name %>); } <% } else { -%> <% if(property.name == "color") {-%> void Light::set<%- camelize(property.name) %>(jni::JNIEnv& env, jni::<%- propertyJNIType(property) %> property) { auto color = Color::parse(jni::Make(env, property)); if (color) { light.set<%- camelize(property.name) %>(color.value()); } } jni::String Light::get<%- camelize(property.name) %>(jni::JNIEnv &env) { auto color = light.get<%- camelize(property.name) %>().asConstant(); return jni::Make(env, color.stringify()); } <% } else if(property.name == "anchor"){ -%> void Light::set<%- camelize(property.name) %>(jni::JNIEnv& env, jni::<%- propertyJNIType(property) %> property) { std::string anchorStr = jni::Make(env, property); if (anchorStr.compare("map") == 0) { light.setAnchor(LightAnchorType::Map); } else if (anchorStr.compare("viewport") == 0) { light.setAnchor(LightAnchorType::Viewport); } } jni::String Light::getAnchor(jni::JNIEnv& env) { auto anchorType = light.getAnchor(); if (anchorType == LightAnchorType::Map) { return jni::Make(env, "map"); } else { return jni::Make(env, "viewport"); } } <% } else { -%> void Light::set<%- camelize(property.name) %>(jni::JNIEnv&, jni::<%- propertyJNIType(property) %> property) { light.set<%- camelize(property.name) %>(property); } jni::<%- propertyJNIType(property) %> Light::get<%- camelize(property.name) %>(jni::JNIEnv&) { return light.get<%- camelize(property.name) %>().asConstant(); } <% } -%> <% } -%> <% if (property.transition) { -%> jni::Object Light::get<%- camelize(property.name) %>Transition(jni::JNIEnv& env) { using namespace mbgl::android::conversion; mbgl::style::TransitionOptions options = light.get<%- camelize(property.name) %>Transition(); return *convert>(env, options); } void Light::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)); light.set<%- camelize(property.name) %>Transition(options); } <% } -%> <% } -%> void Light::registerNative(jni::JNIEnv& env) { // Lookup the class Light::javaClass = *jni::Class::Find(env).NewGlobalRef(env).release(); #define METHOD(MethodPtr, name) jni::MakeNativePeerMethod(name) // Register the peer jni::RegisterNativePeer(env, Light::javaClass, "nativePtr",<% for(var i = 0; i < properties.length; i++) {%> <% if (properties[i].transition) { -%> METHOD(&Light::get<%- camelize(properties[i].name) %>Transition, "nativeGet<%- camelize(properties[i].name) %>Transition"), METHOD(&Light::set<%- camelize(properties[i].name) %>Transition, "nativeSet<%- camelize(properties[i].name) %>Transition"), <% } -%> METHOD(&Light::get<%- camelize(properties[i].name) %>, "nativeGet<%- camelize(properties[i].name) %>"), METHOD(&Light::set<%- camelize(properties[i].name) %>, "nativeSet<%- camelize(properties[i].name) %>")<% if(i != (properties.length -1)) {-%>,<% } -%><% } -%>); } } // namespace android } // namespace mb