Skip to content

Commit f482577

Browse files
committed
[google_maps_flutter_android] Address android review comments
1 parent 0e68d50 commit f482577

6 files changed

Lines changed: 82 additions & 51 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.google.maps.android.heatmaps.Gradient;
4242
import com.google.maps.android.heatmaps.WeightedLatLng;
4343
import io.flutter.FlutterInjector;
44+
import io.flutter.plugins.googlemaps.Messages.FlutterError;
4445
import java.io.IOException;
4546
import java.io.InputStream;
4647
import java.util.ArrayList;
@@ -881,8 +882,12 @@ static Tile tileFromPigeon(Messages.PlatformTile tile) {
881882
sink.setClickable(groundOverlay.getClickable());
882883
sink.setImage(toBitmapDescriptor(groundOverlay.getImage(), assetManager, density, wrapper));
883884
if (groundOverlay.getPosition() != null) {
884-
assert groundOverlay.getWidth() != null
885-
: "Width is required when using a ground overlay with a position.";
885+
if (groundOverlay.getWidth() == null) {
886+
throw new FlutterError(
887+
"Invalid GroundOverlay",
888+
"Width is required when using a ground overlay with a position.",
889+
null);
890+
}
886891
sink.setPosition(
887892
latLngFromPigeon(groundOverlay.getPosition()),
888893
groundOverlay.getWidth().floatValue(),
@@ -906,8 +911,8 @@ static Tile tileFromPigeon(Messages.PlatformTile tile) {
906911
@NonNull String groundOverlayId,
907912
boolean isCreatedWithBounds) {
908913

909-
// Dummy image is used as image is required field of PlatformGroundOverlay and converting image
910-
// back to image descriptor is not currently supported.
914+
// Dummy image is used as image is a required field of PlatformGroundOverlay and converting
915+
// BitmapDescriptor used by Google Maps back to PlatformImageDescriptor is not currently supported.
911916
Messages.PlatformBitmap dummyImage =
912917
new Messages.PlatformBitmap.Builder()
913918
.setBitmap(

packages/google_maps_flutter/google_maps_flutter_android/android/src/test/java/io/flutter/plugins/googlemaps/ConvertTest.java

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,57 @@ public void buildGroundOverlayAnchorForPigeonWithCrossingMeridian() {
692692
Assert.assertEquals(0.5, anchor.getY(), 1e-15);
693693
}
694694

695+
private void assertGroundOverlayEquals(
696+
Messages.PlatformGroundOverlay result,
697+
GroundOverlay expectedOverlay,
698+
String expectedId,
699+
LatLng expectedPosition,
700+
LatLngBounds expectedBounds) {
701+
Assert.assertEquals(expectedId, result.getGroundOverlayId());
702+
if (expectedPosition != null) {
703+
Assert.assertNotNull(result.getPosition());
704+
Assert.assertEquals(expectedPosition.latitude, result.getPosition().getLatitude(), 1e-15);
705+
Assert.assertEquals(expectedPosition.longitude, result.getPosition().getLongitude(), 1e-15);
706+
Assert.assertNotNull(result.getWidth());
707+
Assert.assertNotNull(result.getHeight());
708+
Assert.assertEquals(expectedOverlay.getWidth(), result.getWidth(), 1e-15);
709+
Assert.assertEquals(expectedOverlay.getHeight(), result.getHeight(), 1e-15);
710+
} else {
711+
Assert.assertNull(result.getPosition());
712+
}
713+
if (expectedBounds != null) {
714+
Assert.assertNotNull(result.getBounds());
715+
Assert.assertEquals(
716+
expectedBounds.southwest.latitude,
717+
result.getBounds().getSouthwest().getLatitude(),
718+
1e-15);
719+
Assert.assertEquals(
720+
expectedBounds.southwest.longitude,
721+
result.getBounds().getSouthwest().getLongitude(),
722+
1e-15);
723+
Assert.assertEquals(
724+
expectedBounds.northeast.latitude,
725+
result.getBounds().getNortheast().getLatitude(),
726+
1e-15);
727+
Assert.assertEquals(
728+
expectedBounds.northeast.longitude,
729+
result.getBounds().getNortheast().getLongitude(),
730+
1e-15);
731+
} else {
732+
Assert.assertNull(result.getBounds());
733+
}
734+
735+
Assert.assertEquals(expectedOverlay.getBearing(), result.getBearing(), 1e-15);
736+
Assert.assertEquals(expectedOverlay.getTransparency(), result.getTransparency(), 1e-6);
737+
Assert.assertEquals(expectedOverlay.getZIndex(), result.getZIndex().intValue(), 1e-6);
738+
Assert.assertEquals(expectedOverlay.isVisible(), result.getVisible());
739+
Assert.assertEquals(expectedOverlay.isClickable(), result.getClickable());
740+
Messages.PlatformDoublePair anchor = result.getAnchor();
741+
Assert.assertNotNull(anchor);
742+
Assert.assertEquals(0.5, anchor.getX(), 1e-6);
743+
Assert.assertEquals(0.5, anchor.getY(), 1e-6);
744+
}
745+
695746
@Test
696747
public void groundOverlayToPigeonWithPosition() {
697748
GroundOverlay mockGroundOverlay = mock(GroundOverlay.class);
@@ -709,28 +760,11 @@ public void groundOverlayToPigeonWithPosition() {
709760
when(mockGroundOverlay.isVisible()).thenReturn(true);
710761
when(mockGroundOverlay.isClickable()).thenReturn(false);
711762

763+
String overlayId = "overlay_1";
712764
Messages.PlatformGroundOverlay result =
713-
Convert.groundOverlayToPigeon(mockGroundOverlay, "overlay_1", false);
714-
715-
Assert.assertEquals("overlay_1", result.getGroundOverlayId());
716-
Assert.assertNotNull(result.getPosition());
717-
Assert.assertEquals(position.latitude, result.getPosition().getLatitude(), 1e-15);
718-
Assert.assertEquals(position.longitude, result.getPosition().getLongitude(), 1e-15);
719-
Assert.assertNotNull(result.getWidth());
720-
Assert.assertNotNull(result.getHeight());
721-
Assert.assertEquals(30.0, result.getWidth(), 1e-15);
722-
Assert.assertEquals(40.0, result.getHeight(), 1e-15);
723-
Assert.assertEquals(50.0, result.getBearing(), 1e-15);
724-
Assert.assertEquals(0.6, result.getTransparency(), 1e-6);
725-
Assert.assertEquals(7, result.getZIndex().intValue());
726-
Assert.assertTrue(result.getVisible());
727-
Assert.assertFalse(result.getClickable());
728-
Assert.assertNull(result.getBounds());
765+
Convert.groundOverlayToPigeon(mockGroundOverlay, overlayId, false);
729766

730-
Messages.PlatformDoublePair anchor = result.getAnchor();
731-
Assert.assertNotNull(anchor);
732-
Assert.assertEquals(0.5, anchor.getX(), 1e-6);
733-
Assert.assertEquals(0.5, anchor.getY(), 1e-6);
767+
assertGroundOverlayEquals(result, mockGroundOverlay, overlayId, position, null);
734768
}
735769

736770
@Test
@@ -750,34 +784,11 @@ public void groundOverlayToPigeonWithBounds() {
750784
when(mockGroundOverlay.isVisible()).thenReturn(true);
751785
when(mockGroundOverlay.isClickable()).thenReturn(false);
752786

787+
String overlayId = "overlay_2";
753788
Messages.PlatformGroundOverlay result =
754-
Convert.groundOverlayToPigeon(mockGroundOverlay, "overlay_2", true);
755-
756-
Assert.assertEquals("overlay_2", result.getGroundOverlayId());
757-
Assert.assertNotNull(result.getBounds());
758-
Assert.assertEquals(
759-
bounds.southwest.latitude, result.getBounds().getSouthwest().getLatitude(), 1e-15);
760-
Assert.assertEquals(
761-
bounds.southwest.longitude, result.getBounds().getSouthwest().getLongitude(), 1e-15);
762-
Assert.assertEquals(
763-
bounds.northeast.latitude, result.getBounds().getNortheast().getLatitude(), 1e-15);
764-
Assert.assertEquals(
765-
bounds.northeast.longitude, result.getBounds().getNortheast().getLongitude(), 1e-15);
766-
Assert.assertNotNull(result.getWidth());
767-
Assert.assertNotNull(result.getHeight());
768-
Assert.assertEquals(30.0, result.getWidth(), 1e-15);
769-
Assert.assertEquals(40.0, result.getHeight(), 1e-15);
770-
Assert.assertEquals(50.0, result.getBearing(), 1e-15);
771-
Assert.assertEquals(0.6, result.getTransparency(), 1e-6);
772-
Assert.assertEquals(7, result.getZIndex().intValue());
773-
Assert.assertTrue(result.getVisible());
774-
Assert.assertFalse(result.getClickable());
775-
Assert.assertNull(result.getPosition());
789+
Convert.groundOverlayToPigeon(mockGroundOverlay, overlayId, true);
776790

777-
Messages.PlatformDoublePair anchor = result.getAnchor();
778-
Assert.assertNotNull(anchor);
779-
Assert.assertEquals(0.5, anchor.getX(), 1e-6);
780-
Assert.assertEquals(0.5, anchor.getY(), 1e-6);
791+
assertGroundOverlayEquals(result, mockGroundOverlay, overlayId, null, bounds);
781792
}
782793
}
783794

packages/google_maps_flutter/google_maps_flutter_android/example/integration_test/google_maps_tests.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:io';
78
import 'dart:typed_data';
89
import 'dart:ui' as ui;
910

@@ -20,6 +21,11 @@ const double _kInitialZoomLevel = 5;
2021
const CameraPosition _kInitialCameraPosition =
2122
CameraPosition(target: _kInitialMapCenter, zoom: _kInitialZoomLevel);
2223
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
24+
25+
// The tolerance value for floating-point comparisons in the tests.
26+
// This value was selected as the minimum possible value that the test passes.
27+
// There are multiple float conversions and calculations when data is converted
28+
// between Dart and platform implementations.
2329
const double _floatTolerance = 1e-8;
2430

2531
void googleMapsTests() {
@@ -995,7 +1001,7 @@ void googleMapsTests() {
9951001
},
9961002
// TODO(cyanglaz): un-skip the test when we can test this on CI with API key enabled.
9971003
// https://github.com/flutter/flutter/issues/57057
998-
skip: true);
1004+
skip: Platform.isAndroid);
9991005

10001006
testWidgets(
10011007
'set tileOverlay correctly',

packages/google_maps_flutter/google_maps_flutter_android/example/lib/ground_overlay.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class GroundOverlayBodyState extends State<GroundOverlayBody> {
131131
void _setBearing() {
132132
assert(_groundOverlay != null);
133133
setState(() {
134+
// Adjusts the bearing by 10 degrees, wrapping around at 360 degrees.
135+
// 10 is the increment, 350 degrees of the full circle -10.
134136
_groundOverlay = _groundOverlay!.copyWith(
135137
bearingParam: _groundOverlay!.bearing >= 350
136138
? 0

packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/integration_test/google_maps_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const double _kInitialZoomLevel = 5;
2020
const CameraPosition _kInitialCameraPosition =
2121
CameraPosition(target: _kInitialMapCenter, zoom: _kInitialZoomLevel);
2222
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
23+
24+
// The tolerance value for floating-point comparisons in the tests.
25+
// This value was selected as the minimum possible value that the test passes.
26+
// There are multiple float conversions and calculations when data is converted
27+
// between Dart and platform implementations.
2328
const double _floatTolerance = 1e-6;
2429

2530
void main() {

packages/google_maps_flutter/google_maps_flutter_ios/example/shared/maps_example_dart/lib/ground_overlay.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class GroundOverlayBodyState extends State<GroundOverlayBody> {
128128
void _setBearing() {
129129
assert(_groundOverlay != null);
130130
setState(() {
131+
// Adjusts the bearing by 10 degrees, wrapping around at 360 degrees.
132+
// 10 is the increment, 350 degrees of the full circle -10.
131133
_groundOverlay = _groundOverlay!.copyWith(
132134
bearingParam: _groundOverlay!.bearing >= 350
133135
? 0

0 commit comments

Comments
 (0)