Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] renamed format expression options, added format expression …
Browse files Browse the repository at this point in the history
…example
  • Loading branch information
LukasPaczos committed Oct 24, 2018
1 parent 3d67c78 commit d5b66e5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3246,10 +3246,13 @@ public static Expression collator(Expression caseSensitive, Expression diacritic
* format(
* formatEntry(
* get("header_property"),
* fontScale(2.0),
* textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
* formatFontScale(2.0),
* formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
* ),
* formatEntry(concat(literal("\n"), get("description_property")), fontScale(1.5)),
* formatEntry(concat(literal("\n"), get("description_property")), formatFontScale(1.5))
* )
* )
* );
* }
* </pre>
*
Expand Down Expand Up @@ -4375,7 +4378,7 @@ public static class FormatOption {
* @return format option
*/
@NonNull
public static FormatOption fontScale(@NonNull Expression expression) {
public static FormatOption formatFontScale(@NonNull Expression expression) {
return new FormatOption("font-scale", expression);
}

Expand All @@ -4389,7 +4392,7 @@ public static FormatOption fontScale(@NonNull Expression expression) {
* @return format option
*/
@NonNull
public static FormatOption fontScale(double scale) {
public static FormatOption formatFontScale(double scale) {
return new FormatOption("font-scale", literal(scale));
}

Expand All @@ -4405,7 +4408,7 @@ public static FormatOption fontScale(double scale) {
* @return format option
*/
@NonNull
public static FormatOption textFont(@NonNull Expression expression) {
public static FormatOption formatTextFont(@NonNull Expression expression) {
return new FormatOption("text-font", expression);
}

Expand All @@ -4421,7 +4424,7 @@ public static FormatOption textFont(@NonNull Expression expression) {
* @return format option
*/
@NonNull
public static FormatOption textFont(@NonNull String[] fontStack) {
public static FormatOption formatTextFont(@NonNull String[] fontStack) {
return new FormatOption("text-font", literal(fontStack));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public PropertyValue<String> getTextField() {
* Get the TextField property as {@link Formatted} object
*
* @return property wrapper value around String
* @see Expression#format(Expression...)
* @see Expression#format(Expression.FormatEntry...)
*/
@SuppressWarnings("unchecked")
public PropertyValue<Formatted> getFormattedTextField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* Get the <%- camelize(property.name) %> property as {@link Formatted} object
*
* @return property wrapper value around <%- propertyType(property) %>
* @see Expression#format(Expression...)
* @see Expression#format(Expression.FormatEntry...)
*/
@SuppressWarnings("unchecked")
public PropertyValue<Formatted> getFormatted<%- camelize(property.name) %>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.util.Locale;
import java.util.Map;

import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.fontScale;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.textFont;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
import static com.mapbox.mapboxsdk.style.expressions.Expression.abs;
import static com.mapbox.mapboxsdk.style.expressions.Expression.acos;
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
Expand Down Expand Up @@ -1420,7 +1420,8 @@ public void testFormatSingleArgument() {
}
};
Object[] actual = format(
formatEntry(literal("test"), fontScale(literal(1.5)), textFont(literal(new String[] {"awesome"})))
formatEntry(
literal("test"), formatFontScale(literal(1.5)), formatTextFont(literal(new String[] {"awesome"})))
).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}
Expand Down Expand Up @@ -1455,10 +1456,11 @@ public void testFormatMultipleArgument() {
}
};
Object[] actual = format(
formatEntry(literal("test"), textFont(new String[] {"awesome"})),
formatEntry("test2", fontScale(1.5)),
formatEntry(literal("test"), formatTextFont(new String[] {"awesome"})),
formatEntry("test2", formatFontScale(1.5)),
formatEntry(literal("test3")),
formatEntry(literal("test4"), fontScale(literal(1.5)), textFont(new String[] {"awesome"}))
formatEntry(
literal("test4"), formatFontScale(literal(1.5)), formatTextFont(new String[] {"awesome"}))
).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import timber.log.Timber;

import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.fontScale;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.textFont;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
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;
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
Expand Down Expand Up @@ -315,7 +315,7 @@ public void testConstFormatExpressionFontScaleParam() {
mapboxMap.addLayer(layer);

Expression expression = format(
formatEntry("test", fontScale(1.75))
formatEntry("test", formatFontScale(1.75))
);
layer.setProperties(textField(expression));
waitForLayer(uiController, mapboxMap, latLng);
Expand Down Expand Up @@ -344,13 +344,16 @@ public void testConstFormatExpressionTextFontParam() {

Expression expression = format(
formatEntry(
literal("test"), fontScale(1.0), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
literal("test"),
formatFontScale(1.0),
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
)
);
layer.setProperties(textField(expression));
waitForLayer(uiController, mapboxMap, latLng);
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
.isEmpty());
assertFalse(
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
);

assertNull(layer.getTextField().getExpression());
assertEquals("test", layer.getTextField().getValue());
Expand All @@ -375,13 +378,16 @@ public void testConstFormatExpressionAllParams() {

Expression expression = format(
formatEntry(
"test", fontScale(0.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
"test",
formatFontScale(0.5),
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
)
);
layer.setProperties(textField(expression));
waitForLayer(uiController, mapboxMap, latLng);
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
.isEmpty());
assertFalse(
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
);

assertNull(layer.getTextField().getExpression());
assertEquals("test", layer.getTextField().getValue());
Expand All @@ -404,14 +410,17 @@ public void testConstFormatExpressionMultipleInputs() {

Expression expression = format(
formatEntry(
"test", fontScale(1.5), textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
"test",
formatFontScale(1.5),
formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"})
),
formatEntry("\ntest2", fontScale(2))
formatEntry("\ntest2", formatFontScale(2))
);
layer.setProperties(textField(expression));
waitForLayer(uiController, mapboxMap, latLng);
assertFalse(mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer")
.isEmpty());
assertFalse(
mapboxMap.queryRenderedFeatures(mapboxMap.getProjection().toScreenLocation(latLng), "layer").isEmpty()
);

assertNull(layer.getTextField().getExpression());
assertEquals("test\ntest2", layer.getTextField().getValue());
Expand Down Expand Up @@ -440,8 +449,8 @@ public void testVariableFormatExpression() {
Expression expression = format(
formatEntry(
get("test_property"),
fontScale(number(get("test_property_number"))),
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
Expression.FormatOption.formatFontScale(number(get("test_property_number"))),
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
)
);
layer.setProperties(textField(expression));
Expand Down Expand Up @@ -472,10 +481,10 @@ public void testVariableFormatExpressionMultipleInputs() {
Expression expression = format(
formatEntry(
get("test_property"),
fontScale(1.25),
textFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
formatFontScale(1.25),
formatTextFont(new String[] {"Arial Unicode MS Regular", "DIN Offc Pro Regular"})
),
formatEntry("\ntest2", fontScale(2))
formatEntry("\ntest2", formatFontScale(2))
);
layer.setProperties(textField(expression));
waitForLayer(uiController, mapboxMap, latLng);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.mapbox.geojson.Feature;
Expand All @@ -29,6 +30,11 @@

import java.util.List;

import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatFontScale;
import static com.mapbox.mapboxsdk.style.expressions.Expression.FormatOption.formatTextFont;
import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
import static com.mapbox.mapboxsdk.style.expressions.Expression.format;
import static com.mapbox.mapboxsdk.style.expressions.Expression.formatEntry;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase;
Expand Down Expand Up @@ -118,7 +124,16 @@ public void onMapReady(MapboxMap mapboxMap) {
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
iconColor(Color.RED),
textField(get(TITLE_FEATURE_PROPERTY)),
textField(
format(
formatEntry("this is", formatFontScale(0.75)),
formatEntry(
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
formatFontScale(1.25),
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
)
)
),
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
textColor(Color.RED),
textAllowOverlap(true),
Expand Down

0 comments on commit d5b66e5

Please sign in to comment.