diff --git a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md index 7c21eb45725..f94773f90d8 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.14.3 + +* Converts `PlatformPolygon` and `PlatformPolyline` to pigeon. + ## 2.14.2 * Bumps `com.android.tools.build:gradle` from 7.3.1 to 8.5.1. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index 91c039e2537..78b9f34a8cf 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -690,103 +690,36 @@ private static void interpretInfoWindowOptions( infoWindowAnchor.getDx().floatValue(), infoWindowAnchor.getDy().floatValue()); } - static String interpretPolygonOptions(Map data, PolygonOptionsSink sink) { - final Object consumeTapEvents = data.get("consumeTapEvents"); - if (consumeTapEvents != null) { - sink.setConsumeTapEvents(toBoolean(consumeTapEvents)); - } - final Object geodesic = data.get("geodesic"); - if (geodesic != null) { - sink.setGeodesic(toBoolean(geodesic)); - } - final Object visible = data.get("visible"); - if (visible != null) { - sink.setVisible(toBoolean(visible)); - } - final Object fillColor = data.get("fillColor"); - if (fillColor != null) { - sink.setFillColor(toInt(fillColor)); - } - final Object strokeColor = data.get("strokeColor"); - if (strokeColor != null) { - sink.setStrokeColor(toInt(strokeColor)); - } - final Object strokeWidth = data.get("strokeWidth"); - if (strokeWidth != null) { - sink.setStrokeWidth(toInt(strokeWidth)); - } - final Object zIndex = data.get("zIndex"); - if (zIndex != null) { - sink.setZIndex(toFloat(zIndex)); - } - final Object points = data.get("points"); - if (points != null) { - sink.setPoints(toPoints(points)); - } - final Object holes = data.get("holes"); - if (holes != null) { - sink.setHoles(toHoles(holes)); - } - final String polygonId = (String) data.get("polygonId"); - if (polygonId == null) { - throw new IllegalArgumentException("polygonId was null"); - } else { - return polygonId; - } + static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonOptionsSink sink) { + sink.setConsumeTapEvents(polygon.getConsumesTapEvents()); + sink.setGeodesic(polygon.getGeodesic()); + sink.setVisible(polygon.getVisible()); + sink.setFillColor(polygon.getFillColor().intValue()); + sink.setStrokeColor(polygon.getStrokeColor().intValue()); + sink.setStrokeWidth(polygon.getStrokeWidth()); + sink.setZIndex(polygon.getZIndex()); + sink.setPoints(pointsFromPigeon(polygon.getPoints())); + sink.setHoles(toHoles(polygon.getHoles())); + return polygon.getPolygonId(); } static String interpretPolylineOptions( - Map data, PolylineOptionsSink sink, AssetManager assetManager, float density) { - final Object consumeTapEvents = data.get("consumeTapEvents"); - if (consumeTapEvents != null) { - sink.setConsumeTapEvents(toBoolean(consumeTapEvents)); - } - final Object color = data.get("color"); - if (color != null) { - sink.setColor(toInt(color)); - } - final Object endCap = data.get("endCap"); - if (endCap != null) { - sink.setEndCap(toCap(endCap, assetManager, density)); - } - final Object geodesic = data.get("geodesic"); - if (geodesic != null) { - sink.setGeodesic(toBoolean(geodesic)); - } - final Object jointType = data.get("jointType"); - if (jointType != null) { - sink.setJointType(toInt(jointType)); - } - final Object startCap = data.get("startCap"); - if (startCap != null) { - sink.setStartCap(toCap(startCap, assetManager, density)); - } - final Object visible = data.get("visible"); - if (visible != null) { - sink.setVisible(toBoolean(visible)); - } - final Object width = data.get("width"); - if (width != null) { - sink.setWidth(toInt(width)); - } - final Object zIndex = data.get("zIndex"); - if (zIndex != null) { - sink.setZIndex(toFloat(zIndex)); - } - final Object points = data.get("points"); - if (points != null) { - sink.setPoints(toPoints(points)); - } - final Object pattern = data.get("pattern"); - if (pattern != null) { - sink.setPattern(toPattern(pattern)); - } - final String polylineId = (String) data.get("polylineId"); - if (polylineId == null) { - throw new IllegalArgumentException("polylineId was null"); - } else { - return polylineId; - } + Messages.PlatformPolyline polyline, + PolylineOptionsSink sink, + AssetManager assetManager, + float density) { + sink.setConsumeTapEvents(polyline.getConsumesTapEvents()); + sink.setColor(polyline.getColor().intValue()); + sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density)); + sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density)); + sink.setGeodesic(polyline.getGeodesic()); + sink.setJointType(polyline.getJointType().intValue()); + sink.setVisible(polyline.getVisible()); + sink.setWidth(polyline.getWidth()); + sink.setZIndex(polyline.getZIndex()); + sink.setPoints(pointsFromPigeon(polyline.getPoints())); + sink.setPattern(toPattern(polyline.getPatterns())); + return polyline.getPolylineId(); } static String interpretCircleOptions(Messages.PlatformCircle circle, CircleOptionsSink sink) { @@ -850,14 +783,11 @@ static String interpretHeatmapOptions(Map data, HeatmapOptionsSink si } } - @VisibleForTesting - static List toPoints(Object o) { - final List data = toList(o); + static List pointsFromPigeon(List data) { final List points = new ArrayList<>(data.size()); - for (Object rawPoint : data) { - final List point = toList(rawPoint); - points.add(new LatLng(toDouble(point.get(0)), toDouble(point.get(1)))); + for (Messages.PlatformLatLng rawPoint : data) { + points.add(new LatLng(rawPoint.getLatitude(), rawPoint.getLongitude())); } return points; } @@ -918,12 +848,11 @@ static Gradient toGradient(Object o) { return new Gradient(colors, startPoints, colorMapSize); } - private static List> toHoles(Object o) { - final List data = toList(o); + private static List> toHoles(List> data) { final List> holes = new ArrayList<>(data.size()); - for (Object rawHole : data) { - holes.add(toPoints(rawHole)); + for (List hole : data) { + holes.add(pointsFromPigeon(hole)); } return holes; } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java index 18a3b0e5452..7148e097b60 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java @@ -1052,6 +1052,7 @@ public void setFlat(@NonNull Boolean setterArg) { this.flat = setterArg; } + /** The icon as JSON data. */ private @NonNull Object icon; public @NonNull Object getIcon() { @@ -1380,21 +1381,134 @@ ArrayList toList() { *

