Skip to content

Commit eff249d

Browse files
[google_maps_flutter] Semi-convert remaining Android host API calls to Pigeon (flutter#6980)
Does a "shallow" Pigeon conversion of the remaining host API calls in the Android implementation. All of the actual method calls are now Pigeon, but for the most part the data structures are not yet converted, and the Pigeon representations of the map objects are instead placeholders that currently just wrap the existing JSON serialization. This is done for a few reasons: - Keeps the incremental PR relatively small and easy to understand. - Quickly gets us to a state where any new APIs added will automatically use Pigeon, reducing further accumulation of technical debt. - Avoids duplication of handling code until flutter#150631 is resolved. As noted in a TODO added in this PR, almost all of the data structures that are passed in these methods are also passed through the PlatformView factory constructor, and Pigeon doesn't yet support using the Pigeon codec in non-Pigeon-generated code, so we would need to have both the structured *and* JSON handler for all of these objects if we converted them now. Future PRs will be able to incrementally convert each map object to a structured form. Converting the Flutter APIs (Java->Dart) will also be done in a follow-up, to limit the scope of this PR. Adds Dart unit tests for each method call, as they were previously not unit tested. Part of flutter#117907
1 parent 4ea5948 commit eff249d

23 files changed

+2429
-477
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.11.0
2+
3+
* Converts additional platform calls to Pigeon.
4+
15
## 2.10.0
26

37
* Converts some platform calls to Pigeon.

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.flutter.plugins.googlemaps;
66

7+
import androidx.annotation.NonNull;
78
import com.google.android.gms.maps.GoogleMap;
89
import com.google.android.gms.maps.model.Circle;
910
import com.google.android.gms.maps.model.CircleOptions;
@@ -31,31 +32,28 @@ void setGoogleMap(GoogleMap googleMap) {
3132
this.googleMap = googleMap;
3233
}
3334

34-
void addCircles(List<Object> circlesToAdd) {
35+
void addJsonCircles(List<Object> circlesToAdd) {
3536
if (circlesToAdd != null) {
3637
for (Object circleToAdd : circlesToAdd) {
37-
addCircle(circleToAdd);
38+
addJsonCircle(circleToAdd);
3839
}
3940
}
4041
}
4142

42-
void changeCircles(List<Object> circlesToChange) {
43-
if (circlesToChange != null) {
44-
for (Object circleToChange : circlesToChange) {
45-
changeCircle(circleToChange);
46-
}
43+
void addCircles(@NonNull List<Messages.PlatformCircle> circlesToAdd) {
44+
for (Messages.PlatformCircle circleToAdd : circlesToAdd) {
45+
addJsonCircle(circleToAdd.getJson());
4746
}
4847
}
4948

50-
void removeCircles(List<Object> circleIdsToRemove) {
51-
if (circleIdsToRemove == null) {
52-
return;
49+
void changeCircles(@NonNull List<Messages.PlatformCircle> circlesToChange) {
50+
for (Object circleToChange : circlesToChange) {
51+
changeCircle(circleToChange);
5352
}
54-
for (Object rawCircleId : circleIdsToRemove) {
55-
if (rawCircleId == null) {
56-
continue;
57-
}
58-
String circleId = (String) rawCircleId;
53+
}
54+
55+
void removeCircles(@NonNull List<String> circleIdsToRemove) {
56+
for (String circleId : circleIdsToRemove) {
5957
final CircleController circleController = circleIdToController.remove(circleId);
6058
if (circleController != null) {
6159
circleController.remove();
@@ -77,7 +75,7 @@ boolean onCircleTap(String googleCircleId) {
7775
return false;
7876
}
7977

80-
private void addCircle(Object circle) {
78+
private void addJsonCircle(Object circle) {
8179
if (circle == null) {
8280
return;
8381
}

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,25 @@ private void initListenersForClusterManager(
7979
}
8080

8181
/** Adds new ClusterManagers to the controller. */
82-
void addClusterManagers(@NonNull List<Object> clusterManagersToAdd) {
82+
void addJsonClusterManagers(@NonNull List<Object> clusterManagersToAdd) {
8383
for (Object clusterToAdd : clusterManagersToAdd) {
84-
addClusterManager(clusterToAdd);
84+
String clusterManagerId = getClusterManagerId(clusterToAdd);
85+
if (clusterManagerId == null) {
86+
throw new IllegalArgumentException("clusterManagerId was null");
87+
}
88+
addClusterManager(clusterManagerId);
8589
}
8690
}
8791

88-
/** Adds new ClusterManager to the controller. */
89-
void addClusterManager(Object clusterManagerData) {
90-
String clusterManagerId = getClusterManagerId(clusterManagerData);
91-
if (clusterManagerId == null) {
92-
throw new IllegalArgumentException("clusterManagerId was null");
92+
/** Adds new ClusterManagers to the controller. */
93+
void addClusterManagers(@NonNull List<Messages.PlatformClusterManager> clusterManagersToAdd) {
94+
for (Messages.PlatformClusterManager clusterToAdd : clusterManagersToAdd) {
95+
addClusterManager(clusterToAdd.getIdentifier());
9396
}
97+
}
98+
99+
/** Adds new ClusterManager to the controller. */
100+
void addClusterManager(String clusterManagerId) {
94101
ClusterManager<MarkerBuilder> clusterManager =
95102
new ClusterManager<MarkerBuilder>(context, googleMap, markerManager);
96103
ClusterRenderer<MarkerBuilder> clusterRenderer =
@@ -101,12 +108,8 @@ void addClusterManager(Object clusterManagerData) {
101108
}
102109

103110
/** Removes ClusterManagers by given cluster manager IDs from the controller. */
104-
public void removeClusterManagers(@NonNull List<Object> clusterManagerIdsToRemove) {
105-
for (Object rawClusterManagerId : clusterManagerIdsToRemove) {
106-
if (rawClusterManagerId == null) {
107-
continue;
108-
}
109-
String clusterManagerId = (String) rawClusterManagerId;
111+
public void removeClusterManagers(@NonNull List<String> clusterManagerIdsToRemove) {
112+
for (String clusterManagerId : clusterManagerIdsToRemove) {
110113
removeClusterManager(clusterManagerId);
111114
}
112115
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import android.graphics.BitmapFactory;
1010
import android.graphics.Point;
1111
import androidx.annotation.NonNull;
12+
import androidx.annotation.Nullable;
1213
import androidx.annotation.VisibleForTesting;
1314
import com.google.android.gms.maps.CameraUpdate;
1415
import com.google.android.gms.maps.CameraUpdateFactory;
16+
import com.google.android.gms.maps.MapsInitializer;
1517
import com.google.android.gms.maps.model.BitmapDescriptor;
1618
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
1719
import com.google.android.gms.maps.model.ButtCap;
@@ -357,6 +359,20 @@ private static int toInt(Object o) {
357359
return ((Number) o).intValue();
358360
}
359361

362+
static @Nullable MapsInitializer.Renderer toMapRendererType(
363+
@Nullable Messages.PlatformRendererType type) {
364+
if (type == null) {
365+
return null;
366+
}
367+
switch (type) {
368+
case LATEST:
369+
return MapsInitializer.Renderer.LATEST;
370+
case LEGACY:
371+
return MapsInitializer.Renderer.LEGACY;
372+
}
373+
return null;
374+
}
375+
360376
static Object cameraPositionToJson(CameraPosition position) {
361377
if (position == null) {
362378
return null;

0 commit comments

Comments
 (0)