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 JointType to an enum #7558

Merged
merged 11 commits into from
Sep 4, 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.5

* Converts `JointType` to enum.

## 2.14.4

* Converts 'PlatformTileOverlay' to pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.android.gms.maps.model.Dash;
import com.google.android.gms.maps.model.Dot;
import com.google.android.gms.maps.model.Gap;
import com.google.android.gms.maps.model.JointType;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.PatternItem;
Expand Down Expand Up @@ -703,6 +704,18 @@ static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonO
return polygon.getPolygonId();
}

static int jointTypeFromPigeon(Messages.PlatformJointType jointType) {
switch (jointType) {
case MITERED:
return JointType.DEFAULT;
case BEVEL:
return JointType.BEVEL;
case ROUND:
return JointType.ROUND;
}
return JointType.DEFAULT;
}

static String interpretPolylineOptions(
Messages.PlatformPolyline polyline,
PolylineOptionsSink sink,
Expand All @@ -713,7 +726,7 @@ static String interpretPolylineOptions(
sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density));
sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density));
sink.setGeodesic(polyline.getGeodesic());
sink.setJointType(polyline.getJointType().intValue());
sink.setJointType(jointTypeFromPigeon(polyline.getJointType()));
sink.setVisible(polyline.getVisible());
sink.setWidth(polyline.getWidth());
sink.setZIndex(polyline.getZIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ private PlatformRendererType(final int index) {
}
}

public enum PlatformJointType {
MITERED(0),
BEVEL(1),
ROUND(2);

final int index;

private PlatformJointType(final int index) {
this.index = index;
}
}

/**
* Pigeon representatation of a CameraPosition.
*
Expand Down Expand Up @@ -1760,19 +1772,29 @@ public void setGeodesic(@NonNull Boolean setterArg) {
this.geodesic = setterArg;
}

private @NonNull Long jointType;
/**
* 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.
*/
private @NonNull PlatformJointType jointType;

public @NonNull Long getJointType() {
public @NonNull PlatformJointType getJointType() {
return jointType;
}

public void setJointType(@NonNull Long setterArg) {
public void setJointType(@NonNull PlatformJointType setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"jointType\" is null.");
}
this.jointType = setterArg;
}

/**
* 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.
*/
private @NonNull List<Object> patterns;

public @NonNull List<Object> getPatterns() {
Expand All @@ -1799,6 +1821,10 @@ public void setPoints(@NonNull List<PlatformLatLng> setterArg) {
this.points = setterArg;
}

/**
* 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.
*/
private @NonNull Object startCap;

public @NonNull Object getStartCap() {
Expand Down Expand Up @@ -1941,10 +1967,10 @@ public static final class Builder {
return this;
}

private @Nullable Long jointType;
private @Nullable PlatformJointType jointType;

@CanIgnoreReturnValue
public @NonNull Builder setJointType(@NonNull Long setterArg) {
public @NonNull Builder setJointType(@NonNull PlatformJointType setterArg) {
this.jointType = setterArg;
return this;
}
Expand Down Expand Up @@ -2053,10 +2079,7 @@ ArrayList<Object> toList() {
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));
pigeonResult.setJointType((PlatformJointType) jointType);
Object patterns = __pigeon_list.get(5);
pigeonResult.setPatterns((List<Object>) patterns);
Object points = __pigeon_list.get(6);
Expand Down Expand Up @@ -4177,6 +4200,11 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
Object value = readValue(buffer);
return value == null ? null : PlatformRendererType.values()[(int) value];
}
case (byte) 153:
{
Object value = readValue(buffer);
return value == null ? null : PlatformJointType.values()[(int) value];
}
default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -4256,6 +4284,9 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
} else if (value instanceof PlatformRendererType) {
stream.write(152);
writeValue(stream, value == null ? null : ((PlatformRendererType) value).index);
} else if (value instanceof PlatformJointType) {
stream.write(153);
writeValue(stream, value == null ? null : ((PlatformJointType) value).index);
} else {
super.writeValue(stream, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
width: polyline.width,
zIndex: polyline.zIndex,
points: points,
jointType: polyline.jointType.value,
jointType: platformJointTypeFromJointType(polyline.jointType),
patterns: pattern,
);
}
Expand Down Expand Up @@ -1146,6 +1146,26 @@ PlatformZoomRange? _platformZoomRangeFromMinMaxZoomPreferenceJson(
return PlatformZoomRange(min: minMaxZoom[0], max: minMaxZoom[1]);
}

/// Converts platform interface's JointType to Pigeon's PlatformJointType.
@visibleForTesting
PlatformJointType platformJointTypeFromJointType(JointType jointType) {
switch (jointType) {
case JointType.mitered:
return PlatformJointType.mitered;
case JointType.bevel:
return PlatformJointType.bevel;
case JointType.round:
return PlatformJointType.round;
}
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is helpful.

// ignore: dead_code
return PlatformJointType.mitered;
}

/// Update specification for a set of [TileOverlay]s.
// TODO(stuartmorgan): Fix the missing export of this class in the platform
// interface, and remove this copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ enum PlatformRendererType {
latest,
}

enum PlatformJointType {
mitered,
bevel,
round,
}

/// Pigeon representatation of a CameraPosition.
class PlatformCameraPosition {
PlatformCameraPosition({
Expand Down Expand Up @@ -448,12 +454,15 @@ class PlatformPolyline {

bool geodesic;

int jointType;
/// 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.
PlatformJointType 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.
List<Object?> patterns;

List<PlatformLatLng?> 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.
Object startCap;

Object endCap;
Expand Down Expand Up @@ -488,7 +497,7 @@ class PlatformPolyline {
consumesTapEvents: result[1]! as bool,
color: result[2]! as int,
geodesic: result[3]! as bool,
jointType: result[4]! as int,
jointType: result[4]! as PlatformJointType,
patterns: (result[5] as List<Object?>?)!.cast<Object?>(),
points: (result[6] as List<Object?>?)!.cast<PlatformLatLng?>(),
startCap: result[7]!,
Expand Down Expand Up @@ -1081,6 +1090,9 @@ class _PigeonCodec extends StandardMessageCodec {
} else if (value is PlatformRendererType) {
buffer.putUint8(152);
writeValue(buffer, value.index);
} else if (value is PlatformJointType) {
buffer.putUint8(153);
writeValue(buffer, value.index);
} else {
super.writeValue(buffer, value);
}
Expand Down Expand Up @@ -1139,6 +1151,9 @@ class _PigeonCodec extends StandardMessageCodec {
case 152:
final int? value = readValue(buffer) as int?;
return value == null ? null : PlatformRendererType.values[value];
case 153:
final int? value = readValue(buffer) as int?;
return value == null ? null : PlatformJointType.values[value];
default:
return super.readValueOfType(type, buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ class PlatformPolygon {
final int zIndex;
}

/// Join types for polyline joints.
enum PlatformJointType {
mitered,
bevel,
round,
}

/// Pigeon equivalent of the Polyline class.
class PlatformPolyline {
PlatformPolyline({
Expand All @@ -203,10 +210,8 @@ class PlatformPolyline {
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 joint type.
final PlatformJointType 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.4
version: 2.14.5

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void main() {
expected.consumeTapEvents,
expected.color.value,
expected.geodesic,
expected.jointType.value,
platformJointTypeFromJointType(expected.jointType),
]);
expect(encoded.sublist(9), <Object?>[
expected.visible,
Expand Down