summaryrefslogtreecommitdiff
path: root/platform/android/src/style/formatted.cpp
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-03-14 18:37:54 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-03-15 16:17:59 +0100
commitf1ac3f29c3f1255299db6cf19f7a28d66014593d (patch)
tree132359f7fa31276056f285c6d7a939165411d584 /platform/android/src/style/formatted.cpp
parent69e11155c839b1f2a8685331b4104f82f1aa9882 (diff)
downloadqtlocation-mapboxgl-f1ac3f29c3f1255299db6cf19f7a28d66014593d.tar.gz
[android] text-color option for formatted sections
Diffstat (limited to 'platform/android/src/style/formatted.cpp')
-rw-r--r--platform/android/src/style/formatted.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/platform/android/src/style/formatted.cpp b/platform/android/src/style/formatted.cpp
index 8659e6961e..69c3454e23 100644
--- a/platform/android/src/style/formatted.cpp
+++ b/platform/android/src/style/formatted.cpp
@@ -1,5 +1,7 @@
#include "formatted.hpp"
#include "formatted_section.hpp"
+#include "../conversion/conversion.hpp"
+#include "../conversion/constant.hpp"
namespace mbgl {
namespace android {
@@ -11,36 +13,38 @@ void Formatted::registerNative(jni::JNIEnv& env) {
jni::Local<jni::Object<Formatted>> Formatted::New(jni::JNIEnv& env, const style::expression::Formatted& value) {
static auto& formatted = jni::Class<Formatted>::Singleton(env);
static auto formattedConstructor = formatted.GetConstructor<jni::Array<jni::Object<FormattedSection>>>(env);
- static auto& formattedSection = jni::Class<FormattedSection>::Singleton(env);
+ static auto& formattedSectionClass = jni::Class<FormattedSection>::Singleton(env);
auto sections = jni::Array<jni::Object<FormattedSection>>::New(env, value.sections.size());
for (std::size_t i = 0; i < value.sections.size(); i++) {
auto section = value.sections.at(i);
auto text = jni::Make<jni::String>(env, section.text);
+ static auto formattedSectionConstructor = formattedSectionClass.GetConstructor<jni::String>(env);
+ auto formattedSection = formattedSectionClass.New(env, formattedSectionConstructor, text);
- if (section.fontStack && section.fontScale) {
+ if (section.fontScale) {
double fontScale = section.fontScale.value();
+ static auto method = formattedSectionClass.GetMethod<void (jni::Number)>(env, "setFontScale");
+ formattedSection.Call(env, method, jni::Box(env, fontScale));
+ }
+
+ if (section.fontStack) {
auto fontStack = jni::Array<jni::String>::New(env, section.fontStack.value().size());
for (std::size_t j = 0; j < section.fontStack.value().size(); j++) {
fontStack.Set(env, j, jni::Make<jni::String>(env, section.fontStack.value().at(j)));
}
- static auto formattedSectionConstructor = formattedSection.GetConstructor<jni::String, jni::Number, jni::Array<jni::String>>(env);
- sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text, jni::Box(env, fontScale), fontStack));
- } else if (section.fontScale) {
- double fontScale = section.fontScale.value();
- static auto formattedSectionConstructor = formattedSection.GetConstructor<jni::String, jni::Number>(env);
- sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text, jni::Box(env, fontScale)));
- } else if (section.fontStack) {
- auto fontStack = jni::Array<jni::String>::New(env, section.fontStack.value().size());
- for (std::size_t j = 0; j < section.fontStack.value().size(); j++) {
- fontStack.Set(env, j, jni::Make<jni::String>(env, section.fontStack.value().at(j)));
- }
- static auto formattedSectionConstructor = formattedSection.GetConstructor<jni::String, jni::Array<jni::String>>(env);
- sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text, fontStack));
- } else {
- static auto formattedSectionConstructor = formattedSection.GetConstructor<jni::String>(env);
- sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text));
+ static auto method = formattedSectionClass.GetMethod<void (jni::Array<jni::String>)>(env, "setFontStack");
+ formattedSection.Call(env, method, fontStack);
}
+
+ if (section.textColor) {
+ using namespace mbgl::android::conversion;
+ auto textColor = std::move(*convert<jni::Local<jni::Object<>>>(env, *section.textColor));
+ static auto method = formattedSectionClass.GetMethod<void (jni::Object<>)>(env, "setTextColor");
+ formattedSection.Call(env, method, textColor);
+ }
+
+ sections.Set(env, i, formattedSection);
}
return formatted.New(env, formattedConstructor, sections);