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 f94773f90d8..05213232e0e 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.4 + +* Converts 'PlatformTileOverlay' to pigeon. + ## 2.14.3 * Converts `PlatformPolygon` and `PlatformPolyline` to pigeon. 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 78b9f34a8cf..cc4297ceb06 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 @@ -907,29 +907,13 @@ private static Cap toCap(Object o, AssetManager assetManager, float density) { } } - static String interpretTileOverlayOptions(Map data, TileOverlaySink sink) { - final Object fadeIn = data.get("fadeIn"); - if (fadeIn != null) { - sink.setFadeIn(toBoolean(fadeIn)); - } - final Object transparency = data.get("transparency"); - if (transparency != null) { - sink.setTransparency(toFloat(transparency)); - } - final Object zIndex = data.get("zIndex"); - if (zIndex != null) { - sink.setZIndex(toFloat(zIndex)); - } - final Object visible = data.get("visible"); - if (visible != null) { - sink.setVisible(toBoolean(visible)); - } - final String tileOverlayId = (String) data.get("tileOverlayId"); - if (tileOverlayId == null) { - throw new IllegalArgumentException("tileOverlayId was null"); - } else { - return tileOverlayId; - } + static String interpretTileOverlayOptions( + Messages.PlatformTileOverlay tileOverlay, TileOverlaySink sink) { + sink.setFadeIn(tileOverlay.getFadeIn()); + sink.setTransparency(tileOverlay.getTransparency().floatValue()); + sink.setZIndex(tileOverlay.getZIndex()); + sink.setVisible(tileOverlay.getVisible()); + return tileOverlay.getTileOverlayId(); } static Tile tileFromPigeon(Messages.PlatformTile tile) { 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 7148e097b60..26720bf1ddc 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 @@ -2211,22 +2211,82 @@ ArrayList toList() { *

