[android] text-color option for formatted sections
This commit is contained in:
committed by
Łukasz Paczos
parent
69e11155c8
commit
f1ac3f29c3
@@ -17,8 +17,8 @@ import com.mapbox.mapboxsdk.style.types.Formatted;
|
||||
import com.mapbox.mapboxsdk.style.types.FormattedSection;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.TestingAsyncUtils;
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextColor;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.collator;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
@@ -52,6 +53,7 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -352,6 +354,35 @@ public class ExpressionTest extends EspressoTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionTextColorParam() {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
Expression expression = format(
|
||||
formatEntry(
|
||||
literal("test"),
|
||||
formatTextColor(literal("yellow"))
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(
|
||||
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
|
||||
);
|
||||
assertNull(layer.getTextField().getExpression());
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test", null, null, "rgba(255, 255, 0, 1)")
|
||||
), layer.getTextField().getValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstFormatExpressionAllParams() {
|
||||
validateTestSetup();
|
||||
@@ -366,7 +397,8 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry(
|
||||
"test",
|
||||
formatFontScale(0.5),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
formatTextColor(rgb(126.7, 0, 0))
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
@@ -379,7 +411,8 @@ public class ExpressionTest extends EspressoTest {
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test",
|
||||
0.5,
|
||||
new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"},
|
||||
"rgba(126, 0, 0, 1)")
|
||||
), layer.getTextField().getValue());
|
||||
});
|
||||
}
|
||||
@@ -400,7 +433,7 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatFontScale(1.5),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
|
||||
),
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
formatEntry("\ntest2", formatFontScale(2), formatTextColor(Color.BLUE))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
@@ -412,7 +445,7 @@ public class ExpressionTest extends EspressoTest {
|
||||
assertEquals(new Formatted(
|
||||
new FormattedSection("test", 1.5,
|
||||
new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
new FormattedSection("\ntest2", 2.0)
|
||||
new FormattedSection("\ntest2", 2.0, null, "rgba(0, 0, 255, 1)")
|
||||
), layer.getTextField().getValue());
|
||||
});
|
||||
}
|
||||
@@ -425,6 +458,7 @@ public class ExpressionTest extends EspressoTest {
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
feature.addStringProperty("test_property_color", "green");
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
@@ -433,7 +467,8 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
Expression.FormatOption.formatFontScale(number(get("test_property_number"))),
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"}),
|
||||
formatTextColor(toColor(get("test_property_color")))
|
||||
)
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
@@ -454,6 +489,7 @@ public class ExpressionTest extends EspressoTest {
|
||||
Feature feature = Feature.fromGeometry(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
feature.addStringProperty("test_property", "test");
|
||||
feature.addNumberProperty("test_property_number", 1.5);
|
||||
feature.addStringProperty("test_property_color", "rgba(0, 255, 0, 1)");
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", feature));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
@@ -462,11 +498,12 @@ public class ExpressionTest extends EspressoTest {
|
||||
formatEntry(
|
||||
get("test_property"),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"}),
|
||||
formatTextColor(toColor(get("test_property_color")))
|
||||
),
|
||||
formatEntry("\ntest2", formatFontScale(2))
|
||||
);
|
||||
layer.setProperties(textField(expression));
|
||||
layer.setProperties(textField(expression), textColor("rgba(128, 0, 0, 1)"));
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
@@ -509,9 +546,10 @@ public class ExpressionTest extends EspressoTest {
|
||||
|
||||
Formatted formatted = new Formatted(
|
||||
new FormattedSection("test", 1.5),
|
||||
new FormattedSection("\ntest", 0.5, new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
|
||||
new FormattedSection("\ntest", 0.5, new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"}),
|
||||
new FormattedSection("test", null, null, "rgba(0, 255, 0, 1)")
|
||||
);
|
||||
layer.setProperties(textField(formatted));
|
||||
layer.setProperties(textField(formatted), textColor("rgba(128, 0, 0, 1)"));
|
||||
TestingAsyncUtils.INSTANCE.waitForLayer(uiController, idlingResource.getMapView());
|
||||
|
||||
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
|
||||
|
||||
Reference in New Issue
Block a user