Skip to content

Commit

Permalink
[google_maps_flutter] Move Android inspector to Pigeon (flutter#6958)
Browse files Browse the repository at this point in the history
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#117907
  • Loading branch information
stuartmorgan authored Jun 20, 2024
1 parent a958207 commit 853c677
Show file tree
Hide file tree
Showing 16 changed files with 1,994 additions and 225 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.9.1

* Converts inspector interface platform calls to Pigeon.

## 2.9.0

* Adds support for BitmapDescriptor classes `AssetMapBitmap` and `BytesMapBitmap`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,16 @@ private static String getClusterManagerId(Object clusterManagerData) {
* Requests all current clusters from the algorithm of the requested ClusterManager and converts
* them to result response.
*/
public void getClustersWithClusterManagerId(
String clusterManagerId, MethodChannel.Result result) {
public @NonNull Set<? extends Cluster<MarkerBuilder>> getClustersWithClusterManagerId(
String clusterManagerId) {
ClusterManager<MarkerBuilder> clusterManager = clusterManagerIdToManager.get(clusterManagerId);
if (clusterManager == null) {
result.error(
throw new Messages.FlutterError(
"Invalid clusterManagerId",
"getClusters called with invalid clusterManagerId:" + clusterManagerId,
null);
return;
}

final Set<? extends Cluster<MarkerBuilder>> clusters =
clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
result.success(Convert.clustersToJson(clusterManagerId, clusters));
return clusterManager.getAlgorithm().getClusters(googleMap.getCameraPosition().zoom);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

static Messages.PlatformLatLngBounds latLngBoundsToPigeon(LatLngBounds latLngBounds) {
return new Messages.PlatformLatLngBounds.Builder()
.setNortheast(latLngToPigeon(latLngBounds.northeast))
.setSouthwest(latLngToPigeon(latLngBounds.southwest))
.build();
}

static Object markerIdToJson(String markerId) {
if (markerId == null) {
return null;
Expand Down Expand Up @@ -431,13 +437,11 @@ static Object latLngToJson(LatLng latLng) {
return Arrays.asList(latLng.latitude, latLng.longitude);
}

static Object clustersToJson(
String clusterManagerId, Set<? extends Cluster<MarkerBuilder>> clusters) {
List<Object> data = new ArrayList<>(clusters.size());
for (Cluster<MarkerBuilder> cluster : clusters) {
data.add(clusterToJson(clusterManagerId, cluster));
}
return data;
static Messages.PlatformLatLng latLngToPigeon(LatLng latLng) {
return new Messages.PlatformLatLng.Builder()
.setLat(latLng.latitude)
.setLng(latLng.longitude)
.build();
}

static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> cluster) {
Expand Down Expand Up @@ -470,6 +474,27 @@ static Object clusterToJson(String clusterManagerId, Cluster<MarkerBuilder> clus
return data;
}

static Messages.PlatformCluster clusterToPigeon(
String clusterManagerId, Cluster<MarkerBuilder> cluster) {
int clusterSize = cluster.getSize();
String[] markerIds = new String[clusterSize];
MarkerBuilder[] markerBuilders = cluster.getItems().toArray(new MarkerBuilder[clusterSize]);

LatLngBounds.Builder latLngBoundsBuilder = LatLngBounds.builder();
for (int i = 0; i < clusterSize; i++) {
MarkerBuilder markerBuilder = markerBuilders[i];
latLngBoundsBuilder.include(markerBuilder.getPosition());
markerIds[i] = markerBuilder.markerId();
}

return new Messages.PlatformCluster.Builder()
.setClusterManagerId(clusterManagerId)
.setPosition(latLngToPigeon(cluster.getPosition()))
.setBounds(latLngBoundsToPigeon(latLngBoundsBuilder.build()))
.setMarkerIds(Arrays.asList(markerIds))
.build();
}

static LatLng toLatLng(Object o) {
final List<?> data = toList(o);
return new LatLng(toDouble(data.get(0)), toDouble(data.get(1)));
Expand Down
Loading

0 comments on commit 853c677

Please sign in to comment.