Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_maps_flutter_android] Convert PlatformTileOverlay to Pigeon #7467

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.14.4

* Converts 'PlatformTileOverlay' to pigeon.

## 2.14.3

* Converts `PlatformPolygon` and `PlatformPolyline` to pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,29 +907,13 @@ private static Cap toCap(Object o, AssetManager assetManager, float density) {
}
}

static String interpretTileOverlayOptions(Map<String, ?> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2211,22 +2211,82 @@ ArrayList<Object> toList() {
* <p>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<String, Object> json;
private @NonNull String tileOverlayId;

public @NonNull Map<String, Object> getJson() {
return json;
public @NonNull String getTileOverlayId() {
return tileOverlayId;
}

public void setJson(@NonNull Map<String, Object> 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. */
Expand All @@ -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<String, Object> json;
private @Nullable String tileOverlayId;

@CanIgnoreReturnValue
public @NonNull Builder setJson(@NonNull Map<String, Object> 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<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<Object>(1);
toListResult.add(json);
ArrayList<Object> toListResult = new ArrayList<Object>(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<Object> __pigeon_list) {
PlatformTileOverlay pigeonResult = new PlatformTileOverlay();
Object json = __pigeon_list.get(0);
pigeonResult.setJson((Map<String, Object>) 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ void setGoogleMap(GoogleMap googleMap) {

void addTileOverlays(@NonNull List<Messages.PlatformTileOverlay> tileOverlaysToAdd) {
for (Messages.PlatformTileOverlay tileOverlayToAdd : tileOverlaysToAdd) {
@SuppressWarnings("unchecked")
final Map<String, ?> overlayJson = (Map<String, ?>) tileOverlayToAdd.getJson();
addJsonTileOverlay(overlayJson);
addTileOverlay(tileOverlayToAdd);
}
}

void changeTileOverlays(@NonNull List<Messages.PlatformTileOverlay> tileOverlaysToChange) {
for (Messages.PlatformTileOverlay tileOverlayToChange : tileOverlaysToChange) {
@SuppressWarnings("unchecked")
final Map<String, ?> overlayJson = (Map<String, ?>) tileOverlayToChange.getJson();
changeJsonTileOverlay(overlayJson);
changeTileOverlay(tileOverlayToChange);
}
}

Expand Down Expand Up @@ -79,13 +75,10 @@ TileOverlay getTileOverlay(String tileOverlayId) {
return tileOverlayController.getTileOverlay();
}

private void addJsonTileOverlay(Map<String, ?> 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);
Expand All @@ -95,14 +88,11 @@ private void addJsonTileOverlay(Map<String, ?> tileOverlayOptions) {
tileOverlayIdToController.put(tileOverlayId, tileOverlayController);
}

private void changeJsonTileOverlay(Map<String, ?> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object?>);
tileOverlayId: tileOverlay.tileOverlayId.value,
fadeIn: tileOverlay.fadeIn,
transparency: tileOverlay.transparency,
zIndex: tileOverlay.zIndex,
visible: tileOverlay.visible,
tileSize: tileOverlay.tileSize,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?, Object?> json;
String tileOverlayId;

bool fadeIn;

double transparency;

int zIndex;

bool visible;

int tileSize;

Object encode() {
return <Object?>[
json,
tileOverlayId,
fadeIn,
transparency,
zIndex,
visible,
tileSize,
];
}

static PlatformTileOverlay decode(Object result) {
result as List<Object?>;
return PlatformTileOverlay(
json: (result[0] as Map<Object?, Object?>?)!.cast<String?, Object?>(),
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,
);
}
}
Expand Down
Loading