1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<%
const properties = locals.properties;
-%>
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`.
#include <mbgl/map/map.hpp>
#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<Light> peerLight = std::unique_ptr<Light>(initializeLightPeer(map, coreLight));
jni::jobject* result = peerLight->createJavaPeer(env);
peerLight.release();
return result;
}
jni::Class<Light> Light::javaClass;
jni::jobject* Light::createJavaPeer(jni::JNIEnv& env) {
static auto constructor = Light::javaClass.template GetConstructor<jni::jlong>(env);
return Light::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(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<mbgl::style::<%- camelize(property.name) %>>(env, jposition);
light.set<%- camelize(property.name) %>(<%- property.name %>);
}
jni::Object<Position> 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<jni::Object<<%- camelize(property.name) %>>>(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<std::string>(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<jni::String>(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<std::string>(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<jni::String>(env, "map");
} else {
return jni::Make<jni::String>(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<TransitionOptions> 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<jni::Object<TransitionOptions>>(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<Light>::Find(env).NewGlobalRef(env).release();
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
// Register the peer
jni::RegisterNativePeer<Light>(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
|