Skip to content

Commit e93995a

Browse files
[google_maps_flutter_android] Convert JointType to an enum (flutter#7558)
Replace the raw integers used in `PlatformPolyline` to an enum. flutter#153718 (comment) ## 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. - [ ] 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 `///`). - [ ] 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 f408578 commit e93995a

File tree

8 files changed

+107
-19
lines changed

8 files changed

+107
-19
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.5
2+
3+
* Converts `JointType` to enum.
4+
15
## 2.14.4
26

37
* Converts 'PlatformTileOverlay' to pigeon.

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.android.gms.maps.model.Dash;
3030
import com.google.android.gms.maps.model.Dot;
3131
import com.google.android.gms.maps.model.Gap;
32+
import com.google.android.gms.maps.model.JointType;
3233
import com.google.android.gms.maps.model.LatLng;
3334
import com.google.android.gms.maps.model.LatLngBounds;
3435
import com.google.android.gms.maps.model.PatternItem;
@@ -703,6 +704,18 @@ static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonO
703704
return polygon.getPolygonId();
704705
}
705706

707+
static int jointTypeFromPigeon(Messages.PlatformJointType jointType) {
708+
switch (jointType) {
709+
case MITERED:
710+
return JointType.DEFAULT;
711+
case BEVEL:
712+
return JointType.BEVEL;
713+
case ROUND:
714+
return JointType.ROUND;
715+
}
716+
return JointType.DEFAULT;
717+
}
718+
706719
static String interpretPolylineOptions(
707720
Messages.PlatformPolyline polyline,
708721
PolylineOptionsSink sink,
@@ -713,7 +726,7 @@ static String interpretPolylineOptions(
713726
sink.setEndCap(toCap(polyline.getEndCap(), assetManager, density));
714727
sink.setStartCap(toCap(polyline.getStartCap(), assetManager, density));
715728
sink.setGeodesic(polyline.getGeodesic());
716-
sink.setJointType(polyline.getJointType().intValue());
729+
sink.setJointType(jointTypeFromPigeon(polyline.getJointType()));
717730
sink.setVisible(polyline.getVisible());
718731
sink.setWidth(polyline.getWidth());
719732
sink.setZIndex(polyline.getZIndex());

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ private PlatformRendererType(final int index) {
100100
}
101101
}
102102

103+
public enum PlatformJointType {
104+
MITERED(0),
105+
BEVEL(1),
106+
ROUND(2);
107+
108+
final int index;
109+
110+
private PlatformJointType(final int index) {
111+
this.index = index;
112+
}
113+
}
114+
103115
/**
104116
* Pigeon representatation of a CameraPosition.
105117
*
@@ -1760,19 +1772,29 @@ public void setGeodesic(@NonNull Boolean setterArg) {
17601772
this.geodesic = setterArg;
17611773
}
17621774

1763-
private @NonNull Long jointType;
1775+
/**
1776+
* The joint type as an integer. This must be a value corresponding to one of the values defined
1777+
* in the platform interface package's JointType enum. The integer values specified in this enum
1778+
* must match those used by the native SDK.
1779+
*/
1780+
private @NonNull PlatformJointType jointType;
17641781

1765-
public @NonNull Long getJointType() {
1782+
public @NonNull PlatformJointType getJointType() {
17661783
return jointType;
17671784
}
17681785

1769-
public void setJointType(@NonNull Long setterArg) {
1786+
public void setJointType(@NonNull PlatformJointType setterArg) {
17701787
if (setterArg == null) {
17711788
throw new IllegalStateException("Nonnull field \"jointType\" is null.");
17721789
}
17731790
this.jointType = setterArg;
17741791
}
17751792

1793+
/**
1794+
* The pattern data, as JSON. Each element in this list should be set only from
1795+
* PatternItem.toJson, and the native code must interpret it according to the internal
1796+
* implementation details of that method.
1797+
*/
17761798
private @NonNull List<Object> patterns;
17771799

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

1824+
/**
1825+
* The start and end cap data, as JSON. These should be set only from Cap.toJson, and the native
1826+
* code must interpret it according to the internal implementation details of that method.
1827+
*/
18021828
private @NonNull Object startCap;
18031829

18041830
public @NonNull Object getStartCap() {
@@ -1941,10 +1967,10 @@ public static final class Builder {
19411967
return this;
19421968
}
19431969

1944-
private @Nullable Long jointType;
1970+
private @Nullable PlatformJointType jointType;
19451971

19461972
@CanIgnoreReturnValue
1947-
public @NonNull Builder setJointType(@NonNull Long setterArg) {
1973+
public @NonNull Builder setJointType(@NonNull PlatformJointType setterArg) {
19481974
this.jointType = setterArg;
19491975
return this;
19501976
}
@@ -2053,10 +2079,7 @@ ArrayList<Object> toList() {
20532079
Object geodesic = __pigeon_list.get(3);
20542080
pigeonResult.setGeodesic((Boolean) geodesic);
20552081
Object jointType = __pigeon_list.get(4);
2056-
pigeonResult.setJointType(
2057-
(jointType == null)
2058-
? null
2059-
: ((jointType instanceof Integer) ? (Integer) jointType : (Long) jointType));
2082+
pigeonResult.setJointType((PlatformJointType) jointType);
20602083
Object patterns = __pigeon_list.get(5);
20612084
pigeonResult.setPatterns((List<Object>) patterns);
20622085
Object points = __pigeon_list.get(6);
@@ -4177,6 +4200,11 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
41774200
Object value = readValue(buffer);
41784201
return value == null ? null : PlatformRendererType.values()[(int) value];
41794202
}
4203+
case (byte) 153:
4204+
{
4205+
Object value = readValue(buffer);
4206+
return value == null ? null : PlatformJointType.values()[(int) value];
4207+
}
41804208
default:
41814209
return super.readValueOfType(type, buffer);
41824210
}
@@ -4256,6 +4284,9 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
42564284
} else if (value instanceof PlatformRendererType) {
42574285
stream.write(152);
42584286
writeValue(stream, value == null ? null : ((PlatformRendererType) value).index);
4287+
} else if (value instanceof PlatformJointType) {
4288+
stream.write(153);
4289+
writeValue(stream, value == null ? null : ((PlatformJointType) value).index);
42594290
} else {
42604291
super.writeValue(stream, value);
42614292
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ class GoogleMapsFlutterAndroid extends GoogleMapsFlutterPlatform {
783783
width: polyline.width,
784784
zIndex: polyline.zIndex,
785785
points: points,
786-
jointType: polyline.jointType.value,
786+
jointType: platformJointTypeFromJointType(polyline.jointType),
787787
patterns: pattern,
788788
);
789789
}
@@ -1146,6 +1146,26 @@ PlatformZoomRange? _platformZoomRangeFromMinMaxZoomPreferenceJson(
11461146
return PlatformZoomRange(min: minMaxZoom[0], max: minMaxZoom[1]);
11471147
}
11481148

1149+
/// Converts platform interface's JointType to Pigeon's PlatformJointType.
1150+
@visibleForTesting
1151+
PlatformJointType platformJointTypeFromJointType(JointType jointType) {
1152+
switch (jointType) {
1153+
case JointType.mitered:
1154+
return PlatformJointType.mitered;
1155+
case JointType.bevel:
1156+
return PlatformJointType.bevel;
1157+
case JointType.round:
1158+
return PlatformJointType.round;
1159+
}
1160+
// The enum comes from a different package, which could get a new value at
1161+
// any time, so provide a fallback that ensures this won't break when used
1162+
// with a version that contains new values. This is deliberately outside
1163+
// the switch rather than a `default` so that the linter will flag the
1164+
// switch as needing an update.
1165+
// ignore: dead_code
1166+
return PlatformJointType.mitered;
1167+
}
1168+
11491169
/// Update specification for a set of [TileOverlay]s.
11501170
// TODO(stuartmorgan): Fix the missing export of this class in the platform
11511171
// interface, and remove this copy.

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ enum PlatformRendererType {
4343
latest,
4444
}
4545

46+
enum PlatformJointType {
47+
mitered,
48+
bevel,
49+
round,
50+
}
51+
4652
/// Pigeon representatation of a CameraPosition.
4753
class PlatformCameraPosition {
4854
PlatformCameraPosition({
@@ -448,12 +454,15 @@ class PlatformPolyline {
448454

449455
bool geodesic;
450456

451-
int jointType;
457+
/// 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.
458+
PlatformJointType jointType;
452459

460+
/// 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.
453461
List<Object?> patterns;
454462

455463
List<PlatformLatLng?> points;
456464

465+
/// 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.
457466
Object startCap;
458467

459468
Object endCap;
@@ -488,7 +497,7 @@ class PlatformPolyline {
488497
consumesTapEvents: result[1]! as bool,
489498
color: result[2]! as int,
490499
geodesic: result[3]! as bool,
491-
jointType: result[4]! as int,
500+
jointType: result[4]! as PlatformJointType,
492501
patterns: (result[5] as List<Object?>?)!.cast<Object?>(),
493502
points: (result[6] as List<Object?>?)!.cast<PlatformLatLng?>(),
494503
startCap: result[7]!,
@@ -1081,6 +1090,9 @@ class _PigeonCodec extends StandardMessageCodec {
10811090
} else if (value is PlatformRendererType) {
10821091
buffer.putUint8(152);
10831092
writeValue(buffer, value.index);
1093+
} else if (value is PlatformJointType) {
1094+
buffer.putUint8(153);
1095+
writeValue(buffer, value.index);
10841096
} else {
10851097
super.writeValue(buffer, value);
10861098
}
@@ -1139,6 +1151,9 @@ class _PigeonCodec extends StandardMessageCodec {
11391151
case 152:
11401152
final int? value = readValue(buffer) as int?;
11411153
return value == null ? null : PlatformRendererType.values[value];
1154+
case 153:
1155+
final int? value = readValue(buffer) as int?;
1156+
return value == null ? null : PlatformJointType.values[value];
11421157
default:
11431158
return super.readValueOfType(type, buffer);
11441159
}

packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ class PlatformPolygon {
181181
final int zIndex;
182182
}
183183

184+
/// Join types for polyline joints.
185+
enum PlatformJointType {
186+
mitered,
187+
bevel,
188+
round,
189+
}
190+
184191
/// Pigeon equivalent of the Polyline class.
185192
class PlatformPolyline {
186193
PlatformPolyline({
@@ -203,10 +210,8 @@ class PlatformPolyline {
203210
final int color;
204211
final bool geodesic;
205212

206-
/// 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.
207-
// TODO(schectman): Convert field to enum.
208-
// https://github.com/flutter/flutter/issues/153718
209-
final int jointType;
213+
/// The joint type.
214+
final PlatformJointType jointType;
210215

211216
/// 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.
212217
// TODO(schectman): Convert field to structured data.

packages/google_maps_flutter/google_maps_flutter_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter_android
22
description: Android implementation of the google_maps_flutter plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.14.4
5+
version: 2.14.5
66

77
environment:
88
sdk: ^3.4.0

packages/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ void main() {
546546
expected.consumeTapEvents,
547547
expected.color.value,
548548
expected.geodesic,
549-
expected.jointType.value,
549+
platformJointTypeFromJointType(expected.jointType),
550550
]);
551551
expect(encoded.sublist(9), <Object?>[
552552
expected.visible,

0 commit comments

Comments
 (0)