Skip to content

Commit 1cf868f

Browse files
[google_maps_flutter_android] Convert PlatformTileOverlay to Pigeon (flutter#7467)
Convert `PlatformTileOverlay` from using a JSON implementation to a structured typesafe one. Addresses flutter#152927, which concerns `PlatformTileOverlay` as well as `PlatformTile`. However, as it appears `PlatformTile` is already typesafe, this should resolve the issue. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [ ] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
1 parent 25795a4 commit 1cf868f

File tree

9 files changed

+234
-82
lines changed

9 files changed

+234
-82
lines changed

packages/google_maps_flutter/google_maps_flutter_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.14.4
2+
3+
* Converts 'PlatformTileOverlay' to pigeon.
4+
15
## 2.14.3
26

37
* Converts `PlatformPolygon` and `PlatformPolyline` to pigeon.

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -907,29 +907,13 @@ private static Cap toCap(Object o, AssetManager assetManager, float density) {
907907
}
908908
}
909909

910-
static String interpretTileOverlayOptions(Map<String, ?> data, TileOverlaySink sink) {
911-
final Object fadeIn = data.get("fadeIn");
912-
if (fadeIn != null) {
913-
sink.setFadeIn(toBoolean(fadeIn));
914-
}
915-
final Object transparency = data.get("transparency");
916-
if (transparency != null) {
917-
sink.setTransparency(toFloat(transparency));
918-
}
919-
final Object zIndex = data.get("zIndex");
920-
if (zIndex != null) {
921-
sink.setZIndex(toFloat(zIndex));
922-
}
923-
final Object visible = data.get("visible");
924-
if (visible != null) {
925-
sink.setVisible(toBoolean(visible));
926-
}
927-
final String tileOverlayId = (String) data.get("tileOverlayId");
928-
if (tileOverlayId == null) {
929-
throw new IllegalArgumentException("tileOverlayId was null");
930-
} else {
931-
return tileOverlayId;
932-
}
910+
static String interpretTileOverlayOptions(
911+
Messages.PlatformTileOverlay tileOverlay, TileOverlaySink sink) {
912+
sink.setFadeIn(tileOverlay.getFadeIn());
913+
sink.setTransparency(tileOverlay.getTransparency().floatValue());
914+
sink.setZIndex(tileOverlay.getZIndex());
915+
sink.setVisible(tileOverlay.getVisible());
916+
return tileOverlay.getTileOverlayId();
933917
}
934918

935919
static Tile tileFromPigeon(Messages.PlatformTile tile) {

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java

Lines changed: 152 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,22 +2211,82 @@ ArrayList<Object> toList() {
22112211
* <p>Generated class from Pigeon that represents data sent in messages.
22122212
*/
22132213
public static final class PlatformTileOverlay {
2214-
/**
2215-
* The tile overlay data, as JSON. This should only be set from TileOverlay.toJson, and the
2216-
* native code must interpret it according to the internal implementation details of that
2217-
* method.
2218-
*/
2219-
private @NonNull Map<String, Object> json;
2214+
private @NonNull String tileOverlayId;
22202215

2221-
public @NonNull Map<String, Object> getJson() {
2222-
return json;
2216+
public @NonNull String getTileOverlayId() {
2217+
return tileOverlayId;
22232218
}
22242219

2225-
public void setJson(@NonNull Map<String, Object> setterArg) {
2220+
public void setTileOverlayId(@NonNull String setterArg) {
22262221
if (setterArg == null) {
2227-
throw new IllegalStateException("Nonnull field \"json\" is null.");
2222+
throw new IllegalStateException("Nonnull field \"tileOverlayId\" is null.");
22282223
}
2229-
this.json = setterArg;
2224+
this.tileOverlayId = setterArg;
2225+
}
2226+
2227+
private @NonNull Boolean fadeIn;
2228+
2229+
public @NonNull Boolean getFadeIn() {
2230+
return fadeIn;
2231+
}
2232+
2233+
public void setFadeIn(@NonNull Boolean setterArg) {
2234+
if (setterArg == null) {
2235+
throw new IllegalStateException("Nonnull field \"fadeIn\" is null.");
2236+
}
2237+
this.fadeIn = setterArg;
2238+
}
2239+
2240+
private @NonNull Double transparency;
2241+
2242+
public @NonNull Double getTransparency() {
2243+
return transparency;
2244+
}
2245+
2246+
public void setTransparency(@NonNull Double setterArg) {
2247+
if (setterArg == null) {
2248+
throw new IllegalStateException("Nonnull field \"transparency\" is null.");
2249+
}
2250+
this.transparency = setterArg;
2251+
}
2252+
2253+
private @NonNull Long zIndex;
2254+
2255+
public @NonNull Long getZIndex() {
2256+
return zIndex;
2257+
}
2258+
2259+
public void setZIndex(@NonNull Long setterArg) {
2260+
if (setterArg == null) {
2261+
throw new IllegalStateException("Nonnull field \"zIndex\" is null.");
2262+
}
2263+
this.zIndex = setterArg;
2264+
}
2265+
2266+
private @NonNull Boolean visible;
2267+
2268+
public @NonNull Boolean getVisible() {
2269+
return visible;
2270+
}
2271+
2272+
public void setVisible(@NonNull Boolean setterArg) {
2273+
if (setterArg == null) {
2274+
throw new IllegalStateException("Nonnull field \"visible\" is null.");
2275+
}
2276+
this.visible = setterArg;
2277+
}
2278+
2279+
private @NonNull Long tileSize;
2280+
2281+
public @NonNull Long getTileSize() {
2282+
return tileSize;
2283+
}
2284+
2285+
public void setTileSize(@NonNull Long setterArg) {
2286+
if (setterArg == null) {
2287+
throw new IllegalStateException("Nonnull field \"tileSize\" is null.");
2288+
}
2289+
this.tileSize = setterArg;
22302290
}
22312291

22322292
/** Constructor is non-public to enforce null safety; use Builder. */
@@ -2241,42 +2301,113 @@ public boolean equals(Object o) {
22412301
return false;
22422302
}
22432303
PlatformTileOverlay that = (PlatformTileOverlay) o;
2244-
return json.equals(that.json);
2304+
return tileOverlayId.equals(that.tileOverlayId)
2305+
&& fadeIn.equals(that.fadeIn)
2306+
&& transparency.equals(that.transparency)
2307+
&& zIndex.equals(that.zIndex)
2308+
&& visible.equals(that.visible)
2309+
&& tileSize.equals(that.tileSize);
22452310
}
22462311

22472312
@Override
22482313
public int hashCode() {
2249-
return Objects.hash(json);
2314+
return Objects.hash(tileOverlayId, fadeIn, transparency, zIndex, visible, tileSize);
22502315
}
22512316

22522317
public static final class Builder {
22532318

2254-
private @Nullable Map<String, Object> json;
2319+
private @Nullable String tileOverlayId;
22552320

22562321
@CanIgnoreReturnValue
2257-
public @NonNull Builder setJson(@NonNull Map<String, Object> setterArg) {
2258-
this.json = setterArg;
2322+
public @NonNull Builder setTileOverlayId(@NonNull String setterArg) {
2323+
this.tileOverlayId = setterArg;
2324+
return this;
2325+
}
2326+
2327+
private @Nullable Boolean fadeIn;
2328+
2329+
@CanIgnoreReturnValue
2330+
public @NonNull Builder setFadeIn(@NonNull Boolean setterArg) {
2331+
this.fadeIn = setterArg;
2332+
return this;
2333+
}
2334+
2335+
private @Nullable Double transparency;
2336+
2337+
@CanIgnoreReturnValue
2338+
public @NonNull Builder setTransparency(@NonNull Double setterArg) {
2339+
this.transparency = setterArg;
2340+
return this;
2341+
}
2342+
2343+
private @Nullable Long zIndex;
2344+
2345+
@CanIgnoreReturnValue
2346+
public @NonNull Builder setZIndex(@NonNull Long setterArg) {
2347+
this.zIndex = setterArg;
2348+
return this;
2349+
}
2350+
2351+
private @Nullable Boolean visible;
2352+
2353+
@CanIgnoreReturnValue
2354+
public @NonNull Builder setVisible(@NonNull Boolean setterArg) {
2355+
this.visible = setterArg;
2356+
return this;
2357+
}
2358+
2359+
private @Nullable Long tileSize;
2360+
2361+
@CanIgnoreReturnValue
2362+
public @NonNull Builder setTileSize(@NonNull Long setterArg) {
2363+
this.tileSize = setterArg;
22592364
return this;
22602365
}
22612366

22622367
public @NonNull PlatformTileOverlay build() {
22632368
PlatformTileOverlay pigeonReturn = new PlatformTileOverlay();
2264-
pigeonReturn.setJson(json);
2369+
pigeonReturn.setTileOverlayId(tileOverlayId);
2370+
pigeonReturn.setFadeIn(fadeIn);
2371+
pigeonReturn.setTransparency(transparency);
2372+
pigeonReturn.setZIndex(zIndex);
2373+
pigeonReturn.setVisible(visible);
2374+
pigeonReturn.setTileSize(tileSize);
22652375
return pigeonReturn;
22662376
}
22672377
}
22682378

22692379
@NonNull
22702380
ArrayList<Object> toList() {
2271-
ArrayList<Object> toListResult = new ArrayList<Object>(1);
2272-
toListResult.add(json);
2381+
ArrayList<Object> toListResult = new ArrayList<Object>(6);
2382+
toListResult.add(tileOverlayId);
2383+
toListResult.add(fadeIn);
2384+
toListResult.add(transparency);
2385+
toListResult.add(zIndex);
2386+
toListResult.add(visible);
2387+
toListResult.add(tileSize);
22732388
return toListResult;
22742389
}
22752390

22762391
static @NonNull PlatformTileOverlay fromList(@NonNull ArrayList<Object> __pigeon_list) {
22772392
PlatformTileOverlay pigeonResult = new PlatformTileOverlay();
2278-
Object json = __pigeon_list.get(0);
2279-
pigeonResult.setJson((Map<String, Object>) json);
2393+
Object tileOverlayId = __pigeon_list.get(0);
2394+
pigeonResult.setTileOverlayId((String) tileOverlayId);
2395+
Object fadeIn = __pigeon_list.get(1);
2396+
pigeonResult.setFadeIn((Boolean) fadeIn);
2397+
Object transparency = __pigeon_list.get(2);
2398+
pigeonResult.setTransparency((Double) transparency);
2399+
Object zIndex = __pigeon_list.get(3);
2400+
pigeonResult.setZIndex(
2401+
(zIndex == null)
2402+
? null
2403+
: ((zIndex instanceof Integer) ? (Integer) zIndex : (Long) zIndex));
2404+
Object visible = __pigeon_list.get(4);
2405+
pigeonResult.setVisible((Boolean) visible);
2406+
Object tileSize = __pigeon_list.get(5);
2407+
pigeonResult.setTileSize(
2408+
(tileSize == null)
2409+
? null
2410+
: ((tileSize instanceof Integer) ? (Integer) tileSize : (Long) tileSize));
22802411
return pigeonResult;
22812412
}
22822413
}

packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/TileOverlaysController.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ void setGoogleMap(GoogleMap googleMap) {
3131

3232
void addTileOverlays(@NonNull List<Messages.PlatformTileOverlay> tileOverlaysToAdd) {
3333
for (Messages.PlatformTileOverlay tileOverlayToAdd : tileOverlaysToAdd) {
34-
@SuppressWarnings("unchecked")
35-
final Map<String, ?> overlayJson = (Map<String, ?>) tileOverlayToAdd.getJson();
36-
addJsonTileOverlay(overlayJson);
34+
addTileOverlay(tileOverlayToAdd);
3735
}
3836
}
3937

4038
void changeTileOverlays(@NonNull List<Messages.PlatformTileOverlay> tileOverlaysToChange) {
4139
for (Messages.PlatformTileOverlay tileOverlayToChange : tileOverlaysToChange) {
42-
@SuppressWarnings("unchecked")
43-
final Map<String, ?> overlayJson = (Map<String, ?>) tileOverlayToChange.getJson();
44-
changeJsonTileOverlay(overlayJson);
40+
changeTileOverlay(tileOverlayToChange);
4541
}
4642
}
4743

@@ -79,13 +75,10 @@ TileOverlay getTileOverlay(String tileOverlayId) {
7975
return tileOverlayController.getTileOverlay();
8076
}
8177

82-
private void addJsonTileOverlay(Map<String, ?> tileOverlayOptions) {
83-
if (tileOverlayOptions == null) {
84-
return;
85-
}
78+
private void addTileOverlay(@NonNull Messages.PlatformTileOverlay platformTileOverlay) {
8679
TileOverlayBuilder tileOverlayOptionsBuilder = new TileOverlayBuilder();
8780
String tileOverlayId =
88-
Convert.interpretTileOverlayOptions(tileOverlayOptions, tileOverlayOptionsBuilder);
81+
Convert.interpretTileOverlayOptions(platformTileOverlay, tileOverlayOptionsBuilder);
8982
TileProviderController tileProviderController =
9083
new TileProviderController(flutterApi, tileOverlayId);
9184
tileOverlayOptionsBuilder.setTileProvider(tileProviderController);
@@ -95,14 +88,11 @@ private void addJsonTileOverlay(Map<String, ?> tileOverlayOptions) {
9588
tileOverlayIdToController.put(tileOverlayId, tileOverlayController);
9689
}
9790

98-
private void changeJsonTileOverlay(Map<String, ?> tileOverlayOptions) {
99-
if (tileOverlayOptions == null) {
100-
return;
101-
}
102-
String tileOverlayId = getTileOverlayId(tileOverlayOptions);
91+
private void changeTileOverlay(@NonNull Messages.PlatformTileOverlay platformTileOverlay) {
92+
String tileOverlayId = platformTileOverlay.getTileOverlayId();
10393
TileOverlayController tileOverlayController = tileOverlayIdToController.get(tileOverlayId);
10494
if (tileOverlayController != null) {
105-
Convert.interpretTileOverlayOptions(tileOverlayOptions, tileOverlayController);
95+
Convert.interpretTileOverlayOptions(platformTileOverlay, tileOverlayController);
10696
}
10797
}
10898

packages/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,14 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
790790

791791
static PlatformTileOverlay _platformTileOverlayFromTileOverlay(
792792
TileOverlay tileOverlay) {
793-
// This cast is not ideal, but the Java code already assumes this format.
794-
// See the TODOs at the top of this file and on the 'json' field in
795-
// messages.dart.
796793
return PlatformTileOverlay(
797-
json: tileOverlay.toJson() as Map<String, Object?>);
794+
tileOverlayId: tileOverlay.tileOverlayId.value,
795+
fadeIn: tileOverlay.fadeIn,
796+
transparency: tileOverlay.transparency,
797+
zIndex: tileOverlay.zIndex,
798+
visible: tileOverlay.visible,
799+
tileSize: tileOverlay.tileSize,
800+
);
798801
}
799802
}
800803

packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,24 +535,46 @@ class PlatformTile {
535535
/// Pigeon equivalent of the TileOverlay class.
536536
class PlatformTileOverlay {
537537
PlatformTileOverlay({
538-
required this.json,
538+
required this.tileOverlayId,
539+
required this.fadeIn,
540+
required this.transparency,
541+
required this.zIndex,
542+
required this.visible,
543+
required this.tileSize,
539544
});
540545

541-
/// The tile overlay data, as JSON. This should only be set from
542-
/// TileOverlay.toJson, and the native code must interpret it according to the
543-
/// internal implementation details of that method.
544-
Map<String?, Object?> json;
546+
String tileOverlayId;
547+
548+
bool fadeIn;
549+
550+
double transparency;
551+
552+
int zIndex;
553+
554+
bool visible;
555+
556+
int tileSize;
545557

546558
Object encode() {
547559
return <Object?>[
548-
json,
560+
tileOverlayId,
561+
fadeIn,
562+
transparency,
563+
zIndex,
564+
visible,
565+
tileSize,
549566
];
550567
}
551568

552569
static PlatformTileOverlay decode(Object result) {
553570
result as List<Object?>;
554571
return PlatformTileOverlay(
555-
json: (result[0] as Map<Object?, Object?>?)!.cast<String?, Object?>(),
572+
tileOverlayId: result[0]! as String,
573+
fadeIn: result[1]! as bool,
574+
transparency: result[2]! as double,
575+
zIndex: result[3]! as int,
576+
visible: result[4]! as bool,
577+
tileSize: result[5]! as int,
556578
);
557579
}
558580
}

0 commit comments

Comments
 (0)