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 05213232e0e3..3225fee21a8b 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.5 + +* Converts `JointType` to enum. + ## 2.14.4 * Converts 'PlatformTileOverlay' 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 cc4297ceb06c..9c75e1d0d5e1 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 @@ -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; @@ -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, @@ -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()); 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 26720bf1ddc7..3fcc74f3c690 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 @@ -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. * @@ -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 patterns; public @NonNull List getPatterns() { @@ -1799,6 +1821,10 @@ public void setPoints(@NonNull List 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() { @@ -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; } @@ -2053,10 +2079,7 @@ ArrayList 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) patterns); Object points = __pigeon_list.get(6); @@ -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); } @@ -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); } 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 7b4fa3811260..551a1a74314e 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 @@ -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, ); } @@ -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; + } + // 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. + // 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. 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 d96319107c7a..fae122579b70 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 @@ -43,6 +43,12 @@ enum PlatformRendererType { latest, } +enum PlatformJointType { + mitered, + bevel, + round, +} + /// Pigeon representatation of a CameraPosition. class PlatformCameraPosition { PlatformCameraPosition({ @@ -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 patterns; List 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; @@ -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?)!.cast(), points: (result[6] as List?)!.cast(), startCap: result[7]!, @@ -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); } @@ -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); } 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 6f97587c9002..b303d46486b9 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 @@ -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({ @@ -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. 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 38c840c810de..64865310764c 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.4 +version: 2.14.5 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 a3406690d5f3..293899ac7c67 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 @@ -546,7 +546,7 @@ void main() { expected.consumeTapEvents, expected.color.value, expected.geodesic, - expected.jointType.value, + platformJointTypeFromJointType(expected.jointType), ]); expect(encoded.sublist(9), [ expected.visible,