Generated class from Pigeon that represents data sent in messages. */ public static final class PlatformPolygon { - /** - * The polygon data, as JSON. This should only be set from Polygon.toJson, and the native code - * must interpret it according to the internal implementation details of that method. - */ - private @NonNull Map json; + private @NonNull String polygonId; - public @NonNull Map getJson() { - return json; + public @NonNull String getPolygonId() { + return polygonId; } - public void setJson(@NonNull Map setterArg) { + public void setPolygonId(@NonNull String setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"json\" is null."); + throw new IllegalStateException("Nonnull field \"polygonId\" is null."); } - this.json = setterArg; + this.polygonId = setterArg; + } + + private @NonNull Boolean consumesTapEvents; + + public @NonNull Boolean getConsumesTapEvents() { + return consumesTapEvents; + } + + public void setConsumesTapEvents(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"consumesTapEvents\" is null."); + } + this.consumesTapEvents = setterArg; + } + + private @NonNull Long fillColor; + + public @NonNull Long getFillColor() { + return fillColor; + } + + public void setFillColor(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"fillColor\" is null."); + } + this.fillColor = setterArg; + } + + private @NonNull Boolean geodesic; + + public @NonNull Boolean getGeodesic() { + return geodesic; + } + + public void setGeodesic(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"geodesic\" is null."); + } + this.geodesic = setterArg; + } + + private @NonNull List points; + + public @NonNull List getPoints() { + return points; + } + + public void setPoints(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"points\" is null."); + } + this.points = setterArg; + } + + private @NonNull List> holes; + + public @NonNull List> getHoles() { + return holes; + } + + public void setHoles(@NonNull List> setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"holes\" is null."); + } + this.holes = setterArg; + } + + private @NonNull Boolean visible; + + public @NonNull Boolean getVisible() { + return visible; + } + + public void setVisible(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"visible\" is null."); + } + this.visible = setterArg; + } + + private @NonNull Long strokeColor; + + public @NonNull Long getStrokeColor() { + return strokeColor; + } + + public void setStrokeColor(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"strokeColor\" is null."); + } + this.strokeColor = setterArg; + } + + private @NonNull Long strokeWidth; + + public @NonNull Long getStrokeWidth() { + return strokeWidth; + } + + public void setStrokeWidth(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"strokeWidth\" is null."); + } + this.strokeWidth = setterArg; + } + + private @NonNull Long zIndex; + + public @NonNull Long getZIndex() { + return zIndex; + } + + public void setZIndex(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"zIndex\" is null."); + } + this.zIndex = setterArg; } /** Constructor is non-public to enforce null safety; use Builder. */ @@ -1409,42 +1523,181 @@ public boolean equals(Object o) { return false; } PlatformPolygon that = (PlatformPolygon) o; - return json.equals(that.json); + return polygonId.equals(that.polygonId) + && consumesTapEvents.equals(that.consumesTapEvents) + && fillColor.equals(that.fillColor) + && geodesic.equals(that.geodesic) + && points.equals(that.points) + && holes.equals(that.holes) + && visible.equals(that.visible) + && strokeColor.equals(that.strokeColor) + && strokeWidth.equals(that.strokeWidth) + && zIndex.equals(that.zIndex); } @Override public int hashCode() { - return Objects.hash(json); + return Objects.hash( + polygonId, + consumesTapEvents, + fillColor, + geodesic, + points, + holes, + visible, + strokeColor, + strokeWidth, + zIndex); } public static final class Builder { - private @Nullable Map json; + private @Nullable String polygonId; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Map setterArg) { - this.json = setterArg; + public @NonNull Builder setPolygonId(@NonNull String setterArg) { + this.polygonId = setterArg; + return this; + } + + private @Nullable Boolean consumesTapEvents; + + @CanIgnoreReturnValue + public @NonNull Builder setConsumesTapEvents(@NonNull Boolean setterArg) { + this.consumesTapEvents = setterArg; + return this; + } + + private @Nullable Long fillColor; + + @CanIgnoreReturnValue + public @NonNull Builder setFillColor(@NonNull Long setterArg) { + this.fillColor = setterArg; + return this; + } + + private @Nullable Boolean geodesic; + + @CanIgnoreReturnValue + public @NonNull Builder setGeodesic(@NonNull Boolean setterArg) { + this.geodesic = setterArg; + return this; + } + + private @Nullable List points; + + @CanIgnoreReturnValue + public @NonNull Builder setPoints(@NonNull List setterArg) { + this.points = setterArg; + return this; + } + + private @Nullable List> holes; + + @CanIgnoreReturnValue + public @NonNull Builder setHoles(@NonNull List> setterArg) { + this.holes = setterArg; + return this; + } + + private @Nullable Boolean visible; + + @CanIgnoreReturnValue + public @NonNull Builder setVisible(@NonNull Boolean setterArg) { + this.visible = setterArg; + return this; + } + + private @Nullable Long strokeColor; + + @CanIgnoreReturnValue + public @NonNull Builder setStrokeColor(@NonNull Long setterArg) { + this.strokeColor = setterArg; + return this; + } + + private @Nullable Long strokeWidth; + + @CanIgnoreReturnValue + public @NonNull Builder setStrokeWidth(@NonNull Long setterArg) { + this.strokeWidth = setterArg; + return this; + } + + private @Nullable Long zIndex; + + @CanIgnoreReturnValue + public @NonNull Builder setZIndex(@NonNull Long setterArg) { + this.zIndex = setterArg; return this; } public @NonNull PlatformPolygon build() { PlatformPolygon pigeonReturn = new PlatformPolygon(); - pigeonReturn.setJson(json); + pigeonReturn.setPolygonId(polygonId); + pigeonReturn.setConsumesTapEvents(consumesTapEvents); + pigeonReturn.setFillColor(fillColor); + pigeonReturn.setGeodesic(geodesic); + pigeonReturn.setPoints(points); + pigeonReturn.setHoles(holes); + pigeonReturn.setVisible(visible); + pigeonReturn.setStrokeColor(strokeColor); + pigeonReturn.setStrokeWidth(strokeWidth); + pigeonReturn.setZIndex(zIndex); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add(json); + ArrayList toListResult = new ArrayList(10); + toListResult.add(polygonId); + toListResult.add(consumesTapEvents); + toListResult.add(fillColor); + toListResult.add(geodesic); + toListResult.add(points); + toListResult.add(holes); + toListResult.add(visible); + toListResult.add(strokeColor); + toListResult.add(strokeWidth); + toListResult.add(zIndex); return toListResult; } static @NonNull PlatformPolygon fromList(@NonNull ArrayList __pigeon_list) { PlatformPolygon pigeonResult = new PlatformPolygon(); - Object json = __pigeon_list.get(0); - pigeonResult.setJson((Map) json); + Object polygonId = __pigeon_list.get(0); + pigeonResult.setPolygonId((String) polygonId); + Object consumesTapEvents = __pigeon_list.get(1); + pigeonResult.setConsumesTapEvents((Boolean) consumesTapEvents); + Object fillColor = __pigeon_list.get(2); + pigeonResult.setFillColor( + (fillColor == null) + ? null + : ((fillColor instanceof Integer) ? (Integer) fillColor : (Long) fillColor)); + Object geodesic = __pigeon_list.get(3); + pigeonResult.setGeodesic((Boolean) geodesic); + Object points = __pigeon_list.get(4); + pigeonResult.setPoints((List) points); + Object holes = __pigeon_list.get(5); + pigeonResult.setHoles((List>) holes); + Object visible = __pigeon_list.get(6); + pigeonResult.setVisible((Boolean) visible); + Object strokeColor = __pigeon_list.get(7); + pigeonResult.setStrokeColor( + (strokeColor == null) + ? null + : ((strokeColor instanceof Integer) ? (Integer) strokeColor : (Long) strokeColor)); + Object strokeWidth = __pigeon_list.get(8); + pigeonResult.setStrokeWidth( + (strokeWidth == null) + ? null + : ((strokeWidth instanceof Integer) ? (Integer) strokeWidth : (Long) strokeWidth)); + Object zIndex = __pigeon_list.get(9); + pigeonResult.setZIndex( + (zIndex == null) + ? null + : ((zIndex instanceof Integer) ? (Integer) zIndex : (Long) zIndex)); return pigeonResult; } } @@ -1455,21 +1708,160 @@ ArrayList toList() { *

Generated class from Pigeon that represents data sent in messages. */ public static final class PlatformPolyline { - /** - * The polyline data, as JSON. This should only be set from Polyline.toJson, and the native code - * must interpret it according to the internal implementation details of that method. - */ - private @NonNull Map json; + private @NonNull String polylineId; - public @NonNull Map getJson() { - return json; + public @NonNull String getPolylineId() { + return polylineId; } - public void setJson(@NonNull Map setterArg) { + public void setPolylineId(@NonNull String setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"json\" is null."); + throw new IllegalStateException("Nonnull field \"polylineId\" is null."); } - this.json = setterArg; + this.polylineId = setterArg; + } + + private @NonNull Boolean consumesTapEvents; + + public @NonNull Boolean getConsumesTapEvents() { + return consumesTapEvents; + } + + public void setConsumesTapEvents(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"consumesTapEvents\" is null."); + } + this.consumesTapEvents = setterArg; + } + + private @NonNull Long color; + + public @NonNull Long getColor() { + return color; + } + + public void setColor(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"color\" is null."); + } + this.color = setterArg; + } + + private @NonNull Boolean geodesic; + + public @NonNull Boolean getGeodesic() { + return geodesic; + } + + public void setGeodesic(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"geodesic\" is null."); + } + this.geodesic = setterArg; + } + + private @NonNull Long jointType; + + public @NonNull Long getJointType() { + return jointType; + } + + public void setJointType(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"jointType\" is null."); + } + this.jointType = setterArg; + } + + private @NonNull List patterns; + + public @NonNull List getPatterns() { + return patterns; + } + + public void setPatterns(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"patterns\" is null."); + } + this.patterns = setterArg; + } + + private @NonNull List points; + + public @NonNull List getPoints() { + return points; + } + + public void setPoints(@NonNull List setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"points\" is null."); + } + this.points = setterArg; + } + + private @NonNull Object startCap; + + public @NonNull Object getStartCap() { + return startCap; + } + + public void setStartCap(@NonNull Object setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"startCap\" is null."); + } + this.startCap = setterArg; + } + + private @NonNull Object endCap; + + public @NonNull Object getEndCap() { + return endCap; + } + + public void setEndCap(@NonNull Object setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"endCap\" is null."); + } + this.endCap = setterArg; + } + + private @NonNull Boolean visible; + + public @NonNull Boolean getVisible() { + return visible; + } + + public void setVisible(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"visible\" is null."); + } + this.visible = setterArg; + } + + private @NonNull Long width; + + public @NonNull Long getWidth() { + return width; + } + + public void setWidth(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"width\" is null."); + } + this.width = setterArg; + } + + private @NonNull Long zIndex; + + public @NonNull Long getZIndex() { + return zIndex; + } + + public void setZIndex(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"zIndex\" is null."); + } + this.zIndex = setterArg; } /** Constructor is non-public to enforce null safety; use Builder. */ @@ -1484,42 +1876,205 @@ public boolean equals(Object o) { return false; } PlatformPolyline that = (PlatformPolyline) o; - return json.equals(that.json); + return polylineId.equals(that.polylineId) + && consumesTapEvents.equals(that.consumesTapEvents) + && color.equals(that.color) + && geodesic.equals(that.geodesic) + && jointType.equals(that.jointType) + && patterns.equals(that.patterns) + && points.equals(that.points) + && startCap.equals(that.startCap) + && endCap.equals(that.endCap) + && visible.equals(that.visible) + && width.equals(that.width) + && zIndex.equals(that.zIndex); } @Override public int hashCode() { - return Objects.hash(json); + return Objects.hash( + polylineId, + consumesTapEvents, + color, + geodesic, + jointType, + patterns, + points, + startCap, + endCap, + visible, + width, + zIndex); } public static final class Builder { - private @Nullable Map json; + private @Nullable String polylineId; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Map setterArg) { - this.json = setterArg; + public @NonNull Builder setPolylineId(@NonNull String setterArg) { + this.polylineId = setterArg; + return this; + } + + private @Nullable Boolean consumesTapEvents; + + @CanIgnoreReturnValue + public @NonNull Builder setConsumesTapEvents(@NonNull Boolean setterArg) { + this.consumesTapEvents = setterArg; + return this; + } + + private @Nullable Long color; + + @CanIgnoreReturnValue + public @NonNull Builder setColor(@NonNull Long setterArg) { + this.color = setterArg; + return this; + } + + private @Nullable Boolean geodesic; + + @CanIgnoreReturnValue + public @NonNull Builder setGeodesic(@NonNull Boolean setterArg) { + this.geodesic = setterArg; + return this; + } + + private @Nullable Long jointType; + + @CanIgnoreReturnValue + public @NonNull Builder setJointType(@NonNull Long setterArg) { + this.jointType = setterArg; + return this; + } + + private @Nullable List patterns; + + @CanIgnoreReturnValue + public @NonNull Builder setPatterns(@NonNull List setterArg) { + this.patterns = setterArg; + return this; + } + + private @Nullable List points; + + @CanIgnoreReturnValue + public @NonNull Builder setPoints(@NonNull List setterArg) { + this.points = setterArg; + return this; + } + + private @Nullable Object startCap; + + @CanIgnoreReturnValue + public @NonNull Builder setStartCap(@NonNull Object setterArg) { + this.startCap = setterArg; + return this; + } + + private @Nullable Object endCap; + + @CanIgnoreReturnValue + public @NonNull Builder setEndCap(@NonNull Object setterArg) { + this.endCap = setterArg; + return this; + } + + private @Nullable Boolean visible; + + @CanIgnoreReturnValue + public @NonNull Builder setVisible(@NonNull Boolean setterArg) { + this.visible = setterArg; + return this; + } + + private @Nullable Long width; + + @CanIgnoreReturnValue + public @NonNull Builder setWidth(@NonNull Long setterArg) { + this.width = setterArg; + return this; + } + + private @Nullable Long zIndex; + + @CanIgnoreReturnValue + public @NonNull Builder setZIndex(@NonNull Long setterArg) { + this.zIndex = setterArg; return this; } public @NonNull PlatformPolyline build() { PlatformPolyline pigeonReturn = new PlatformPolyline(); - pigeonReturn.setJson(json); + pigeonReturn.setPolylineId(polylineId); + pigeonReturn.setConsumesTapEvents(consumesTapEvents); + pigeonReturn.setColor(color); + pigeonReturn.setGeodesic(geodesic); + pigeonReturn.setJointType(jointType); + pigeonReturn.setPatterns(patterns); + pigeonReturn.setPoints(points); + pigeonReturn.setStartCap(startCap); + pigeonReturn.setEndCap(endCap); + pigeonReturn.setVisible(visible); + pigeonReturn.setWidth(width); + pigeonReturn.setZIndex(zIndex); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add(json); + ArrayList toListResult = new ArrayList(12); + toListResult.add(polylineId); + toListResult.add(consumesTapEvents); + toListResult.add(color); + toListResult.add(geodesic); + toListResult.add(jointType); + toListResult.add(patterns); + toListResult.add(points); + toListResult.add(startCap); + toListResult.add(endCap); + toListResult.add(visible); + toListResult.add(width); + toListResult.add(zIndex); return toListResult; } static @NonNull PlatformPolyline fromList(@NonNull ArrayList __pigeon_list) { PlatformPolyline pigeonResult = new PlatformPolyline(); - Object json = __pigeon_list.get(0); - pigeonResult.setJson((Map) json); + Object polylineId = __pigeon_list.get(0); + pigeonResult.setPolylineId((String) polylineId); + Object consumesTapEvents = __pigeon_list.get(1); + pigeonResult.setConsumesTapEvents((Boolean) consumesTapEvents); + Object color = __pigeon_list.get(2); + pigeonResult.setColor( + (color == null) ? null : ((color instanceof Integer) ? (Integer) color : (Long) color)); + Object geodesic = __pigeon_list.get(3); + pigeonResult.setGeodesic((Boolean) geodesic); + Object jointType = __pigeon_list.get(4); + pigeonResult.setJointType( + (jointType == null) + ? null + : ((jointType instanceof Integer) ? (Integer) jointType : (Long) jointType)); + Object patterns = __pigeon_list.get(5); + pigeonResult.setPatterns((List) patterns); + Object points = __pigeon_list.get(6); + pigeonResult.setPoints((List) points); + Object startCap = __pigeon_list.get(7); + pigeonResult.setStartCap(startCap); + Object endCap = __pigeon_list.get(8); + pigeonResult.setEndCap(endCap); + Object visible = __pigeon_list.get(9); + pigeonResult.setVisible((Boolean) visible); + Object width = __pigeon_list.get(10); + pigeonResult.setWidth( + (width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width)); + Object zIndex = __pigeon_list.get(11); + pigeonResult.setZIndex( + (zIndex == null) + ? null + : ((zIndex instanceof Integer) ? (Integer) zIndex : (Long) zIndex)); return pigeonResult; } } @@ -3482,15 +4037,11 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { case (byte) 150: return PlatformZoomRange.fromList((ArrayList) readValue(buffer)); case (byte) 151: - // Manual edit to fix https://github.com/flutter/flutter/issues/150108 - // the way the generator will fix it once the PR lands. { Object value = readValue(buffer); return value == null ? null : PlatformMapType.values()[(int) value]; } case (byte) 152: - // Manual edit to fix https://github.com/flutter/flutter/issues/150108 - // the way the generator will fix it once the PR lands. { Object value = readValue(buffer); return value == null ? null : PlatformRendererType.values()[(int) value]; diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolygonsController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolygonsController.java index 57d7a6a5271..98a43477765 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolygonsController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolygonsController.java @@ -34,13 +34,13 @@ void setGoogleMap(GoogleMap googleMap) { void addPolygons(@NonNull List polygonsToAdd) { for (Messages.PlatformPolygon polygonToAdd : polygonsToAdd) { - addJsonPolygon(polygonToAdd.getJson()); + addPolygon(polygonToAdd); } } void changePolygons(@NonNull List polygonsToChange) { for (Messages.PlatformPolygon polygonToChange : polygonsToChange) { - changeJsonPolygon(polygonToChange.getJson()); + changePolygon(polygonToChange); } } @@ -67,10 +67,7 @@ boolean onPolygonTap(String googlePolygonId) { return false; } - private void addJsonPolygon(Map polygon) { - if (polygon == null) { - return; - } + private void addPolygon(@NonNull Messages.PlatformPolygon polygon) { PolygonBuilder polygonBuilder = new PolygonBuilder(density); String polygonId = Convert.interpretPolygonOptions(polygon, polygonBuilder); PolygonOptions options = polygonBuilder.build(); @@ -85,12 +82,8 @@ private void addPolygon( googleMapsPolygonIdToDartPolygonId.put(polygon.getId(), polygonId); } - private void changeJsonPolygon(Map polygon) { - if (polygon == null) { - return; - } - String polygonId = getPolygonId(polygon); - PolygonController polygonController = polygonIdToController.get(polygonId); + private void changePolygon(@NonNull Messages.PlatformPolygon polygon) { + PolygonController polygonController = polygonIdToController.get(polygon.getPolygonId()); if (polygonController != null) { Convert.interpretPolygonOptions(polygon, polygonController); } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolylinesController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolylinesController.java index 646f14c4497..65b53eb7e07 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolylinesController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/PolylinesController.java @@ -38,13 +38,13 @@ void setGoogleMap(GoogleMap googleMap) { void addPolylines(@NonNull List polylinesToAdd) { for (Messages.PlatformPolyline polylineToAdd : polylinesToAdd) { - addJsonPolyline(polylineToAdd.getJson()); + addPolyline(polylineToAdd); } } void changePolylines(@NonNull List polylinesToChange) { for (Messages.PlatformPolyline polylineToChange : polylinesToChange) { - changeJsonPolyline(polylineToChange.getJson()); + changePolyline(polylineToChange); } } @@ -71,10 +71,7 @@ boolean onPolylineTap(String googlePolylineId) { return false; } - private void addJsonPolyline(Map polyline) { - if (polyline == null) { - return; - } + private void addPolyline(@NonNull Messages.PlatformPolyline polyline) { PolylineBuilder polylineBuilder = new PolylineBuilder(density); String polylineId = Convert.interpretPolylineOptions(polyline, polylineBuilder, assetManager, density); @@ -90,11 +87,8 @@ private void addPolyline( googleMapsPolylineIdToDartPolylineId.put(polyline.getId(), polylineId); } - private void changeJsonPolyline(Map polyline) { - if (polyline == null) { - return; - } - String polylineId = getPolylineId(polyline); + private void changePolyline(@NonNull Messages.PlatformPolyline polyline) { + String polylineId = polyline.getPolylineId(); PolylineController polylineController = polylineIdToController.get(polylineId); if (polylineController != null) { Convert.interpretPolylineOptions(polyline, polylineController, assetManager, density); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ConvertTest.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ConvertTest.java index 1efab354086..a7331b89f79 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ConvertTest.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ConvertTest.java @@ -43,7 +43,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -86,15 +86,12 @@ public void tearDown() throws Exception { } @Test - public void ConvertToPointsConvertsThePointsWithFullPrecision() { + public void ConvertPointsFromPigeonConvertsThePointsWithFullPrecision() { double latitude = 43.03725568057; double longitude = -87.90466904649; - ArrayList point = new ArrayList<>(); - point.add(latitude); - point.add(longitude); - ArrayList> pointsList = new ArrayList<>(); - pointsList.add(point); - List latLngs = Convert.toPoints(pointsList); + Messages.PlatformLatLng platLng = + new Messages.PlatformLatLng.Builder().setLatitude(latitude).setLongitude(longitude).build(); + List latLngs = Convert.pointsFromPigeon(Collections.singletonList(platLng)); LatLng latLng = latLngs.get(0); Assert.assertEquals(latitude, latLng.latitude, 1e-15); Assert.assertEquals(longitude, latLng.longitude, 1e-15); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart index b7051ca679e..e42b57a9146 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart @@ -746,17 +746,46 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { } static PlatformPolygon _platformPolygonFromPolygon(Polygon polygon) { - // This cast is not ideal, but the Java code already assumes this format. - // See the TODOs at the top of this file and on the 'json' field in - // messages.dart. - return PlatformPolygon(json: polygon.toJson() as Map); + final List points = + polygon.points.map(_platformLatLngFromLatLng).toList(); + final List?> holes = + polygon.holes.map((List hole) { + return hole.map(_platformLatLngFromLatLng).toList(); + }).toList(); + return PlatformPolygon( + polygonId: polygon.polygonId.value, + fillColor: polygon.fillColor.value, + geodesic: polygon.geodesic, + consumesTapEvents: polygon.consumeTapEvents, + points: points, + holes: holes, + strokeColor: polygon.strokeColor.value, + strokeWidth: polygon.strokeWidth, + zIndex: polygon.zIndex, + visible: polygon.visible, + ); } static PlatformPolyline _platformPolylineFromPolyline(Polyline polyline) { - // This cast is not ideal, but the Java code already assumes this format. - // See the TODOs at the top of this file and on the 'json' field in - // messages.dart. - return PlatformPolyline(json: polyline.toJson() as Map); + final List points = + polyline.points.map(_platformLatLngFromLatLng).toList(); + final List pattern = polyline.patterns.map((PatternItem item) { + return item.toJson(); + }).toList(); + return PlatformPolyline( + polylineId: polyline.polylineId.value, + consumesTapEvents: polyline.consumeTapEvents, + color: polyline.color.value, + startCap: polyline.startCap.toJson(), + endCap: polyline.endCap.toJson(), + geodesic: polyline.geodesic, + visible: polyline.visible, + width: polyline.width, + zIndex: polyline.zIndex, + points: points, + jointType: polyline.jointType.value, + patterns: pattern, + ); } static PlatformTileOverlay _platformTileOverlayFromTileOverlay( diff --git a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart index d28a12eb1b5..d0c2d1537e6 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart @@ -301,6 +301,7 @@ class PlatformMarker { bool flat; + /// The icon as JSON data. Object icon; PlatformInfoWindow infoWindow; @@ -358,24 +359,66 @@ class PlatformMarker { /// Pigeon equivalent of the Polygon class. class PlatformPolygon { PlatformPolygon({ - required this.json, + required this.polygonId, + required this.consumesTapEvents, + required this.fillColor, + required this.geodesic, + required this.points, + required this.holes, + required this.visible, + required this.strokeColor, + required this.strokeWidth, + required this.zIndex, }); - /// The polygon data, as JSON. This should only be set from - /// Polygon.toJson, and the native code must interpret it according to the - /// internal implementation details of that method. - Map json; + String polygonId; + + bool consumesTapEvents; + + int fillColor; + + bool geodesic; + + List points; + + List?> holes; + + bool visible; + + int strokeColor; + + int strokeWidth; + + int zIndex; Object encode() { return [ - json, + polygonId, + consumesTapEvents, + fillColor, + geodesic, + points, + holes, + visible, + strokeColor, + strokeWidth, + zIndex, ]; } static PlatformPolygon decode(Object result) { result as List; return PlatformPolygon( - json: (result[0] as Map?)!.cast(), + polygonId: result[0]! as String, + consumesTapEvents: result[1]! as bool, + fillColor: result[2]! as int, + geodesic: result[3]! as bool, + points: (result[4] as List?)!.cast(), + holes: (result[5] as List?)!.cast?>(), + visible: result[6]! as bool, + strokeColor: result[7]! as int, + strokeWidth: result[8]! as int, + zIndex: result[9]! as int, ); } } @@ -383,24 +426,76 @@ class PlatformPolygon { /// Pigeon equivalent of the Polyline class. class PlatformPolyline { PlatformPolyline({ - required this.json, + required this.polylineId, + required this.consumesTapEvents, + required this.color, + required this.geodesic, + required this.jointType, + required this.patterns, + required this.points, + required this.startCap, + required this.endCap, + required this.visible, + required this.width, + required this.zIndex, }); - /// The polyline data, as JSON. This should only be set from - /// Polyline.toJson, and the native code must interpret it according to the - /// internal implementation details of that method. - Map json; + String polylineId; + + bool consumesTapEvents; + + int color; + + bool geodesic; + + int jointType; + + List patterns; + + List points; + + Object startCap; + + Object endCap; + + bool visible; + + int width; + + int zIndex; Object encode() { return [ - json, + polylineId, + consumesTapEvents, + color, + geodesic, + jointType, + patterns, + points, + startCap, + endCap, + visible, + width, + zIndex, ]; } static PlatformPolyline decode(Object result) { result as List; return PlatformPolyline( - json: (result[0] as Map?)!.cast(), + polylineId: result[0]! as String, + consumesTapEvents: result[1]! as bool, + color: result[2]! as int, + geodesic: result[3]! as bool, + jointType: result[4]! as int, + patterns: (result[5] as List?)!.cast(), + points: (result[6] as List?)!.cast(), + startCap: result[7]!, + endCap: result[8]!, + visible: result[9]! as bool, + width: result[10]! as int, + zIndex: result[11]! as int, ); } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart index 778aa17f547..52ce09a1430 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart @@ -156,26 +156,70 @@ class PlatformMarker { /// Pigeon equivalent of the Polygon class. class PlatformPolygon { - PlatformPolygon(this.json); + PlatformPolygon({ + required this.polygonId, + required this.consumesTapEvents, + required this.fillColor, + required this.geodesic, + required this.points, + required this.holes, + required this.visible, + required this.strokeColor, + required this.strokeWidth, + required this.zIndex, + }); - /// The polygon data, as JSON. This should only be set from - /// Polygon.toJson, and the native code must interpret it according to the - /// internal implementation details of that method. - // TODO(stuartmorgan): Replace this with structured data. This exists only to - // allow incremental migration to Pigeon. - final Map json; + final String polygonId; + final bool consumesTapEvents; + final int fillColor; + final bool geodesic; + final List points; + final List?> holes; + final bool visible; + final int strokeColor; + final int strokeWidth; + final int zIndex; } /// Pigeon equivalent of the Polyline class. class PlatformPolyline { - PlatformPolyline(this.json); + PlatformPolyline({ + required this.polylineId, + required this.consumesTapEvents, + required this.color, + required this.geodesic, + required this.jointType, + required this.patterns, + required this.points, + required this.startCap, + required this.endCap, + required this.visible, + required this.width, + required this.zIndex, + }); - /// The polyline data, as JSON. This should only be set from - /// Polyline.toJson, and the native code must interpret it according to the - /// internal implementation details of that method. - // TODO(stuartmorgan): Replace this with structured data. This exists only to - // allow incremental migration to Pigeon. - final Map json; + final String polylineId; + final bool consumesTapEvents; + final int color; + final bool geodesic; + + /// The joint type as an integer. This must be a value corresponding to one of the values defined in the platform interface package's JointType enum. The integer values specified in this enum must match those used by the native SDK. + // TODO(schectman): Convert field to enum. + // https://github.com/flutter/flutter/issues/153718 + final int jointType; + + /// The pattern data, as JSON. Each element in this list should be set only from PatternItem.toJson, and the native code must interpret it according to the internal implementation details of that method. + // TODO(schectman): Convert field to structured data. + final List patterns; + final List points; + + /// The start and end cap data, as JSON. These should be set only from Cap.toJson, and the native code must interpret it according to the internal implementation details of that method. + // TODO(schectman): Convert below two fields to structured data. + final Object startCap; + final Object endCap; + final bool visible; + final int width; + final int zIndex; } /// Pigeon equivalent of the Tile class. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml index 01d95416829..71aa5320b40 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_android description: Android implementation of the google_maps_flutter plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 2.14.2 +version: 2.14.3 environment: sdk: ^3.4.0 diff --git a/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart b/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart index 95a06148a3b..2c8769f4106 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart @@ -481,12 +481,41 @@ void main() { // Object one should be removed. expect(toRemove.length, 1); expect(toRemove.first, object1.polygonId.value); + void expectPolygon(PlatformPolygon actual, Polygon expected) { + final List encoded = actual.encode() as List; + expect(encoded.sublist(0, 4), [ + expected.polygonId.value, + expected.consumeTapEvents, + expected.fillColor.value, + expected.geodesic, + ]); + expect(actual.points.length, expected.points.length); + for (final (int i, PlatformLatLng? point) in actual.points.indexed) { + expect(point?.latitude, actual.points[i]?.latitude); + expect(point?.longitude, actual.points[i]?.longitude); + } + expect(actual.holes.length, expected.holes.length); + for (final (int i, List? hole) in actual.holes.indexed) { + final List expectedHole = expected.holes[i]; + for (final (int j, PlatformLatLng? point) in hole!.indexed) { + expect(point?.latitude, expectedHole[j].latitude); + expect(point?.longitude, expectedHole[j].longitude); + } + } + expect(encoded.sublist(6), [ + expected.visible, + expected.strokeColor.value, + expected.strokeWidth, + expected.zIndex, + ]); + } + // Object two should be changed. expect(toChange.length, 1); - expect(toChange.first?.json, object2new.toJson()); + expectPolygon(toChange.first!, object2new); // Object 3 should be added. expect(toAdd.length, 1); - expect(toAdd.first?.json, object3.toJson()); + expectPolygon(toAdd.first!, object3); }); test('updatePolylines passes expected arguments', () async { @@ -510,15 +539,40 @@ void main() { final List toChange = verification.captured[1] as List; final List toRemove = verification.captured[2] as List; + void expectPolyline(PlatformPolyline actual, Polyline expected) { + final List encoded = actual.encode() as List; + expect(encoded.sublist(0, 5), [ + expected.polylineId.value, + expected.consumeTapEvents, + expected.color.value, + expected.geodesic, + expected.jointType.value, + ]); + expect(encoded.sublist(9), [ + expected.visible, + expected.width, + expected.zIndex, + ]); + expect(actual.points.length, expected.points.length); + for (final (int i, PlatformLatLng? point) in actual.points.indexed) { + expect(point?.latitude, actual.points[i]?.latitude); + expect(point?.longitude, actual.points[i]?.longitude); + } + expect(actual.patterns.length, expected.patterns.length); + for (final (int i, Object? pattern) in actual.patterns.indexed) { + expect(pattern, expected.patterns[i].toJson()); + } + } + // Object one should be removed. expect(toRemove.length, 1); expect(toRemove.first, object1.polylineId.value); // Object two should be changed. expect(toChange.length, 1); - expect(toChange.first?.json, object2new.toJson()); + expectPolyline(toChange.first!, object2new); // Object 3 should be added. expect(toAdd.length, 1); - expect(toAdd.first?.json, object3.toJson()); + expectPolyline(toAdd.first!, object3); }); test('updateTileOverlays passes expected arguments', () async {