Skip to content

Commit 853c677

Browse files
[google_maps_flutter] Move Android inspector to Pigeon (#6958)
Converts the inspector API (only intended for use in integration tests) of the Android implementation to Pigeon. This is a small, simple API surface to start the migration with, allowing setting up the basic Pigeon plumbing without major changes. Part of flutter/flutter#117907
1 parent a958207 commit 853c677

File tree

16 files changed

+1994
-225
lines changed

16 files changed

+1994
-225
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.9.1
2+
3+
* Converts inspector interface platform calls to Pigeon.
4+
15
## 2.9.0
26

37
* Adds support for BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap`.

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,16 @@ private static String getClusterManagerId(Object clusterManagerData) {
169169
* Requests all current clusters from the algorithm of the requested ClusterManager and converts
170170
* them to result response.
171171
*/
172-
public void getClustersWithClusterManagerId(
173-
String clusterManagerId, MethodChannel.Result result) {
172+
public @NonNull Set<? extends Cluster<MarkerBuilder>> getClustersWithClusterManagerId(
173+
String clusterManagerId) {
174174
ClusterManager<MarkerBuilder> clusterManager = clusterManagerIdToManager.get(clusterManagerId);
175175
if (clusterManager == null) {
176-
result.error(
176+
throw new Messages.FlutterError(
177177
"Invalid clusterManagerId",
178178
"getClusters called with invalid clusterManagerId:" + clusterManagerId,
179179
null);
180-
return;
181180
}
182-
183-
final Set<? extends Cluster<MarkerBuilder>> clusters =
184-
clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
185-
result.success(Convert.clustersToJson(clusterManagerId, clusters));
181+
return clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
186182
}
187183

188184
@Override

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.HashMap;
3737
import java.util.List;
3838
import java.util.Map;
39-
import java.util.Set;
4039

4140
/** Conversions between JSON-like values and GoogleMaps data types. */
4241
class Convert {
@@ -377,6 +376,13 @@ static Object latLngBoundsToJson(LatLngBounds latLngBounds) {
377376
return arguments;
378377
}
379378

379+
static Messages.PlatformLatLngBounds latLngBoundsToPigeon(LatLngBounds latLngBounds) {
380+
return new Messages.PlatformLatLngBounds.Builder()
381+
.setNortheast(latLngToPigeon(latLngBounds.northeast))
382+
.setSouthwest(latLngToPigeon(latLngBounds.southwest))
383+
.build();
384+
}
385+
380386
static Object markerIdToJson(String markerId) {
381387
if (markerId == null) {
382388
return null;
@@ -431,13 +437,11 @@ static Object latLngToJson(LatLng latLng) {
431437
return Arrays.asList(latLng.latitude, latLng.longitude);
432438
}
433439

434-
static Object clustersToJson(
435-
String clusterManagerId, Set<? extends Cluster<MarkerBuilder>> clusters) {
436-
List<Object> data = new ArrayList<>(clusters.size());
437-
for (Cluster<MarkerBuilder> cluster : clusters) {
438-
data.add(clusterToJson(clusterManagerId, cluster));
439-
}
440-
return data;
440+
static Messages.PlatformLatLng latLngToPigeon(LatLng latLng) {
441+
return new Messages.PlatformLatLng.Builder()
442+
.setLat(latLng.latitude)
443+
.setLng(latLng.longitude)
444+
.build();
441445
}
442446

443447
static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> cluster) {
@@ -470,6 +474,27 @@ static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> clus
470474
return data;
471475
}
472476

477+
static Messages.PlatformCluster clusterToPigeon(
478+
String clusterManagerId, Cluster<MarkerBuilder> cluster) {
479+
int clusterSize = cluster.getSize();
480+
String[] markerIds = new String[clusterSize];
481+
MarkerBuilder[] markerBuilders = cluster.getItems().toArray(new MarkerBuilder[clusterSize]);
482+
483+
LatLngBounds.Builder latLngBoundsBuilder = LatLngBounds.builder();
484+
for (int i = 0; i < clusterSize; i++) {
485+
MarkerBuilder markerBuilder = markerBuilders[i];
486+
latLngBoundsBuilder.include(markerBuilder.getPosition());
487+
markerIds[i] = markerBuilder.markerId();
488+
}
489+
490+
return new Messages.PlatformCluster.Builder()
491+
.setClusterManagerId(clusterManagerId)
492+
.setPosition(latLngToPigeon(cluster.getPosition()))
493+
.setBounds(latLngBoundsToPigeon(latLngBoundsBuilder.build()))
494+
.setMarkerIds(Arrays.asList(markerIds))
495+
.build();
496+
}
497+
473498
static LatLng toLatLng(Object o) {
474499
final List<?> data = toList(o);
475500
return new LatLng(toDouble(data.get(0)), toDouble(data.get(1)));

0 commit comments

Comments
 (0)