Generated class from Pigeon that represents data sent in messages. */ public static final class PlatformTileOverlay { - /** - * The tile overlay data, as JSON. This should only be set from TileOverlay.toJson, and the - * native code must interpret it according to the internal implementation details of that - * method. - */ - private @NonNull Map json; + private @NonNull String tileOverlayId; - public @NonNull Map getJson() { - return json; + public @NonNull String getTileOverlayId() { + return tileOverlayId; } - public void setJson(@NonNull Map setterArg) { + public void setTileOverlayId(@NonNull String setterArg) { if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"json\" is null."); + throw new IllegalStateException("Nonnull field \"tileOverlayId\" is null."); } - this.json = setterArg; + this.tileOverlayId = setterArg; + } + + private @NonNull Boolean fadeIn; + + public @NonNull Boolean getFadeIn() { + return fadeIn; + } + + public void setFadeIn(@NonNull Boolean setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"fadeIn\" is null."); + } + this.fadeIn = setterArg; + } + + private @NonNull Double transparency; + + public @NonNull Double getTransparency() { + return transparency; + } + + public void setTransparency(@NonNull Double setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"transparency\" is null."); + } + this.transparency = 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; + } + + 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 tileSize; + + public @NonNull Long getTileSize() { + return tileSize; + } + + public void setTileSize(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"tileSize\" is null."); + } + this.tileSize = setterArg; } /** Constructor is non-public to enforce null safety; use Builder. */ @@ -2241,42 +2301,113 @@ public boolean equals(Object o) { return false; } PlatformTileOverlay that = (PlatformTileOverlay) o; - return json.equals(that.json); + return tileOverlayId.equals(that.tileOverlayId) + && fadeIn.equals(that.fadeIn) + && transparency.equals(that.transparency) + && zIndex.equals(that.zIndex) + && visible.equals(that.visible) + && tileSize.equals(that.tileSize); } @Override public int hashCode() { - return Objects.hash(json); + return Objects.hash(tileOverlayId, fadeIn, transparency, zIndex, visible, tileSize); } public static final class Builder { - private @Nullable Map json; + private @Nullable String tileOverlayId; @CanIgnoreReturnValue - public @NonNull Builder setJson(@NonNull Map setterArg) { - this.json = setterArg; + public @NonNull Builder setTileOverlayId(@NonNull String setterArg) { + this.tileOverlayId = setterArg; + return this; + } + + private @Nullable Boolean fadeIn; + + @CanIgnoreReturnValue + public @NonNull Builder setFadeIn(@NonNull Boolean setterArg) { + this.fadeIn = setterArg; + return this; + } + + private @Nullable Double transparency; + + @CanIgnoreReturnValue + public @NonNull Builder setTransparency(@NonNull Double setterArg) { + this.transparency = setterArg; + return this; + } + + private @Nullable Long zIndex; + + @CanIgnoreReturnValue + public @NonNull Builder setZIndex(@NonNull Long setterArg) { + this.zIndex = setterArg; + return this; + } + + private @Nullable Boolean visible; + + @CanIgnoreReturnValue + public @NonNull Builder setVisible(@NonNull Boolean setterArg) { + this.visible = setterArg; + return this; + } + + private @Nullable Long tileSize; + + @CanIgnoreReturnValue + public @NonNull Builder setTileSize(@NonNull Long setterArg) { + this.tileSize = setterArg; return this; } public @NonNull PlatformTileOverlay build() { PlatformTileOverlay pigeonReturn = new PlatformTileOverlay(); - pigeonReturn.setJson(json); + pigeonReturn.setTileOverlayId(tileOverlayId); + pigeonReturn.setFadeIn(fadeIn); + pigeonReturn.setTransparency(transparency); + pigeonReturn.setZIndex(zIndex); + pigeonReturn.setVisible(visible); + pigeonReturn.setTileSize(tileSize); return pigeonReturn; } } @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add(json); + ArrayList toListResult = new ArrayList(6); + toListResult.add(tileOverlayId); + toListResult.add(fadeIn); + toListResult.add(transparency); + toListResult.add(zIndex); + toListResult.add(visible); + toListResult.add(tileSize); return toListResult; } static @NonNull PlatformTileOverlay fromList(@NonNull ArrayList __pigeon_list) { PlatformTileOverlay pigeonResult = new PlatformTileOverlay(); - Object json = __pigeon_list.get(0); - pigeonResult.setJson((Map) json); + Object tileOverlayId = __pigeon_list.get(0); + pigeonResult.setTileOverlayId((String) tileOverlayId); + Object fadeIn = __pigeon_list.get(1); + pigeonResult.setFadeIn((Boolean) fadeIn); + Object transparency = __pigeon_list.get(2); + pigeonResult.setTransparency((Double) transparency); + Object zIndex = __pigeon_list.get(3); + pigeonResult.setZIndex( + (zIndex == null) + ? null + : ((zIndex instanceof Integer) ? (Integer) zIndex : (Long) zIndex)); + Object visible = __pigeon_list.get(4); + pigeonResult.setVisible((Boolean) visible); + Object tileSize = __pigeon_list.get(5); + pigeonResult.setTileSize( + (tileSize == null) + ? null + : ((tileSize instanceof Integer) ? (Integer) tileSize : (Long) tileSize)); return pigeonResult; } } diff --git a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/TileOverlaysController.java b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/TileOverlaysController.java index fcc5c212d8d..2ee8dcac857 100644 --- a/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/TileOverlaysController.java +++ b/packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/TileOverlaysController.java @@ -31,17 +31,13 @@ void setGoogleMap(GoogleMap googleMap) { void addTileOverlays(@NonNull List tileOverlaysToAdd) { for (Messages.PlatformTileOverlay tileOverlayToAdd : tileOverlaysToAdd) { - @SuppressWarnings("unchecked") - final Map overlayJson = (Map) tileOverlayToAdd.getJson(); - addJsonTileOverlay(overlayJson); + addTileOverlay(tileOverlayToAdd); } } void changeTileOverlays(@NonNull List tileOverlaysToChange) { for (Messages.PlatformTileOverlay tileOverlayToChange : tileOverlaysToChange) { - @SuppressWarnings("unchecked") - final Map overlayJson = (Map) tileOverlayToChange.getJson(); - changeJsonTileOverlay(overlayJson); + changeTileOverlay(tileOverlayToChange); } } @@ -79,13 +75,10 @@ TileOverlay getTileOverlay(String tileOverlayId) { return tileOverlayController.getTileOverlay(); } - private void addJsonTileOverlay(Map tileOverlayOptions) { - if (tileOverlayOptions == null) { - return; - } + private void addTileOverlay(@NonNull Messages.PlatformTileOverlay platformTileOverlay) { TileOverlayBuilder tileOverlayOptionsBuilder = new TileOverlayBuilder(); String tileOverlayId = - Convert.interpretTileOverlayOptions(tileOverlayOptions, tileOverlayOptionsBuilder); + Convert.interpretTileOverlayOptions(platformTileOverlay, tileOverlayOptionsBuilder); TileProviderController tileProviderController = new TileProviderController(flutterApi, tileOverlayId); tileOverlayOptionsBuilder.setTileProvider(tileProviderController); @@ -95,14 +88,11 @@ private void addJsonTileOverlay(Map tileOverlayOptions) { tileOverlayIdToController.put(tileOverlayId, tileOverlayController); } - private void changeJsonTileOverlay(Map tileOverlayOptions) { - if (tileOverlayOptions == null) { - return; - } - String tileOverlayId = getTileOverlayId(tileOverlayOptions); + private void changeTileOverlay(@NonNull Messages.PlatformTileOverlay platformTileOverlay) { + String tileOverlayId = platformTileOverlay.getTileOverlayId(); TileOverlayController tileOverlayController = tileOverlayIdToController.get(tileOverlayId); if (tileOverlayController != null) { - Convert.interpretTileOverlayOptions(tileOverlayOptions, tileOverlayController); + Convert.interpretTileOverlayOptions(platformTileOverlay, tileOverlayController); } } 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 e42b57a9146..7b4fa381126 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 @@ -790,11 +790,14 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform { static PlatformTileOverlay _platformTileOverlayFromTileOverlay( TileOverlay tileOverlay) { - // 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); + tileOverlayId: tileOverlay.tileOverlayId.value, + fadeIn: tileOverlay.fadeIn, + transparency: tileOverlay.transparency, + zIndex: tileOverlay.zIndex, + visible: tileOverlay.visible, + tileSize: tileOverlay.tileSize, + ); } } 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 d0c2d1537e6..d96319107c7 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 @@ -535,24 +535,46 @@ class PlatformTile { /// Pigeon equivalent of the TileOverlay class. class PlatformTileOverlay { PlatformTileOverlay({ - required this.json, + required this.tileOverlayId, + required this.fadeIn, + required this.transparency, + required this.zIndex, + required this.visible, + required this.tileSize, }); - /// The tile overlay data, as JSON. This should only be set from - /// TileOverlay.toJson, and the native code must interpret it according to the - /// internal implementation details of that method. - Map json; + String tileOverlayId; + + bool fadeIn; + + double transparency; + + int zIndex; + + bool visible; + + int tileSize; Object encode() { return [ - json, + tileOverlayId, + fadeIn, + transparency, + zIndex, + visible, + tileSize, ]; } static PlatformTileOverlay decode(Object result) { result as List; return PlatformTileOverlay( - json: (result[0] as Map?)!.cast(), + tileOverlayId: result[0]! as String, + fadeIn: result[1]! as bool, + transparency: result[2]! as double, + zIndex: result[3]! as int, + visible: result[4]! as bool, + tileSize: result[5]! 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 52ce09a1430..6f97587c900 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 @@ -233,14 +233,21 @@ class PlatformTile { /// Pigeon equivalent of the TileOverlay class. class PlatformTileOverlay { - PlatformTileOverlay(this.json); + PlatformTileOverlay({ + required this.tileOverlayId, + required this.fadeIn, + required this.transparency, + required this.zIndex, + required this.visible, + required this.tileSize, + }); - /// The tile overlay data, as JSON. This should only be set from - /// TileOverlay.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 tileOverlayId; + final bool fadeIn; + final double transparency; + final int zIndex; + final bool visible; + final int tileSize; } /// Pigeon equivalent of Flutter's EdgeInsets. 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 71aa5320b40..38c840c810d 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.3 +version: 2.14.4 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 2c8769f4106..a3406690d5f 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 @@ -601,15 +601,26 @@ void main() { final List toChange = verification.captured[1] as List; final List toRemove = verification.captured[2] as List; + void expectTileOverlay(PlatformTileOverlay? actual, TileOverlay expected) { + expect(actual?.encode(), [ + expected.tileOverlayId.value, + expected.fadeIn, + expected.transparency, + expected.zIndex, + expected.visible, + expected.tileSize, + ]); + } + // Object one should be removed. expect(toRemove.length, 1); expect(toRemove.first, object1.tileOverlayId.value); // Object two should be changed. expect(toChange.length, 1); - expect(toChange.first?.json, object2new.toJson()); + expectTileOverlay(toChange.first, object2new); // Object 3 should be added. expect(toAdd.length, 1); - expect(toAdd.first?.json, object3.toJson()); + expectTileOverlay(toAdd.first, object3); }); test('markers send drag event to correct streams', () async {