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

Commit

Permalink
[android] verify if text-field is not null before performing compat…
Browse files Browse the repository at this point in the history
…ibility operations

(cherry picked from commit bb55bae)
  • Loading branch information
LukasPaczos authored and tobrun committed Nov 7, 2018
1 parent f5baaf8 commit 408a767
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,18 @@ public PropertyValue<String> getTextField() {
if (propertyValue.isExpression()) {
return (PropertyValue<String>) propertyValue;
} else {
String text = null;

Formatted formatted = (Formatted) nativeGetTextField();
StringBuilder builder = new StringBuilder();
for (FormattedSection section : formatted.getFormattedSections()) {
builder.append(section.getText());
if (formatted != null) {
StringBuilder builder = new StringBuilder();
for (FormattedSection section : formatted.getFormattedSections()) {
builder.append(section.getText());
}
text = builder.toString();
}

return (PropertyValue<String>) new PropertyValue("text-field", builder.toString());
return (PropertyValue<String>) new PropertyValue("text-field", text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,18 @@ public class <%- camelize(type) %>Layer extends Layer {
if (propertyValue.isExpression()) {
return (PropertyValue<String>) propertyValue;
} else {
String text = null;
Formatted formatted = (Formatted) nativeGetTextField();
StringBuilder builder = new StringBuilder();
for (FormattedSection section : formatted.getFormattedSections()) {
builder.append(section.getText());
if (formatted != null) {
StringBuilder builder = new StringBuilder();
for (FormattedSection section : formatted.getFormattedSections()) {
builder.append(section.getText());
}
text = builder.toString();
}
return (PropertyValue<String>) new PropertyValue("text-field", builder.toString());
return (PropertyValue<String>) new PropertyValue("text-field", text);
}
<% } else { -%>
return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void testBackgroundColorAsConstant() {
Timber.i("background-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getBackgroundColor().getValue());

// Set and Get
layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)"));
Expand Down Expand Up @@ -125,6 +126,7 @@ public void testBackgroundPatternAsConstant() {
Timber.i("background-pattern");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getBackgroundPattern().getValue());

// Set and Get
layer.setProperties(backgroundPattern("pedestrian-polygon"));
Expand Down Expand Up @@ -154,6 +156,7 @@ public void testBackgroundOpacityAsConstant() {
Timber.i("background-opacity");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getBackgroundOpacity().getValue());

// Set and Get
layer.setProperties(backgroundOpacity(0.3f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void testCircleRadiusAsConstant() {
Timber.i("circle-radius");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getCircleRadius().getValue());

// Set and Get
layer.setProperties(circleRadius(0.3f));
Expand All @@ -153,6 +154,7 @@ public void testCircleRadiusAsExpression() {
Timber.i("circle-radius-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleRadius().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -183,6 +185,7 @@ public void testCircleColorAsConstant() {
Timber.i("circle-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getCircleColor().getValue());

// Set and Get
layer.setProperties(circleColor("rgba(0, 0, 0, 1)"));
Expand All @@ -197,6 +200,7 @@ public void testCircleColorAsExpression() {
Timber.i("circle-color-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleColor().getExpression());

// Set and Get
Expression expression = toColor(Expression.get("undefined"));
Expand Down Expand Up @@ -241,6 +245,7 @@ public void testCircleBlurAsConstant() {
Timber.i("circle-blur");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getCircleBlur().getValue());

// Set and Get
layer.setProperties(circleBlur(0.3f));
Expand All @@ -255,6 +260,7 @@ public void testCircleBlurAsExpression() {
Timber.i("circle-blur-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleBlur().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -285,6 +291,7 @@ public void testCircleOpacityAsConstant() {
Timber.i("circle-opacity");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getCircleOpacity().getValue());

// Set and Get
layer.setProperties(circleOpacity(0.3f));
Expand All @@ -299,6 +306,7 @@ public void testCircleOpacityAsExpression() {
Timber.i("circle-opacity-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleOpacity().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -329,6 +337,7 @@ public void testCircleTranslateAsConstant() {
Timber.i("circle-translate");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float[]) layer.getCircleTranslate().getValue());

// Set and Get
layer.setProperties(circleTranslate(new Float[] {0f, 0f}));
Expand All @@ -343,6 +352,7 @@ public void testCircleTranslateAnchorAsConstant() {
Timber.i("circle-translate-anchor");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getCircleTranslateAnchor().getValue());

// Set and Get
layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP));
Expand All @@ -357,6 +367,7 @@ public void testCirclePitchScaleAsConstant() {
Timber.i("circle-pitch-scale");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getCirclePitchScale().getValue());

// Set and Get
layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP));
Expand All @@ -371,6 +382,7 @@ public void testCirclePitchAlignmentAsConstant() {
Timber.i("circle-pitch-alignment");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getCirclePitchAlignment().getValue());

// Set and Get
layer.setProperties(circlePitchAlignment(CIRCLE_PITCH_ALIGNMENT_MAP));
Expand Down Expand Up @@ -400,6 +412,7 @@ public void testCircleStrokeWidthAsConstant() {
Timber.i("circle-stroke-width");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getCircleStrokeWidth().getValue());

// Set and Get
layer.setProperties(circleStrokeWidth(0.3f));
Expand All @@ -414,6 +427,7 @@ public void testCircleStrokeWidthAsExpression() {
Timber.i("circle-stroke-width-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleStrokeWidth().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -444,6 +458,7 @@ public void testCircleStrokeColorAsConstant() {
Timber.i("circle-stroke-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getCircleStrokeColor().getValue());

// Set and Get
layer.setProperties(circleStrokeColor("rgba(0, 0, 0, 1)"));
Expand All @@ -458,6 +473,7 @@ public void testCircleStrokeColorAsExpression() {
Timber.i("circle-stroke-color-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleStrokeColor().getExpression());

// Set and Get
Expression expression = toColor(Expression.get("undefined"));
Expand Down Expand Up @@ -502,6 +518,7 @@ public void testCircleStrokeOpacityAsConstant() {
Timber.i("circle-stroke-opacity");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getCircleStrokeOpacity().getValue());

// Set and Get
layer.setProperties(circleStrokeOpacity(0.3f));
Expand All @@ -516,6 +533,7 @@ public void testCircleStrokeOpacityAsExpression() {
Timber.i("circle-stroke-opacity-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getCircleStrokeOpacity().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void testFillExtrusionOpacityAsConstant() {
Timber.i("fill-extrusion-opacity");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getFillExtrusionOpacity().getValue());

// Set and Get
layer.setProperties(fillExtrusionOpacity(0.3f));
Expand Down Expand Up @@ -168,6 +169,7 @@ public void testFillExtrusionColorAsConstant() {
Timber.i("fill-extrusion-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillExtrusionColor().getValue());

// Set and Get
layer.setProperties(fillExtrusionColor("rgba(0, 0, 0, 1)"));
Expand All @@ -182,6 +184,7 @@ public void testFillExtrusionColorAsExpression() {
Timber.i("fill-extrusion-color-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillExtrusionColor().getExpression());

// Set and Get
Expression expression = toColor(Expression.get("undefined"));
Expand Down Expand Up @@ -226,6 +229,7 @@ public void testFillExtrusionTranslateAsConstant() {
Timber.i("fill-extrusion-translate");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float[]) layer.getFillExtrusionTranslate().getValue());

// Set and Get
layer.setProperties(fillExtrusionTranslate(new Float[] {0f, 0f}));
Expand All @@ -240,6 +244,7 @@ public void testFillExtrusionTranslateAnchorAsConstant() {
Timber.i("fill-extrusion-translate-anchor");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillExtrusionTranslateAnchor().getValue());

// Set and Get
layer.setProperties(fillExtrusionTranslateAnchor(FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP));
Expand Down Expand Up @@ -269,6 +274,7 @@ public void testFillExtrusionPatternAsConstant() {
Timber.i("fill-extrusion-pattern");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillExtrusionPattern().getValue());

// Set and Get
layer.setProperties(fillExtrusionPattern("pedestrian-polygon"));
Expand All @@ -283,6 +289,7 @@ public void testFillExtrusionPatternAsExpression() {
Timber.i("fill-extrusion-pattern-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillExtrusionPattern().getExpression());

// Set and Get
Expression expression = string(Expression.get("undefined"));
Expand Down Expand Up @@ -313,6 +320,7 @@ public void testFillExtrusionHeightAsConstant() {
Timber.i("fill-extrusion-height");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getFillExtrusionHeight().getValue());

// Set and Get
layer.setProperties(fillExtrusionHeight(0.3f));
Expand All @@ -327,6 +335,7 @@ public void testFillExtrusionHeightAsExpression() {
Timber.i("fill-extrusion-height-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillExtrusionHeight().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -357,6 +366,7 @@ public void testFillExtrusionBaseAsConstant() {
Timber.i("fill-extrusion-base");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getFillExtrusionBase().getValue());

// Set and Get
layer.setProperties(fillExtrusionBase(0.3f));
Expand All @@ -371,6 +381,7 @@ public void testFillExtrusionBaseAsExpression() {
Timber.i("fill-extrusion-base-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillExtrusionBase().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void testFillAntialiasAsConstant() {
Timber.i("fill-antialias");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Boolean) layer.getFillAntialias().getValue());

// Set and Get
layer.setProperties(fillAntialias(true));
Expand Down Expand Up @@ -153,6 +154,7 @@ public void testFillOpacityAsConstant() {
Timber.i("fill-opacity");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float) layer.getFillOpacity().getValue());

// Set and Get
layer.setProperties(fillOpacity(0.3f));
Expand All @@ -167,6 +169,7 @@ public void testFillOpacityAsExpression() {
Timber.i("fill-opacity-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillOpacity().getExpression());

// Set and Get
Expression expression = number(Expression.get("undefined"));
Expand Down Expand Up @@ -197,6 +200,7 @@ public void testFillColorAsConstant() {
Timber.i("fill-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillColor().getValue());

// Set and Get
layer.setProperties(fillColor("rgba(0, 0, 0, 1)"));
Expand All @@ -211,6 +215,7 @@ public void testFillColorAsExpression() {
Timber.i("fill-color-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillColor().getExpression());

// Set and Get
Expression expression = toColor(Expression.get("undefined"));
Expand Down Expand Up @@ -255,6 +260,7 @@ public void testFillOutlineColorAsConstant() {
Timber.i("fill-outline-color");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillOutlineColor().getValue());

// Set and Get
layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)"));
Expand All @@ -269,6 +275,7 @@ public void testFillOutlineColorAsExpression() {
Timber.i("fill-outline-color-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillOutlineColor().getExpression());

// Set and Get
Expression expression = toColor(Expression.get("undefined"));
Expand Down Expand Up @@ -313,6 +320,7 @@ public void testFillTranslateAsConstant() {
Timber.i("fill-translate");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((Float[]) layer.getFillTranslate().getValue());

// Set and Get
layer.setProperties(fillTranslate(new Float[] {0f, 0f}));
Expand All @@ -327,6 +335,7 @@ public void testFillTranslateAnchorAsConstant() {
Timber.i("fill-translate-anchor");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillTranslateAnchor().getValue());

// Set and Get
layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP));
Expand Down Expand Up @@ -356,6 +365,7 @@ public void testFillPatternAsConstant() {
Timber.i("fill-pattern");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull((String) layer.getFillPattern().getValue());

// Set and Get
layer.setProperties(fillPattern("pedestrian-polygon"));
Expand All @@ -370,6 +380,7 @@ public void testFillPatternAsExpression() {
Timber.i("fill-pattern-expression");
invoke(mapboxMap, (uiController, mapboxMap) -> {
assertNotNull(layer);
assertNull(layer.getFillPattern().getExpression());

// Set and Get
Expression expression = string(Expression.get("undefined"));
Expand Down
Loading

0 comments on commit 408a767

Please sign in to comment.