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 7a1833338bf..cecdb79a6e4 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.11.1 + +* Fixes handling of Circle updates. + ## 2.11.0 * Converts additional platform calls to Pigeon. diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/CirclesController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/CirclesController.java index 2b52641caa0..c11696e30ee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/CirclesController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/CirclesController.java @@ -5,6 +5,7 @@ package io.flutter.plugins.googlemaps; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.model.Circle; import com.google.android.gms.maps.model.CircleOptions; @@ -14,8 +15,7 @@ import java.util.Map; class CirclesController { - - private final Map circleIdToController; + @VisibleForTesting final Map circleIdToController; private final Map googleMapsCircleIdToDartCircleId; private final MethodChannel methodChannel; private final float density; @@ -35,7 +35,9 @@ void setGoogleMap(GoogleMap googleMap) { void addJsonCircles(List circlesToAdd) { if (circlesToAdd != null) { for (Object circleToAdd : circlesToAdd) { - addJsonCircle(circleToAdd); + @SuppressWarnings("unchecked") + Map circleMap = (Map) circleToAdd; + addJsonCircle(circleMap); } } } @@ -47,8 +49,8 @@ void addCircles(@NonNull List circlesToAdd) { } void changeCircles(@NonNull List circlesToChange) { - for (Object circleToChange : circlesToChange) { - changeCircle(circleToChange); + for (Messages.PlatformCircle circleToChange : circlesToChange) { + changeJsonCircle(circleToChange.getJson()); } } @@ -75,7 +77,7 @@ boolean onCircleTap(String googleCircleId) { return false; } - private void addJsonCircle(Object circle) { + private void addJsonCircle(Map circle) { if (circle == null) { return; } @@ -92,7 +94,7 @@ private void addCircle(String circleId, CircleOptions circleOptions, boolean con googleMapsCircleIdToDartCircleId.put(circle.getId(), circleId); } - private void changeCircle(Object circle) { + private void changeJsonCircle(Map circle) { if (circle == null) { return; } @@ -103,9 +105,7 @@ private void changeCircle(Object circle) { } } - @SuppressWarnings("unchecked") - private static String getCircleId(Object circle) { - Map circleMap = (Map) circle; - return (String) circleMap.get("circleId"); + private static String getCircleId(Map circle) { + return (String) circle.get("circleId"); } } 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 71455b668e8..3ff4f542b0f 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 @@ -693,8 +693,7 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) { /** Set the options in the given object to marker options sink. */ static void interpretMarkerOptions( - Object o, MarkerOptionsSink sink, AssetManager assetManager, float density) { - final Map data = toMap(o); + Map data, MarkerOptionsSink sink, AssetManager assetManager, float density) { final Object alpha = data.get("alpha"); if (alpha != null) { sink.setAlpha(toFloat(alpha)); @@ -758,8 +757,7 @@ private static void interpretInfoWindowOptions( } } - static String interpretPolygonOptions(Object o, PolygonOptionsSink sink) { - final Map data = toMap(o); + static String interpretPolygonOptions(Map data, PolygonOptionsSink sink) { final Object consumeTapEvents = data.get("consumeTapEvents"); if (consumeTapEvents != null) { sink.setConsumeTapEvents(toBoolean(consumeTapEvents)); @@ -805,8 +803,7 @@ static String interpretPolygonOptions(Object o, PolygonOptionsSink sink) { } static String interpretPolylineOptions( - Object o, PolylineOptionsSink sink, AssetManager assetManager, float density) { - final Map data = toMap(o); + Map data, PolylineOptionsSink sink, AssetManager assetManager, float density) { final Object consumeTapEvents = data.get("consumeTapEvents"); if (consumeTapEvents != null) { sink.setConsumeTapEvents(toBoolean(consumeTapEvents)); @@ -859,8 +856,7 @@ static String interpretPolylineOptions( } } - static String interpretCircleOptions(Object o, CircleOptionsSink sink) { - final Map data = toMap(o); + static String interpretCircleOptions(Map data, CircleOptionsSink sink) { final Object consumeTapEvents = data.get("consumeTapEvents"); if (consumeTapEvents != null) { sink.setConsumeTapEvents(toBoolean(consumeTapEvents)); diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/MarkersController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/MarkersController.java index 5d870e88081..61b4120bf18 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/MarkersController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/MarkersController.java @@ -47,7 +47,9 @@ void setCollection(MarkerManager.Collection markerCollection) { void addJsonMarkers(List markersToAdd) { if (markersToAdd != null) { for (Object markerToAdd : markersToAdd) { - addJsonMarker(markerToAdd); + @SuppressWarnings("unchecked") + Map markerMap = (Map) markerToAdd; + addJsonMarker(markerMap); } } } @@ -186,7 +188,7 @@ public void onClusterItemRendered(MarkerBuilder markerBuilder, Marker marker) { } } - private void addJsonMarker(Object marker) { + private void addJsonMarker(Map marker) { if (marker == null) { return; } @@ -232,7 +234,7 @@ private void createControllerForMarker(String markerId, Marker marker, boolean c googleMapsMarkerIdToDartMarkerId.put(marker.getId(), markerId); } - private void changeJsonMarker(Object marker) { + private void changeJsonMarker(Map marker) { if (marker == null) { return; } @@ -264,15 +266,11 @@ private void changeJsonMarker(Object marker) { } } - @SuppressWarnings("unchecked") - private static String getMarkerId(Object marker) { - Map markerMap = (Map) marker; - return (String) markerMap.get("markerId"); + private static String getMarkerId(Map marker) { + return (String) marker.get("markerId"); } - @SuppressWarnings("unchecked") - private static String getClusterManagerId(Object marker) { - Map markerMap = (Map) marker; - return (String) markerMap.get("clusterManagerId"); + private static String getClusterManagerId(Map marker) { + return (String) marker.get("clusterManagerId"); } } 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 ba47fa72d2c..9415539b9e7 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 @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v20.0.1), do not edit directly. +// Autogenerated from Pigeon (v20.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package io.flutter.plugins.googlemaps; @@ -22,6 +22,8 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) @@ -102,6 +104,23 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformCameraUpdate() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformCameraUpdate that = (PlatformCameraUpdate) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { private @Nullable Object json; @@ -144,13 +163,13 @@ public static final class PlatformCircle { * The circle data, as JSON. This should only be set from Circle.toJson, and the native code * must intepret it according to the internal implementation details of that method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -160,12 +179,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformCircle() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformCircle that = (PlatformCircle) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -187,7 +223,7 @@ ArrayList toList() { static @NonNull PlatformCircle fromList(@NonNull ArrayList __pigeon_list) { PlatformCircle pigeonResult = new PlatformCircle(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -214,6 +250,23 @@ public void setIdentifier(@NonNull String setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformClusterManager() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformClusterManager that = (PlatformClusterManager) o; + return identifier.equals(that.identifier); + } + + @Override + public int hashCode() { + return Objects.hash(identifier); + } + public static final class Builder { private @Nullable String identifier; @@ -256,13 +309,13 @@ public static final class PlatformMarker { * The marker data, as JSON. This should only be set from Marker.toJson, and the native code * must intepret it according to the internal implementation details of that method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -272,12 +325,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformMarker() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformMarker that = (PlatformMarker) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -299,7 +369,7 @@ ArrayList toList() { static @NonNull PlatformMarker fromList(@NonNull ArrayList __pigeon_list) { PlatformMarker pigeonResult = new PlatformMarker(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -314,13 +384,13 @@ public static final class PlatformPolygon { * The polygon data, as JSON. This should only be set from Polygon.toJson, and the native code * must intepret it according to the internal implementation details of that method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -330,12 +400,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformPolygon() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformPolygon that = (PlatformPolygon) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -357,7 +444,7 @@ ArrayList toList() { static @NonNull PlatformPolygon fromList(@NonNull ArrayList __pigeon_list) { PlatformPolygon pigeonResult = new PlatformPolygon(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -372,13 +459,13 @@ public static final class PlatformPolyline { * The polyline data, as JSON. This should only be set from Polyline.toJson, and the native code * must intepret it according to the internal implementation details of that method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -388,12 +475,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformPolyline() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformPolyline that = (PlatformPolyline) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -415,7 +519,7 @@ ArrayList toList() { static @NonNull PlatformPolyline fromList(@NonNull ArrayList __pigeon_list) { PlatformPolyline pigeonResult = new PlatformPolyline(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -430,13 +534,13 @@ public static final class PlatformTileOverlay { * The tile overlay data, as JSON. This should only be set from TileOverlay.toJson, and the * native code must intepret it according to the internal implementation details of that method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -446,12 +550,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformTileOverlay() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformTileOverlay that = (PlatformTileOverlay) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -473,7 +594,7 @@ ArrayList toList() { static @NonNull PlatformTileOverlay fromList(@NonNull ArrayList __pigeon_list) { PlatformTileOverlay pigeonResult = new PlatformTileOverlay(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -513,6 +634,23 @@ public void setLongitude(@NonNull Double setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformLatLng() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformLatLng that = (PlatformLatLng) o; + return latitude.equals(that.latitude) && longitude.equals(that.longitude); + } + + @Override + public int hashCode() { + return Objects.hash(latitude, longitude); + } + public static final class Builder { private @Nullable Double latitude; @@ -592,6 +730,23 @@ public void setSouthwest(@NonNull PlatformLatLng setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformLatLngBounds() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformLatLngBounds that = (PlatformLatLngBounds) o; + return northeast.equals(that.northeast) && southwest.equals(that.southwest); + } + + @Override + public int hashCode() { + return Objects.hash(northeast, southwest); + } + public static final class Builder { private @Nullable PlatformLatLng northeast; @@ -697,6 +852,26 @@ public void setMarkerIds(@NonNull List setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformCluster() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformCluster that = (PlatformCluster) o; + return clusterManagerId.equals(that.clusterManagerId) + && position.equals(that.position) + && bounds.equals(that.bounds) + && markerIds.equals(that.markerIds); + } + + @Override + public int hashCode() { + return Objects.hash(clusterManagerId, position, bounds, markerIds); + } + public static final class Builder { private @Nullable String clusterManagerId; @@ -776,13 +951,13 @@ public static final class PlatformMapConfiguration { * and the native code must intepret it according to the internal implementation details of that * method. */ - private @NonNull Object json; + private @NonNull Map json; - public @NonNull Object getJson() { + public @NonNull Map getJson() { return json; } - public void setJson(@NonNull Object setterArg) { + public void setJson(@NonNull Map setterArg) { if (setterArg == null) { throw new IllegalStateException("Nonnull field \"json\" is null."); } @@ -792,12 +967,29 @@ public void setJson(@NonNull Object setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformMapConfiguration() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformMapConfiguration that = (PlatformMapConfiguration) o; + return json.equals(that.json); + } + + @Override + public int hashCode() { + return Objects.hash(json); + } + public static final class Builder { - private @Nullable Object json; + private @Nullable Map json; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Object setterArg) { + public @NonNull Builder setJson(@NonNull Map setterArg) { this.json = setterArg; return this; } @@ -819,7 +1011,7 @@ ArrayList toList() { static @NonNull PlatformMapConfiguration fromList(@NonNull ArrayList __pigeon_list) { PlatformMapConfiguration pigeonResult = new PlatformMapConfiguration(); Object json = __pigeon_list.get(0); - pigeonResult.setJson(json); + pigeonResult.setJson((Map) json); return pigeonResult; } } @@ -859,6 +1051,23 @@ public void setY(@NonNull Long setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformPoint() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformPoint that = (PlatformPoint) o; + return x.equals(that.x) && y.equals(that.y); + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + public static final class Builder { private @Nullable Long x; @@ -964,6 +1173,26 @@ public void setZIndex(@NonNull Double setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformTileLayer() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformTileLayer that = (PlatformTileLayer) o; + return visible.equals(that.visible) + && fadeIn.equals(that.fadeIn) + && transparency.equals(that.transparency) + && zIndex.equals(that.zIndex); + } + + @Override + public int hashCode() { + return Objects.hash(visible, fadeIn, transparency, zIndex); + } + public static final class Builder { private @Nullable Boolean visible; @@ -1067,6 +1296,23 @@ public void setMax(@NonNull Double setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PlatformZoomRange() {} + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PlatformZoomRange that = (PlatformZoomRange) o; + return min.equals(that.min) && max.equals(that.max); + } + + @Override + public int hashCode() { + return Objects.hash(min, max); + } + public static final class Builder { private @Nullable Double min; 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 a68e3e89ea8..8792386349f 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 @@ -35,7 +35,9 @@ void setGoogleMap(GoogleMap googleMap) { void addJsonPolygons(List polygonsToAdd) { if (polygonsToAdd != null) { for (Object polygonToAdd : polygonsToAdd) { - addJsonPolygon(polygonToAdd); + @SuppressWarnings("unchecked") + Map polygonMap = (Map) polygonToAdd; + addJsonPolygon(polygonMap); } } } @@ -75,7 +77,7 @@ boolean onPolygonTap(String googlePolygonId) { return false; } - private void addJsonPolygon(Object polygon) { + private void addJsonPolygon(Map polygon) { if (polygon == null) { return; } @@ -93,7 +95,7 @@ private void addPolygon( googleMapsPolygonIdToDartPolygonId.put(polygon.getId(), polygonId); } - private void changeJsonPolygon(Object polygon) { + private void changeJsonPolygon(Map polygon) { if (polygon == null) { return; } @@ -104,9 +106,7 @@ private void changeJsonPolygon(Object polygon) { } } - @SuppressWarnings("unchecked") - private static String getPolygonId(Object polygon) { - Map polygonMap = (Map) polygon; - return (String) polygonMap.get("polygonId"); + private static String getPolygonId(Map polygon) { + return (String) polygon.get("polygonId"); } } 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 043474d3dc3..ad849b7fb7d 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,7 +38,9 @@ void setGoogleMap(GoogleMap googleMap) { void addJsonPolylines(List polylinesToAdd) { if (polylinesToAdd != null) { for (Object polylineToAdd : polylinesToAdd) { - addJsonPolyline(polylineToAdd); + @SuppressWarnings("unchecked") + Map polylineMap = (Map) polylineToAdd; + addJsonPolyline(polylineMap); } } } @@ -78,7 +80,7 @@ boolean onPolylineTap(String googlePolylineId) { return false; } - private void addJsonPolyline(Object polyline) { + private void addJsonPolyline(Map polyline) { if (polyline == null) { return; } @@ -97,7 +99,7 @@ private void addPolyline( googleMapsPolylineIdToDartPolylineId.put(polyline.getId(), polylineId); } - private void changeJsonPolyline(Object polyline) { + private void changeJsonPolyline(Map polyline) { if (polyline == null) { return; } @@ -108,9 +110,7 @@ private void changeJsonPolyline(Object polyline) { } } - @SuppressWarnings("unchecked") - private static String getPolylineId(Object polyline) { - Map polylineMap = (Map) polyline; - return (String) polylineMap.get("polylineId"); + private static String getPolylineId(Map polyline) { + return (String) polyline.get("polylineId"); } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/CirclesControllerTest.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/CirclesControllerTest.java new file mode 100644 index 00000000000..2df310d13c3 --- /dev/null +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/CirclesControllerTest.java @@ -0,0 +1,78 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.googlemaps; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.android.gms.internal.maps.zzl; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.model.Circle; +import com.google.android.gms.maps.model.CircleOptions; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class CirclesControllerTest { + @Mock GoogleMap mockGoogleMap; + AutoCloseable mockCloseable; + + @Before + public void setUp() { + mockCloseable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + mockCloseable.close(); + } + + @Test + public void controller_changeCircles_updatesExistingCircle() { + final zzl z = mock(zzl.class); + final Circle circle = spy(new Circle(z)); + when(mockGoogleMap.addCircle(any(CircleOptions.class))).thenReturn(circle); + + final CirclesController controller = new CirclesController(null, 1.0f); + controller.setGoogleMap(mockGoogleMap); + + final String id = "a_circle"; + final Map circleJson = new HashMap<>(); + circleJson.put("circleId", id); + circleJson.put("consumeTapEvents", false); + circleJson.put("fillColor", 0); + circleJson.put("center", Arrays.asList(0.0, 0.0)); + circleJson.put("radius", 1.0); + circleJson.put("strokeColor", 0); + circleJson.put("strokeWidth", 1.0); + circleJson.put("visible", true); + circleJson.put("zIndex", 0); + + controller.addCircles( + Collections.singletonList( + new Messages.PlatformCircle.Builder().setJson(circleJson).build())); + // There should be exactly one circle. + Assert.assertEquals(1, controller.circleIdToController.size()); + + circleJson.put("consumeTapEvents", true); + controller.changeCircles( + Collections.singletonList( + new Messages.PlatformCircle.Builder().setJson(circleJson).build())); + // There should still only be one circle, and it should be updated. + Assert.assertEquals(1, controller.circleIdToController.size()); + verify(circle, times(1)).setClickable(true); + } +} 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 3b77fa91480..31991443bef 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 @@ -821,7 +821,10 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { } static PlatformCircle _platformCircleFromCircle(Circle circle) { - return PlatformCircle(json: circle.toJson()); + // 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 PlatformCircle(json: circle.toJson() as Map); } static PlatformClusterManager _platformClusterManagerFromClusterManager( @@ -831,20 +834,33 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { } static PlatformMarker _platformMarkerFromMarker(Marker marker) { - return PlatformMarker(json: marker.toJson()); + // 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 PlatformMarker(json: marker.toJson() as Map); } static PlatformPolygon _platformPolygonFromPolygon(Polygon polygon) { - return PlatformPolygon(json: polygon.toJson()); + // 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); } static PlatformPolyline _platformPolylineFromPolyline(Polyline polyline) { - return PlatformPolyline(json: polyline.toJson()); + // 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); } static PlatformTileOverlay _platformTileOverlayFromTileOverlay( TileOverlay tileOverlay) { - return PlatformTileOverlay(json: tileOverlay.toJson()); + // 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 PlatformTileOverlay( + json: tileOverlay.toJson() as Map); } } 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 23f7aa45c0a..d3a42977475 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 @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v20.0.1), do not edit directly. +// Autogenerated from Pigeon (v20.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -57,7 +57,7 @@ class PlatformCircle { /// The circle data, as JSON. This should only be set from /// Circle.toJson, and the native code must intepret it according to the /// internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -68,7 +68,7 @@ class PlatformCircle { static PlatformCircle decode(Object result) { result as List; return PlatformCircle( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } @@ -104,7 +104,7 @@ class PlatformMarker { /// The marker data, as JSON. This should only be set from /// Marker.toJson, and the native code must intepret it according to the /// internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -115,7 +115,7 @@ class PlatformMarker { static PlatformMarker decode(Object result) { result as List; return PlatformMarker( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } @@ -129,7 +129,7 @@ class PlatformPolygon { /// The polygon data, as JSON. This should only be set from /// Polygon.toJson, and the native code must intepret it according to the /// internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -140,7 +140,7 @@ class PlatformPolygon { static PlatformPolygon decode(Object result) { result as List; return PlatformPolygon( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } @@ -154,7 +154,7 @@ class PlatformPolyline { /// The polyline data, as JSON. This should only be set from /// Polyline.toJson, and the native code must intepret it according to the /// internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -165,7 +165,7 @@ class PlatformPolyline { static PlatformPolyline decode(Object result) { result as List; return PlatformPolyline( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } @@ -179,7 +179,7 @@ class PlatformTileOverlay { /// The tile overlay data, as JSON. This should only be set from /// TileOverlay.toJson, and the native code must intepret it according to the /// internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -190,7 +190,7 @@ class PlatformTileOverlay { static PlatformTileOverlay decode(Object result) { result as List; return PlatformTileOverlay( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } @@ -295,7 +295,7 @@ class PlatformMapConfiguration { /// The configuration options, as JSON. This should only be set from /// _jsonForMapConfiguration, and the native code must intepret it according /// to the internal implementation details of that method. - Object json; + Map json; Object encode() { return [ @@ -306,7 +306,7 @@ class PlatformMapConfiguration { static PlatformMapConfiguration decode(Object result) { result as List; return PlatformMapConfiguration( - json: result[0]!, + json: (result[0] as Map?)!.cast(), ); } } 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 3b78a5b180b..28d1c01a517 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 @@ -38,7 +38,7 @@ class PlatformCircle { /// internal implementation details of that method. // TODO(stuartmorgan): Replace this with structured data. This exists only to // allow incremental migration to Pigeon. - final Object json; + final Map json; } /// Pigeon equivalent of the ClusterManager class. @@ -57,7 +57,7 @@ class PlatformMarker { /// internal implementation details of that method. // TODO(stuartmorgan): Replace this with structured data. This exists only to // allow incremental migration to Pigeon. - final Object json; + final Map json; } /// Pigeon equivalent of the Polygon class. @@ -69,7 +69,7 @@ class PlatformPolygon { /// internal implementation details of that method. // TODO(stuartmorgan): Replace this with structured data. This exists only to // allow incremental migration to Pigeon. - final Object json; + final Map json; } /// Pigeon equivalent of the Polyline class. @@ -81,7 +81,7 @@ class PlatformPolyline { /// internal implementation details of that method. // TODO(stuartmorgan): Replace this with structured data. This exists only to // allow incremental migration to Pigeon. - final Object json; + final Map json; } /// Pigeon equivalent of the TileOverlay class. @@ -93,7 +93,7 @@ class PlatformTileOverlay { /// internal implementation details of that method. // TODO(stuartmorgan): Replace this with structured data. This exists only to // allow incremental migration to Pigeon. - final Object json; + final Map json; } /// Pigeon equivalent of LatLng. @@ -139,7 +139,7 @@ class PlatformMapConfiguration { /// 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 Object json; + final Map json; } /// Pigeon representation of an x,y coordinate. 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 e55b16a6b94..7a8f7a6cf4f 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.11.0 +version: 2.11.1 environment: sdk: ^3.4.0