summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-09-19 15:20:03 -0700
committerChris Loer <chris.loer@mapbox.com>2018-10-15 13:15:46 -0700
commitfdfb9386a6732d5a00c5c205013aa1d9ed8b91a4 (patch)
treeb6640441896e8f2af413ebc4a1a0568a32fd9f51 /platform/android
parentd0cd49f516d053620147e9f047252bd88374ac5d (diff)
downloadqtlocation-mapboxgl-fdfb9386a6732d5a00c5c205013aa1d9ed8b91a4.tar.gz
[android] Minimal Android support for 'format' expression
- No dedicated support for creating format expressions - Java accessors for 'text-field' flatten back to String - 'text-field' setter implicitly creates a 'format' expression. For tests, use JsonArray to build an equivalent format expression by hand.
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java27
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs33
-rw-r--r--platform/android/src/conversion/constant.cpp4
-rw-r--r--platform/android/src/conversion/constant.hpp7
4 files changed, 69 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java
index 98c9c27fc2..7026e87a47 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java
@@ -13,6 +13,8 @@ import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
@@ -477,7 +479,18 @@ public class SymbolLayerTest extends BaseActivityTest {
assertEquals((String) layer.getTextField().getValue(), (String) "");
layer.setProperties(textField("{token}"));
- assertEquals(layer.getTextField().getExpression(), Expression.toString(Expression.get("token")));
+ JsonArray formatExpression = new JsonArray();
+ formatExpression.add("format");
+ JsonArray getExpression = new JsonArray();
+ getExpression.add("get");
+ getExpression.add("token");
+ JsonArray stringCoercion = new JsonArray();
+ stringCoercion.add("to-string");
+ stringCoercion.add(getExpression);
+ formatExpression.add(stringCoercion);
+ formatExpression.add(new JsonObject());
+ assertEquals(layer.getTextField().getExpression(),
+ Converter.convert(formatExpression));
});
}
@@ -490,7 +503,17 @@ public class SymbolLayerTest extends BaseActivityTest {
assertNotNull(layer);
// Set and Get
- Expression expression = string(Expression.get("undefined"));
+ JsonArray formatExpression = new JsonArray();
+ formatExpression.add("format");
+ JsonArray getExpression = new JsonArray();
+ getExpression.add("get");
+ getExpression.add("undefined");
+ JsonArray stringAssertion = new JsonArray();
+ stringAssertion.add("string");
+ stringAssertion.add(getExpression);
+ formatExpression.add(stringAssertion);
+ formatExpression.add(new JsonObject());
+ Expression expression = Converter.convert(formatExpression);
layer.setProperties(textField(expression));
assertEquals(layer.getTextField().getExpression(), expression);
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
index 142d1bd203..e78620d1b7 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs
@@ -17,6 +17,10 @@ import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import org.junit.Test;
import org.junit.runner.RunWith;
+<% if (type === 'symbol') { -%>
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+<% } -%>
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
@@ -165,8 +169,23 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
<% if (property.tokens) { -%>
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>("{token}"));
+<% if (property.type === 'formatted') { -%>
+ JsonArray formatExpression = new JsonArray();
+ formatExpression.add("format");
+ JsonArray getExpression = new JsonArray();
+ getExpression.add("get");
+ getExpression.add("token");
+ JsonArray stringCoercion = new JsonArray();
+ stringCoercion.add("to-string");
+ stringCoercion.add(getExpression);
+ formatExpression.add(stringCoercion);
+ formatExpression.add(new JsonObject());
+ assertEquals(layer.getTextField().getExpression(),
+ Converter.convert(formatExpression));
+<% } else { -%>
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), Expression.toString(Expression.get("token")));
<% } -%>
+<% } -%>
});
}
<% if (property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven') { -%>
@@ -181,7 +200,21 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
assertNotNull(layer);
// Set and Get
+<% if (property.type === 'formatted') { -%>
+ JsonArray formatExpression = new JsonArray();
+ formatExpression.add("format");
+ JsonArray getExpression = new JsonArray();
+ getExpression.add("get");
+ getExpression.add("undefined");
+ JsonArray stringAssertion = new JsonArray();
+ stringAssertion.add("string");
+ stringAssertion.add(getExpression);
+ formatExpression.add(stringAssertion);
+ formatExpression.add(new JsonObject());
+ Expression expression = Converter.convert(formatExpression);
+<% } else { -%>
Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined"));
+<% } -%>
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(expression));
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), expression);
});
diff --git a/platform/android/src/conversion/constant.cpp b/platform/android/src/conversion/constant.cpp
index 804d5fd146..eaff434dbc 100644
--- a/platform/android/src/conversion/constant.cpp
+++ b/platform/android/src/conversion/constant.cpp
@@ -29,6 +29,10 @@ Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, Color>::o
return jni::Make<jni::String>(env, sstream.str());
}
+Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, style::expression::Formatted>::operator()(jni::JNIEnv& env, const style::expression::Formatted& value) const {
+ return jni::Make<jni::String>(env, value.toString());
+}
+
Result<jni::Local<jni::Object<>>> Converter<jni::Local<jni::Object<>>, std::vector<std::string>>::operator()(jni::JNIEnv& env, const std::vector<std::string>& value) const {
auto result = jni::Array<jni::String>::New(env, value.size());
diff --git a/platform/android/src/conversion/constant.hpp b/platform/android/src/conversion/constant.hpp
index c6dafe1174..4def670f3c 100644
--- a/platform/android/src/conversion/constant.hpp
+++ b/platform/android/src/conversion/constant.hpp
@@ -5,6 +5,8 @@
#include <mbgl/util/color.hpp>
#include <mbgl/util/enum.hpp>
+#include <mbgl/style/expression/formatted.hpp>
+
#include <jni/jni.hpp>
#include <string>
@@ -53,6 +55,11 @@ struct Converter<jni::Local<jni::Object<>>, Color> {
Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const Color& value) const;
};
+template <>
+struct Converter<jni::Local<jni::Object<>>, style::expression::Formatted> {
+ Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const style::expression::Formatted& value) const;
+};
+
template <std::size_t N>
struct Converter<jni::Local<jni::Object<>>, std::array<float, N>> {
Result<jni::Local<jni::Object<>>> operator()(jni::JNIEnv& env, const std::array<float, N>& value) const {