Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.19.7

* Fixes warnings in Java code.

## 2.19.6

* Fixes the onTap callback for clustered pin info window taps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

package io.flutter.plugins.googlemaps;

import androidx.annotation.NonNull;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;

class CircleBuilder implements CircleOptionsSink {
private final CircleOptions circleOptions;
private final @NonNull CircleOptions circleOptions;
Comment thread
stuartmorgan-g marked this conversation as resolved.
private final float density;
private boolean consumeTapEvents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
class ClusterManagersController
implements GoogleMap.OnCameraIdleListener,
ClusterManager.OnClusterClickListener<MarkerBuilder> {
@NonNull private final Context context;
private final @NonNull Context context;

@VisibleForTesting @NonNull
protected final HashMap<String, ClusterManager<MarkerBuilder>> clusterManagerIdToManager;

@NonNull private final MapsCallbackApi flutterApi;
@Nullable private MarkerManager markerManager;
@Nullable private GoogleMap googleMap;
@NonNull private PlatformMarkerType markerType;
private final @NonNull MapsCallbackApi flutterApi;
private @Nullable MarkerManager markerManager;
private @Nullable GoogleMap googleMap;
private final @NonNull PlatformMarkerType markerType;

@Nullable
private ClusterManager.OnClusterItemClickListener<MarkerBuilder> clusterItemClickListener;
Expand Down Expand Up @@ -116,7 +116,7 @@ void addClusterManagers(@NonNull List<Messages.PlatformClusterManager> clusterMa
/** Adds new ClusterManager to the controller. */
void addClusterManager(String clusterManagerId) {
ClusterManager<MarkerBuilder> clusterManager =
new ClusterManager<MarkerBuilder>(context, googleMap, markerManager);
new ClusterManager<>(context, googleMap, markerManager);
initializeRenderer(clusterManager);
clusterManagerIdToManager.put(clusterManagerId, clusterManager);
}
Expand All @@ -126,17 +126,12 @@ void addClusterManager(String clusterManagerId) {
* advanced markers and MarkerClusterRenderer is used for default markers.
*/
private void initializeRenderer(ClusterManager<MarkerBuilder> clusterManager) {
final ClusterRenderer<MarkerBuilder> clusterRenderer;
switch (markerType) {
case ADVANCED_MARKER:
clusterRenderer =
new AdvancedMarkerClusterRenderer<>(context, googleMap, clusterManager, this);
break;
case MARKER:
default:
clusterRenderer = new MarkerClusterRenderer<>(context, googleMap, clusterManager, this);
break;
}
final ClusterRenderer<MarkerBuilder> clusterRenderer =
switch (markerType) {
case ADVANCED_MARKER ->
new AdvancedMarkerClusterRenderer<>(context, googleMap, clusterManager, this);
default -> new MarkerClusterRenderer<>(context, googleMap, clusterManager, this);
};
clusterManager.setRenderer(clusterRenderer);
initListenersForClusterManager(
clusterManager, this, clusterItemClickListener, clusterItemInfoWindowClickListener);
Expand All @@ -154,7 +149,7 @@ public void removeClusterManagers(@NonNull List<String> clusterManagerIdsToRemov
* to this cluster manager is removed from the clusterManagerIdToManager and it will be garbage
* collected later.
*/
private void removeClusterManager(Object clusterManagerId) {
private void removeClusterManager(String clusterManagerId) {
// Remove the cluster manager from the hash map to allow it to be garbage collected.
final ClusterManager<MarkerBuilder> clusterManager =
clusterManagerIdToManager.remove(clusterManagerId);
Expand Down Expand Up @@ -213,15 +208,6 @@ void onClusterItemRendered(@NonNull MarkerBuilder item, @NonNull Marker marker)
}
}

/** Reads clusterManagerId from object data. */
@SuppressWarnings("unchecked")
private static String getClusterManagerId(Object clusterManagerData) {
Map<String, Object> clusterMap = (Map<String, Object>) clusterManagerData;
// Ref: google_maps_flutter_platform_interface/lib/src/types/cluster_manager.dart
// ClusterManager.toJson() method.
return (String) clusterMap.get("clusterManagerId");
}

/**
* Requests all current clusters from the algorithm of the requested ClusterManager and converts
* them to result response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.maps.android.heatmaps.WeightedLatLng;
import io.flutter.FlutterInjector;
import io.flutter.plugins.googlemaps.Messages.FlutterError;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -66,18 +65,15 @@ private static BitmapDescriptor toBitmapDescriptor(
float density,
BitmapDescriptorFactoryWrapper wrapper) {
Object bitmap = platformBitmap.getBitmap();
if (bitmap instanceof Messages.PlatformBitmapDefaultMarker) {
Messages.PlatformBitmapDefaultMarker typedBitmap =
(Messages.PlatformBitmapDefaultMarker) bitmap;
if (bitmap instanceof Messages.PlatformBitmapDefaultMarker typedBitmap) {
if (typedBitmap.getHue() == null) {
return BitmapDescriptorFactory.defaultMarker();
} else {
final float hue = typedBitmap.getHue().floatValue();
return BitmapDescriptorFactory.defaultMarker(hue);
}
}
if (bitmap instanceof Messages.PlatformBitmapAsset) {
Messages.PlatformBitmapAsset typedBitmap = (Messages.PlatformBitmapAsset) bitmap;
if (bitmap instanceof Messages.PlatformBitmapAsset typedBitmap) {
final String assetPath = typedBitmap.getName();
final String assetPackage = typedBitmap.getPkg();
if (assetPackage == null) {
Expand All @@ -90,27 +86,22 @@ private static BitmapDescriptor toBitmapDescriptor(
.getLookupKeyForAsset(assetPath, assetPackage));
}
}
if (bitmap instanceof Messages.PlatformBitmapAssetImage) {
Messages.PlatformBitmapAssetImage typedBitmap = (Messages.PlatformBitmapAssetImage) bitmap;
if (bitmap instanceof Messages.PlatformBitmapAssetImage typedBitmap) {
final String assetImagePath = typedBitmap.getName();
return BitmapDescriptorFactory.fromAsset(
FlutterInjector.instance().flutterLoader().getLookupKeyForAsset(assetImagePath));
}
if (bitmap instanceof Messages.PlatformBitmapBytes) {
Messages.PlatformBitmapBytes typedBitmap = (Messages.PlatformBitmapBytes) bitmap;
if (bitmap instanceof Messages.PlatformBitmapBytes typedBitmap) {
return getBitmapFromBytesLegacy(typedBitmap);
}
if (bitmap instanceof Messages.PlatformBitmapAssetMap) {
Messages.PlatformBitmapAssetMap typedBitmap = (Messages.PlatformBitmapAssetMap) bitmap;
if (bitmap instanceof Messages.PlatformBitmapAssetMap typedBitmap) {
return getBitmapFromAsset(
typedBitmap, assetManager, density, wrapper, new FlutterInjectorWrapper());
}
if (bitmap instanceof Messages.PlatformBitmapBytesMap) {
Messages.PlatformBitmapBytesMap typedBitmap = (Messages.PlatformBitmapBytesMap) bitmap;
if (bitmap instanceof Messages.PlatformBitmapBytesMap typedBitmap) {
return getBitmapFromBytes(typedBitmap, density, wrapper);
}
if (bitmap instanceof Messages.PlatformBitmapPinConfig) {
Messages.PlatformBitmapPinConfig pinConfigBitmap = (Messages.PlatformBitmapPinConfig) bitmap;
if (bitmap instanceof Messages.PlatformBitmapPinConfig pinConfigBitmap) {
return getBitmapFromPinConfigBuilder(pinConfigBitmap, assetManager, density, wrapper);
}
throw new IllegalArgumentException("PlatformBitmap did not contain a supported subtype.");
Expand Down Expand Up @@ -288,9 +279,7 @@ public static BitmapDescriptor getBitmapFromAsset(
case AUTO:
final Double width = assetMap.getWidth();
final Double height = assetMap.getHeight();
InputStream inputStream = null;
try {
inputStream = assetManager.open(assetKey);
try (InputStream inputStream = assetManager.open(assetKey)) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

if (width != null || height != null) {
Expand All @@ -315,14 +304,6 @@ public static BitmapDescriptor getBitmapFromAsset(
}
} catch (Exception e) {
throw new IllegalArgumentException("'asset' cannot open asset: " + assetName, e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
case NONE:
break;
Expand All @@ -343,51 +324,36 @@ public static BitmapDescriptor getBitmapFromAsset(

static CameraUpdate cameraUpdateFromPigeon(Messages.PlatformCameraUpdate update, float density) {
Object cameraUpdate = update.getCameraUpdate();
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewCameraPosition) {
Messages.PlatformCameraUpdateNewCameraPosition newCameraPosition =
(Messages.PlatformCameraUpdateNewCameraPosition) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewCameraPosition newCameraPosition) {
return CameraUpdateFactory.newCameraPosition(
cameraPositionFromPigeon(newCameraPosition.getCameraPosition()));
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLng) {
Messages.PlatformCameraUpdateNewLatLng newLatLng =
(Messages.PlatformCameraUpdateNewLatLng) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLng newLatLng) {
return CameraUpdateFactory.newLatLng(latLngFromPigeon(newLatLng.getLatLng()));
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLngZoom) {
Messages.PlatformCameraUpdateNewLatLngZoom newLatLngZoom =
(Messages.PlatformCameraUpdateNewLatLngZoom) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLngZoom newLatLngZoom) {
return CameraUpdateFactory.newLatLngZoom(
latLngFromPigeon(newLatLngZoom.getLatLng()), newLatLngZoom.getZoom().floatValue());
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLngBounds) {
Messages.PlatformCameraUpdateNewLatLngBounds newLatLngBounds =
(Messages.PlatformCameraUpdateNewLatLngBounds) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateNewLatLngBounds newLatLngBounds) {
return CameraUpdateFactory.newLatLngBounds(
latLngBoundsFromPigeon(newLatLngBounds.getBounds()),
(int) (newLatLngBounds.getPadding() * density));
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateScrollBy) {
Messages.PlatformCameraUpdateScrollBy scrollBy =
(Messages.PlatformCameraUpdateScrollBy) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateScrollBy scrollBy) {
return CameraUpdateFactory.scrollBy(
scrollBy.getDx().floatValue() * density, scrollBy.getDy().floatValue() * density);
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoomBy) {
Messages.PlatformCameraUpdateZoomBy zoomBy =
(Messages.PlatformCameraUpdateZoomBy) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoomBy zoomBy) {
final Point focus = pointFromPigeon(zoomBy.getFocus(), density);
return (focus != null)
? CameraUpdateFactory.zoomBy(zoomBy.getAmount().floatValue(), focus)
: CameraUpdateFactory.zoomBy(zoomBy.getAmount().floatValue());
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoomTo) {
Messages.PlatformCameraUpdateZoomTo zoomTo =
(Messages.PlatformCameraUpdateZoomTo) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoomTo zoomTo) {
return CameraUpdateFactory.zoomTo(zoomTo.getZoom().floatValue());
}
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoom) {
Messages.PlatformCameraUpdateZoom zoom = (Messages.PlatformCameraUpdateZoom) cameraUpdate;
if (cameraUpdate instanceof Messages.PlatformCameraUpdateZoom zoom) {
return (zoom.getOut()) ? CameraUpdateFactory.zoomOut() : CameraUpdateFactory.zoomIn();
}
throw new IllegalArgumentException(
Expand All @@ -404,19 +370,13 @@ private static int toInt(Object o) {
}

static int toMapType(@NonNull Messages.PlatformMapType type) {
switch (type) {
case NONE:
return MAP_TYPE_NONE;
case NORMAL:
return MAP_TYPE_NORMAL;
case SATELLITE:
return MAP_TYPE_SATELLITE;
case TERRAIN:
return MAP_TYPE_TERRAIN;
case HYBRID:
return MAP_TYPE_HYBRID;
}
return MAP_TYPE_NORMAL;
return switch (type) {
Comment thread
stuartmorgan-g marked this conversation as resolved.
case NONE -> MAP_TYPE_NONE;
case NORMAL -> MAP_TYPE_NORMAL;
case SATELLITE -> MAP_TYPE_SATELLITE;
case TERRAIN -> MAP_TYPE_TERRAIN;
case HYBRID -> MAP_TYPE_HYBRID;
};
}

// For now, suppress the deprecation warning for LEGACY; in theory using it
Expand All @@ -432,13 +392,10 @@ static int toMapType(@NonNull Messages.PlatformMapType type) {
if (type == null) {
return null;
}
switch (type) {
case LATEST:
return MapsInitializer.Renderer.LATEST;
case LEGACY:
return MapsInitializer.Renderer.LEGACY;
}
return null;
return switch (type) {
case LATEST -> MapsInitializer.Renderer.LATEST;
case LEGACY -> MapsInitializer.Renderer.LEGACY;
};
}

static @NonNull Messages.PlatformCameraPosition cameraPositionToPigeon(
Expand Down Expand Up @@ -684,15 +641,11 @@ static String interpretPolygonOptions(Messages.PlatformPolygon polygon, PolygonO
}

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;
return switch (jointType) {
case MITERED -> JointType.DEFAULT;
case BEVEL -> JointType.BEVEL;
case ROUND -> JointType.ROUND;
};
}

/**
Expand All @@ -704,16 +657,13 @@ static int jointTypeFromPigeon(Messages.PlatformJointType jointType) {
*/
static int collisionBehaviorFromPigeon(
@NonNull Messages.PlatformMarkerCollisionBehavior collisionBehavior) {
switch (collisionBehavior) {
case REQUIRED_DISPLAY:
return AdvancedMarkerOptions.CollisionBehavior.REQUIRED;
case OPTIONAL_AND_HIDES_LOWER_PRIORITY:
return AdvancedMarkerOptions.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY;
case REQUIRED_AND_HIDES_OPTIONAL:
return AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL;
default:
return AdvancedMarkerOptions.CollisionBehavior.REQUIRED;
}
return switch (collisionBehavior) {
case REQUIRED_DISPLAY -> AdvancedMarkerOptions.CollisionBehavior.REQUIRED;
case OPTIONAL_AND_HIDES_LOWER_PRIORITY ->
AdvancedMarkerOptions.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY;
case REQUIRED_AND_HIDES_OPTIONAL ->
AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL;
};
}

static String interpretPolylineOptions(
Expand Down Expand Up @@ -750,19 +700,7 @@ static String interpretCircleOptions(Messages.PlatformCircle circle, CircleOptio
/**
* Set the options in the given heatmap object to the given sink.
*
* @param data the object expected to be a Map containing the heatmap options. The options map is
* expected to have the following structure:
* <pre>{@code
* {
* "heatmapId": String,
* "data": List, // List of serialized weighted lat/lng
* "gradient": Map, // Serialized heatmap gradient
* "maxIntensity": Double,
* "opacity": Double,
* "radius": Integer
* }
* }</pre>
*
* @param heatmap the heatmap object to read settings from.
* @param sink the HeatmapOptionsSink where the options will be set.
* @return the heatmapId.
* @throws IllegalArgumentException if heatmapId is null.
Expand Down Expand Up @@ -865,22 +803,19 @@ private static List<PatternItem> patternFromPigeon(

private static Cap capFromPigeon(
Messages.PlatformCap cap, AssetManager assetManager, float density) {
switch (cap.getType()) {
case BUTT_CAP:
return new ButtCap();
case ROUND_CAP:
return new RoundCap();
case SQUARE_CAP:
return new SquareCap();
case CUSTOM_CAP:
return switch (cap.getType()) {
case BUTT_CAP -> new ButtCap();
case ROUND_CAP -> new RoundCap();
case SQUARE_CAP -> new SquareCap();
case CUSTOM_CAP -> {
if (cap.getRefWidth() == null) {
throw new IllegalArgumentException("A Custom Cap must specify a refWidth value.");
}
return new CustomCap(
yield new CustomCap(
toBitmapDescriptor(cap.getBitmapDescriptor(), assetManager, density),
cap.getRefWidth().floatValue());
}
throw new IllegalArgumentException("Unrecognized PlatformCap type: " + cap.getType());
}
};
}

static String interpretTileOverlayOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

class GoogleMapBuilder implements GoogleMapOptionsSink {
private final GoogleMapOptions options = new GoogleMapOptions();
private final @NonNull GoogleMapOptions options = new GoogleMapOptions();
Comment thread
stuartmorgan-g marked this conversation as resolved.
private boolean trackCameraPosition = false;
private boolean myLocationEnabled = false;
private boolean myLocationButtonEnabled = false;
Expand Down
Loading
Loading