diff --git a/ApiDemos/java/app/build.gradle b/ApiDemos/java/app/build.gradle index 7697ef38..fea3eeaa 100644 --- a/ApiDemos/java/app/build.gradle +++ b/ApiDemos/java/app/build.gradle @@ -55,15 +55,13 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.gms:play-services-maps:17.0.0' - // Needed for the LiteListDemo implementation "androidx.recyclerview:recyclerview:1.1.0" - v3Implementation name:'maps-sdk-3.0.0-beta', ext:'aar' - v3Implementation 'com.google.android.gms:play-services-basement:17.3.0' - v3Implementation 'com.google.android.gms:play-services-base:17.3.0' - v3Implementation 'com.google.android.gms:play-services-gcm:17.0.0' - v3Implementation 'com.google.android.gms:play-services-location:17.0.0' + // GMS + gmsImplementation 'com.google.android.gms:play-services-maps:17.0.0' + + // V3 + v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta' // Tests testImplementation 'junit:junit:4.13' diff --git a/ApiDemos/java/app/libs/maps-sdk-3.0.0-beta.aar b/ApiDemos/java/app/libs/maps-sdk-3.0.0-beta.aar deleted file mode 100644 index b836c660..00000000 Binary files a/ApiDemos/java/app/libs/maps-sdk-3.0.0-beta.aar and /dev/null differ diff --git a/ApiDemos/java/app/src/main/AndroidManifest.xml b/ApiDemos/java/app/src/main/AndroidManifest.xml index dbed12d3..2b176f66 100644 --- a/ApiDemos/java/app/src/main/AndroidManifest.xml +++ b/ApiDemos/java/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ ~ limitations under the License. --> + package="com.example.mapdemo"> - Start cap - End cap - Joint Type - Pattern - Butt - Square - Round - Image - Default - Bevel - Round - Solid - Dotted - Dashed - Mixed - Grid Lite Mode @@ -239,4 +218,56 @@ This sample requires location permission to enable the \'my location\' layer. Please try again and grant access to use the location.\nIf the permission has been permanently denied, it can be enabled from the System Settings > Apps > \'Google Maps API Demos\'. Location permission is required for this demo. + + 26a66b031807a453 + Normal + Satellite + Hybrid + Terrain + Cloud Styling + Demonstrates how to use a simple map using Cloud Styling. + + + Polygons + Demonstrates how to add Polygons to a map. + Start cap + End cap + Joint Type + Pattern + Butt + Square + Round + Image + Default + Bevel + Round + Solid + Dotted + Dashed + Mixed + Polylines + Demonstrates how to add and configure Polylines to a map. + Select polyline + Sydney + Melbourne + Australia + World + ARGB + Chevron + Ook + Default + Bevel + Round + Solid color + Gradient color + Textured + Point sprite + Default + Geodesic + Visible + + + Marker Collision + Demonstrates different supported marker collision behaviors. + diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/BasicMapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/BasicMapDemoActivity.java index 16b3acc8..88d39441 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/BasicMapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/BasicMapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +21,6 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraClampingDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraClampingDemoActivity.java index a874f686..5ff656f6 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraClampingDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraClampingDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - package com.example.mapdemo; import com.google.android.libraries.maps.CameraUpdateFactory; @@ -32,12 +24,11 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.LatLngBounds; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.TextView; import android.widget.Toast; -import androidx.appcompat.app.AppCompatActivity; - /** * This shows how to constrain the camera to specific boundaries and zoom levels. */ diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraDemoActivity.java index d516ffc8..4ef0b7ed 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - package com.example.mapdemo; import android.graphics.Color; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CircleDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CircleDemoActivity.java index 9d50a66a..60887900 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CircleDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CircleDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CloudBasedMapStylingDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CloudBasedMapStylingDemoActivity.java new file mode 100644 index 00000000..cc9717ab --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/CloudBasedMapStylingDemoActivity.java @@ -0,0 +1,58 @@ +package com.example.mapdemo; + +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import com.google.android.libraries.maps.GoogleMap; +import com.google.android.libraries.maps.OnMapReadyCallback; +import com.google.android.libraries.maps.SupportMapFragment; + +/** + * This shows how to use Cloud-based Map Styling in a simple Activity. For more information on how + * to style a map using this method, see: + * https://developers.google.com/maps/documentation/android-sdk/cloud-styling-android + **/ +public class CloudBasedMapStylingDemoActivity extends AppCompatActivity implements OnMapReadyCallback { + + private static final String MAP_TYPE_KEY = "map_type"; + private GoogleMap map; + private int currentMapType = GoogleMap.MAP_TYPE_NORMAL; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + currentMapType = savedInstanceState.getInt(MAP_TYPE_KEY); + } + + // The underlying style the map will use has been set in the layout + // `cloud_styling_basic_demo` under the SupportMapFragment's `map:mapId` attribute. + setContentView(R.layout.cloud_styling_basic_demo); + SupportMapFragment mapFragment = + (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + + setUpButtonListeners(); + } + + @Override + public void onMapReady(GoogleMap map) { + this.map = map; + map.setMapType(currentMapType); + } + + private void setUpButtonListeners() { + findViewById(R.id.styling_normal_mode).setOnClickListener( + v -> setMapType(GoogleMap.MAP_TYPE_NORMAL)); + findViewById(R.id.styling_satellite_mode).setOnClickListener( + v -> setMapType(GoogleMap.MAP_TYPE_SATELLITE)); + findViewById(R.id.styling_hybrid_mode).setOnClickListener( + v -> setMapType(GoogleMap.MAP_TYPE_HYBRID)); + findViewById(R.id.styling_terrain_mode).setOnClickListener( + v -> setMapType(GoogleMap.MAP_TYPE_TERRAIN)); + } + + private void setMapType(int mapType) { + currentMapType = mapType; + map.setMapType(mapType); + } +} \ No newline at end of file diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetails.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetails.java index 9222b4d1..d804ea0f 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetails.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetails.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetailsList.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetailsList.java index 8b349826..a9d2aae7 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetailsList.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/DemoDetailsList.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,123 +15,136 @@ package com.example.mapdemo; +import com.example.mapdemo.polyline.PolylineDemoActivity; + /** * A list of all the demos we have available. */ public final class DemoDetailsList { - /** This class should not be instantiated. */ + /** + * This class should not be instantiated. + */ private DemoDetailsList() { } public static final DemoDetails[] DEMOS = { - new DemoDetails(R.string.basic_map_demo_label, - R.string.basic_map_demo_description, - BasicMapDemoActivity.class), - new DemoDetails(R.string.camera_demo_label, - R.string.camera_demo_description, - CameraDemoActivity.class), - new DemoDetails(R.string.camera_clamping_demo_label, - R.string.camera_clamping_demo_description, - CameraClampingDemoActivity.class), - new DemoDetails(R.string.circle_demo_label, - R.string.circle_demo_description, - CircleDemoActivity.class), - new DemoDetails(R.string.events_demo_label, - R.string.events_demo_description, - EventsDemoActivity.class), - new DemoDetails(R.string.ground_overlay_demo_label, - R.string.ground_overlay_demo_description, - GroundOverlayDemoActivity.class), - new DemoDetails(R.string.indoor_demo_label, - R.string.indoor_demo_description, - IndoorDemoActivity.class), - new DemoDetails(R.string.layers_demo_label, - R.string.layers_demo_description, - LayersDemoActivity.class), - new DemoDetails(R.string.lite_demo_label, - R.string.lite_demo_description, - LiteDemoActivity.class), - new DemoDetails(R.string.lite_list_demo_label, - R.string.lite_list_demo_description, - LiteListDemoActivity.class), - new DemoDetails(R.string.location_source_demo_label, - R.string.location_source_demo_description, - LocationSourceDemoActivity.class), - new DemoDetails(R.string.map_in_pager_demo_label, - R.string.map_in_pager_demo_description, - MapInPagerDemoActivity.class), - new DemoDetails(R.string.marker_demo_label, - R.string.marker_demo_description, - MarkerDemoActivity.class), - new DemoDetails(R.string.marker_close_info_window_on_retap_demo_label, - R.string.marker_close_info_window_on_retap_demo_description, - MarkerCloseInfoWindowOnRetapDemoActivity.class), - new DemoDetails(R.string.multi_map_demo_label, - R.string.multi_map_demo_description, - MultiMapDemoActivity.class), - new DemoDetails(R.string.my_location_demo_label, - R.string.my_location_demo_description, - MyLocationDemoActivity.class), - new DemoDetails(R.string.options_demo_label, - R.string.options_demo_description, - OptionsDemoActivity.class), - new DemoDetails(R.string.polygon_demo_label, - R.string.polygon_demo_description, - PolygonDemoActivity.class), - new DemoDetails(R.string.polyline_demo_label, - R.string.polyline_demo_description, - PolylineDemoActivity.class), - new DemoDetails(R.string.programmatic_demo_label, - R.string.programmatic_demo_description, - ProgrammaticDemoActivity.class), - new DemoDetails(R.string.raw_map_view_demo_label, - R.string.raw_map_view_demo_description, - RawMapViewDemoActivity.class), - new DemoDetails(R.string.retain_map_demo_label, - R.string.retain_map_demo_description, - RetainMapDemoActivity.class), - new DemoDetails(R.string.save_state_demo_label, - R.string.save_state_demo_description, - SaveStateDemoActivity.class), - new DemoDetails(R.string.snapshot_demo_label, - R.string.snapshot_demo_description, - SnapshotDemoActivity.class), - new DemoDetails(R.string.split_street_view_panorama_and_map_demo_label, - R.string.split_street_view_panorama_and_map_demo_description, - SplitStreetViewPanoramaAndMapDemoActivity.class), - new DemoDetails(R.string.street_view_panorama_basic_demo_label, - R.string.street_view_panorama_basic_demo_description, - StreetViewPanoramaBasicDemoActivity.class), - new DemoDetails(R.string.street_view_panorama_events_demo_label, - R.string.street_view_panorama_events_demo_description, - StreetViewPanoramaEventsDemoActivity.class), - new DemoDetails(R.string.street_view_panorama_navigation_demo_label, - R.string.street_view_panorama_navigation_demo_description, - StreetViewPanoramaNavigationDemoActivity.class), - new DemoDetails(R.string.street_view_panorama_options_demo_label, - R.string.street_view_panorama_options_demo_description, - StreetViewPanoramaOptionsDemoActivity.class), - new DemoDetails(R.string.street_view_panorama_view_demo_label, - R.string.street_view_panorama_view_demo_description, - StreetViewPanoramaViewDemoActivity.class), - new DemoDetails(R.string.styled_map_demo_label, - R.string.styled_map_demo_description, - StyledMapDemoActivity.class), - new DemoDetails(R.string.tags_demo_label, - R.string.tags_demo_description, - TagsDemoActivity.class), - new DemoDetails(R.string.tile_coordinate_demo_label, - R.string.tile_coordinate_demo_description, - TileCoordinateDemoActivity.class), - new DemoDetails(R.string.tile_overlay_demo_label, - R.string.tile_overlay_demo_description, - TileOverlayDemoActivity.class), - new DemoDetails(R.string.ui_settings_demo_label, - R.string.ui_settings_demo_description, - UiSettingsDemoActivity.class), - new DemoDetails(R.string.visible_region_demo_label, - R.string.visible_region_demo_description, - VisibleRegionDemoActivity.class), + new DemoDetails(R.string.basic_map_demo_label, + R.string.basic_map_demo_description, + BasicMapDemoActivity.class), + new DemoDetails(R.string.camera_demo_label, + R.string.camera_demo_description, + CameraDemoActivity.class), + new DemoDetails(R.string.camera_clamping_demo_label, + R.string.camera_clamping_demo_description, + CameraClampingDemoActivity.class), + new DemoDetails(R.string.circle_demo_label, + R.string.circle_demo_description, + CircleDemoActivity.class), + new DemoDetails(R.string.cloud_styling_label, + R.string.cloud_styling_description, + CloudBasedMapStylingDemoActivity.class), + new DemoDetails(R.string.events_demo_label, + R.string.events_demo_description, + EventsDemoActivity.class), + new DemoDetails(R.string.ground_overlay_demo_label, + R.string.ground_overlay_demo_description, + GroundOverlayDemoActivity.class), + new DemoDetails(R.string.indoor_demo_label, + R.string.indoor_demo_description, + IndoorDemoActivity.class), + new DemoDetails(R.string.layers_demo_label, + R.string.layers_demo_description, + LayersDemoActivity.class), + new DemoDetails(R.string.lite_demo_label, + R.string.lite_demo_description, + LiteDemoActivity.class), + new DemoDetails(R.string.lite_list_demo_label, + R.string.lite_list_demo_description, + LiteListDemoActivity.class), + new DemoDetails(R.string.location_source_demo_label, + R.string.location_source_demo_description, + LocationSourceDemoActivity.class), + new DemoDetails(R.string.map_in_pager_demo_label, + R.string.map_in_pager_demo_description, + MapInPagerDemoActivity.class), + new DemoDetails(R.string.marker_demo_label, + R.string.marker_demo_description, + MarkerDemoActivity.class), + new DemoDetails(R.string.marker_collision_label, + R.string.marker_collision_description, + MarkerCollisionDemoActivity.class), + new DemoDetails(R.string.marker_close_info_window_on_retap_demo_label, + R.string.marker_close_info_window_on_retap_demo_description, + MarkerCloseInfoWindowOnRetapDemoActivity.class), + new DemoDetails(R.string.polyline_demo_label, + R.string.polyline_demo_description, + PolylineDemoActivity.class), + new DemoDetails(R.string.multi_map_demo_label, + R.string.multi_map_demo_description, + MultiMapDemoActivity.class), + new DemoDetails(R.string.my_location_demo_label, + R.string.my_location_demo_description, + MyLocationDemoActivity.class), + new DemoDetails(R.string.options_demo_label, + R.string.options_demo_description, + OptionsDemoActivity.class), + new DemoDetails(R.string.polygon_demo_label, + R.string.polygon_demo_description, + PolygonDemoActivity.class), + new DemoDetails(R.string.polyline_demo_label, + R.string.polyline_demo_description, + PolylineDemoActivity.class), + new DemoDetails(R.string.programmatic_demo_label, + R.string.programmatic_demo_description, + ProgrammaticDemoActivity.class), + new DemoDetails(R.string.raw_map_view_demo_label, + R.string.raw_map_view_demo_description, + RawMapViewDemoActivity.class), + new DemoDetails(R.string.retain_map_demo_label, + R.string.retain_map_demo_description, + RetainMapDemoActivity.class), + new DemoDetails(R.string.save_state_demo_label, + R.string.save_state_demo_description, + SaveStateDemoActivity.class), + new DemoDetails(R.string.snapshot_demo_label, + R.string.snapshot_demo_description, + SnapshotDemoActivity.class), + new DemoDetails(R.string.split_street_view_panorama_and_map_demo_label, + R.string.split_street_view_panorama_and_map_demo_description, + SplitStreetViewPanoramaAndMapDemoActivity.class), + new DemoDetails(R.string.street_view_panorama_basic_demo_label, + R.string.street_view_panorama_basic_demo_description, + StreetViewPanoramaBasicDemoActivity.class), + new DemoDetails(R.string.street_view_panorama_events_demo_label, + R.string.street_view_panorama_events_demo_description, + StreetViewPanoramaEventsDemoActivity.class), + new DemoDetails(R.string.street_view_panorama_navigation_demo_label, + R.string.street_view_panorama_navigation_demo_description, + StreetViewPanoramaNavigationDemoActivity.class), + new DemoDetails(R.string.street_view_panorama_options_demo_label, + R.string.street_view_panorama_options_demo_description, + StreetViewPanoramaOptionsDemoActivity.class), + new DemoDetails(R.string.street_view_panorama_view_demo_label, + R.string.street_view_panorama_view_demo_description, + StreetViewPanoramaViewDemoActivity.class), + new DemoDetails(R.string.styled_map_demo_label, + R.string.styled_map_demo_description, + StyledMapDemoActivity.class), + new DemoDetails(R.string.tags_demo_label, + R.string.tags_demo_description, + TagsDemoActivity.class), + new DemoDetails(R.string.tile_coordinate_demo_label, + R.string.tile_coordinate_demo_description, + TileCoordinateDemoActivity.class), + new DemoDetails(R.string.tile_overlay_demo_label, + R.string.tile_overlay_demo_description, + TileOverlayDemoActivity.class), + new DemoDetails(R.string.ui_settings_demo_label, + R.string.ui_settings_demo_description, + UiSettingsDemoActivity.class), + new DemoDetails(R.string.visible_region_demo_label, + R.string.visible_region_demo_description, + VisibleRegionDemoActivity.class), }; } diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/EventsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/EventsDemoActivity.java index d17c6d1c..41e79063 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/EventsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/EventsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.GoogleMap; @@ -31,9 +25,8 @@ import com.google.android.libraries.maps.SupportMapFragment; import com.google.android.libraries.maps.model.LatLng; import android.os.Bundle; -import android.widget.TextView; - import androidx.appcompat.app.AppCompatActivity; +import android.widget.TextView; /** * This shows how to listen to some {@link GoogleMap} events. diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/FeatureView.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/FeatureView.java index 6af3ca11..b67d91dd 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/FeatureView.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/FeatureView.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import android.content.Context; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/GroundOverlayDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/GroundOverlayDemoActivity.java index 32fea96f..d5c2b61d 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/GroundOverlayDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/GroundOverlayDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.CameraUpdateFactory; @@ -33,13 +27,12 @@ import com.google.android.libraries.maps.model.GroundOverlayOptions; import com.google.android.libraries.maps.model.LatLng; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; -import androidx.appcompat.app.AppCompatActivity; - import java.util.ArrayList; import java.util.List; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/IndoorDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/IndoorDemoActivity.java index ebf4f68b..072362d5 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/IndoorDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/IndoorDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,11 +24,10 @@ import com.google.android.libraries.maps.model.IndoorLevel; import com.google.android.libraries.maps.model.LatLng; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; - import java.util.List; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LayersDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LayersDemoActivity.java index 1ccd4ff5..93fba523 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LayersDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LayersDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +22,9 @@ import com.google.android.libraries.maps.SupportMapFragment; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.AdapterView; @@ -38,10 +34,6 @@ import android.widget.CheckBox; import android.widget.Spinner; import android.widget.Toast; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - import static com.google.android.libraries.maps.GoogleMap.MAP_TYPE_HYBRID; import static com.google.android.libraries.maps.GoogleMap.MAP_TYPE_NONE; import static com.google.android.libraries.maps.GoogleMap.MAP_TYPE_NORMAL; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteDemoActivity.java index 215db344..99881796 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.CameraUpdateFactory; @@ -34,9 +28,8 @@ import com.google.android.libraries.maps.model.PolylineOptions; import android.graphics.Color; import android.os.Bundle; -import android.view.View; - import androidx.appcompat.app.AppCompatActivity; +import android.view.View; /** * This demo shows some features supported in lite mode. diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteListDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteListDemoActivity.java index 96fe9309..60b193ae 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteListDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LiteListDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,16 +24,16 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; /** * This shows to include a map in lite mode in a ListView. diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LocationSourceDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LocationSourceDemoActivity.java index 724aff1b..192f53d1 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LocationSourceDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/LocationSourceDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.GoogleMap; @@ -31,7 +25,6 @@ import com.google.android.libraries.maps.model.LatLng; import android.location.Location; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MainActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MainActivity.java index f70c0d51..164564f6 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MainActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MainActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,7 +77,7 @@ public final class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - ListView list = (ListView) findViewById(R.id.list); + ListView list = findViewById(R.id.list); ListAdapter adapter = new CustomArrayAdapter(this, DemoDetailsList.DEMOS); @@ -93,7 +86,7 @@ public final class MainActivity extends AppCompatActivity list.setEmptyView(findViewById(R.id.empty)); if (getString(R.string.maps_api_key).isEmpty()) { - Toast.makeText(this, "Add your own API key in ApiDemos/java/secure.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Add your own API key in ApiDemos/java/app/secure.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show(); } } diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MapInPagerDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MapInPagerDemoActivity.java index 813850a5..ff436fc3 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MapInPagerDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MapInPagerDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,34 +18,38 @@ package com.example.mapdemo; import com.google.android.libraries.maps.SupportMapFragment; import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; +import androidx.appcompat.app.AppCompatActivity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + /** * This shows how to add a map to a ViewPager. Note the use of * {@link ViewGroup#requestTransparentRegion(View)} to reduce jankiness. */ public class MapInPagerDemoActivity extends AppCompatActivity { + private MyAdapter mAdapter; + + private ViewPager mPager; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_in_pager_demo); - MyAdapter adapter = new MyAdapter(getSupportFragmentManager()); + mAdapter = new MyAdapter(getSupportFragmentManager()); - ViewPager pager = findViewById(R.id.pager); - pager.setAdapter(adapter); + mPager = (ViewPager) findViewById(R.id.pager); + mPager.setAdapter(mAdapter); // This is required to avoid a black flash when the map is loaded. The flash is due // to the use of a SurfaceView as the underlying view of the map. - pager.requestTransparentRegion(pager); + mPager.requestTransparentRegion(mPager); } /** A simple fragment that displays a TextView. */ @@ -68,7 +65,7 @@ public class MapInPagerDemoActivity extends AppCompatActivity { public static class MyAdapter extends FragmentPagerAdapter { public MyAdapter(FragmentManager fm) { - super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); + super(fm); } @Override diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCloseInfoWindowOnRetapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCloseInfoWindowOnRetapDemoActivity.java index cf23dc91..fd2fac36 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCloseInfoWindowOnRetapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCloseInfoWindowOnRetapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +26,6 @@ import com.google.android.libraries.maps.model.Marker; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCollisionDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCollisionDemoActivity.java new file mode 100644 index 00000000..dbced934 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerCollisionDemoActivity.java @@ -0,0 +1,84 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo; + +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import com.google.android.libraries.maps.CameraUpdateFactory; +import com.google.android.libraries.maps.GoogleMap; +import com.google.android.libraries.maps.OnMapReadyCallback; +import com.google.android.libraries.maps.SupportMapFragment; +import com.google.android.libraries.maps.model.BitmapDescriptorFactory; +import com.google.android.libraries.maps.model.LatLng; +import com.google.android.libraries.maps.model.Marker; +import com.google.android.libraries.maps.model.MarkerOptions; + +/** This shows how to set collision behavior for the marker. */ +public class MarkerCollisionDemoActivity extends AppCompatActivity implements OnMapReadyCallback { + + private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689); + + private GoogleMap map = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.marker_collision_demo); + + SupportMapFragment mapFragment = + (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(GoogleMap map) { + this.map = map; + addMarkersToMap(); + map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 3)); + } + + private void addMarkersToMap() { + MarkerOptions defaultMarkerOptions = new MarkerOptions(); + + // Add 100 markers to the map. + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + defaultMarkerOptions + .position(new LatLng(SYDNEY.latitude + i, SYDNEY.longitude - j)) + .zIndex(i * 10 + j) + .title("zIndex:" + (i * 10 + j)) + .draggable(true); + + if ((i + j) % 3 == 0) { + defaultMarkerOptions.icon( + BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); + defaultMarkerOptions.collisionBehavior( + Marker.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY); + } else if ((i + j) % 3 == 1) { + defaultMarkerOptions.icon( + BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); + defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL); + } else { + defaultMarkerOptions.icon( + BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); + defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED); + } + map.addMarker(defaultMarkerOptions); + } + } + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java index 54841701..fba07ed4 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.CameraUpdateFactory; @@ -44,12 +38,11 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; - import androidx.annotation.ColorInt; import androidx.annotation.DrawableRes; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.res.ResourcesCompat; import androidx.core.graphics.drawable.DrawableCompat; +import androidx.appcompat.app.AppCompatActivity; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.view.View; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MultiMapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MultiMapDemoActivity.java index 56f8735b..6382f770 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MultiMapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MultiMapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +16,6 @@ package com.example.mapdemo; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MyLocationDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MyLocationDemoActivity.java index 822b8165..545dabe9 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MyLocationDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/MyLocationDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +15,7 @@ package com.example.mapdemo; +import android.location.Location; import com.google.android.libraries.maps.GoogleMap; import com.google.android.libraries.maps.GoogleMap.OnMyLocationButtonClickListener; import com.google.android.libraries.maps.GoogleMap.OnMyLocationClickListener; @@ -30,27 +24,25 @@ import com.google.android.libraries.maps.SupportMapFragment; import android.Manifest; import android.content.pm.PackageManager; -import android.location.Location; import android.os.Bundle; - import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; import android.widget.Toast; /** - * This demo shows how GMS Location can be used to check for changes to the users location. The - * "My Location" button uses GMS Location to set the blue dot representing the users location. - * Permission for {@link android.Manifest.permission#ACCESS_FINE_LOCATION} is requested at run - * time. If the permission has not been granted, the Activity is finished with an error message. + * This demo shows how GMS Location can be used to check for changes to the users location. The "My + * Location" button uses GMS Location to set the blue dot representing the users location. + * Permission for {@link android.Manifest.permission#ACCESS_FINE_LOCATION} is requested at run time. + * If the permission has not been granted, the Activity is finished with an error message. */ public class MyLocationDemoActivity extends AppCompatActivity - implements - OnMyLocationButtonClickListener, - OnMyLocationClickListener, - OnMapReadyCallback, - ActivityCompat.OnRequestPermissionsResultCallback { + implements + OnMyLocationButtonClickListener, + OnMyLocationClickListener, + OnMapReadyCallback, + ActivityCompat.OnRequestPermissionsResultCallback { /** * Request code for location permission request. @@ -60,8 +52,8 @@ public class MyLocationDemoActivity extends AppCompatActivity private static final int LOCATION_PERMISSION_REQUEST_CODE = 1; /** - * Flag indicating whether a requested permission has been denied after returning in - * {@link #onRequestPermissionsResult(int, String[], int[])}. + * Flag indicating whether a requested permission has been denied after returning in {@link + * #onRequestPermissionsResult(int, String[], int[])}. */ private boolean permissionDenied = false; @@ -73,7 +65,7 @@ public class MyLocationDemoActivity extends AppCompatActivity setContentView(R.layout.my_location_demo); SupportMapFragment mapFragment = - (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); + (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); } @@ -91,7 +83,7 @@ public class MyLocationDemoActivity extends AppCompatActivity private void enableMyLocation() { // [START maps_check_location_permission] if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) - == PackageManager.PERMISSION_GRANTED) { + == PackageManager.PERMISSION_GRANTED) { if (map != null) { map.setMyLocationEnabled(true); } @@ -118,12 +110,14 @@ public class MyLocationDemoActivity extends AppCompatActivity // [START maps_check_location_permission_result] @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, + @NonNull int[] grantResults) { if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) { return; } - if (PermissionUtils.isPermissionGranted(permissions, grantResults, Manifest.permission.ACCESS_FINE_LOCATION)) { + if (PermissionUtils.isPermissionGranted(permissions, grantResults, + Manifest.permission.ACCESS_FINE_LOCATION)) { // Enable the my location layer if the permission has been granted. enableMyLocation(); } else { @@ -151,7 +145,7 @@ public class MyLocationDemoActivity extends AppCompatActivity */ private void showMissingPermissionError() { PermissionUtils.PermissionDeniedDialog - .newInstance(true).show(getSupportFragmentManager(), "dialog"); + .newInstance(true).show(getSupportFragmentManager(), "dialog"); } -} +} \ No newline at end of file diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OnMapAndViewReadyListener.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OnMapAndViewReadyListener.java index 4969c3d0..374a119f 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OnMapAndViewReadyListener.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OnMapAndViewReadyListener.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OptionsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OptionsDemoActivity.java index ad238ddb..c068eae6 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OptionsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/OptionsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. - package com.example.mapdemo; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PermissionUtils.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PermissionUtils.java index 21094cb6..e87f1bd7 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PermissionUtils.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PermissionUtils.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,10 +21,9 @@ import android.app.Dialog; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.os.Bundle; - -import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.fragment.app.DialogFragment; +import androidx.appcompat.app.AppCompatActivity; import android.widget.Toast; /** @@ -44,7 +36,7 @@ public abstract class PermissionUtils { * be shown to the user, displays a dialog that triggers the request. */ public static void requestPermission(AppCompatActivity activity, int requestId, - String permission, boolean finishActivity) { + String permission, boolean finishActivity) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // Display a dialog with rationale. PermissionUtils.RationaleDialog.newInstance(requestId, finishActivity) diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolygonDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolygonDemoActivity.java index 7a5c167d..179d318d 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolygonDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolygonDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +17,7 @@ package com.example.mapdemo; import android.graphics.Color; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; @@ -33,8 +27,6 @@ import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.Spinner; -import androidx.appcompat.app.AppCompatActivity; - import com.google.android.libraries.maps.CameraUpdateFactory; import com.google.android.libraries.maps.GoogleMap; import com.google.android.libraries.maps.OnMapReadyCallback; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolylineDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolylineDemoActivity.java deleted file mode 100644 index ec4bd53a..00000000 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/PolylineDemoActivity.java +++ /dev/null @@ -1,332 +0,0 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -package com.example.mapdemo; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.View; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.SeekBar; -import android.widget.SeekBar.OnSeekBarChangeListener; -import android.widget.Spinner; - -import androidx.appcompat.app.AppCompatActivity; - -import com.google.android.libraries.maps.CameraUpdateFactory; -import com.google.android.libraries.maps.GoogleMap; -import com.google.android.libraries.maps.OnMapReadyCallback; -import com.google.android.libraries.maps.SupportMapFragment; -import com.google.android.libraries.maps.model.BitmapDescriptorFactory; -import com.google.android.libraries.maps.model.ButtCap; -import com.google.android.libraries.maps.model.Cap; -import com.google.android.libraries.maps.model.CustomCap; -import com.google.android.libraries.maps.model.Dash; -import com.google.android.libraries.maps.model.Dot; -import com.google.android.libraries.maps.model.Gap; -import com.google.android.libraries.maps.model.JointType; -import com.google.android.libraries.maps.model.LatLng; -import com.google.android.libraries.maps.model.PatternItem; -import com.google.android.libraries.maps.model.Polyline; -import com.google.android.libraries.maps.model.PolylineOptions; -import com.google.android.libraries.maps.model.RoundCap; -import com.google.android.libraries.maps.model.SquareCap; - -import java.util.Arrays; -import java.util.List; - -/** - * This shows how to draw polylines on a map. - */ -public class PolylineDemoActivity extends AppCompatActivity - implements OnSeekBarChangeListener, OnItemSelectedListener, OnMapReadyCallback { - - // City locations for mutable polyline. - private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995); - private static final LatLng DARWIN = new LatLng(-12.4258647, 130.7932231); - private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298); - private static final LatLng PERTH = new LatLng(-31.95285, 115.85734); - - // Airport locations for geodesic polyline. - private static final LatLng AKL = new LatLng(-37.006254, 174.783018); - private static final LatLng JFK = new LatLng(40.641051, -73.777485); - private static final LatLng LAX = new LatLng(33.936524, -118.377686); - private static final LatLng LHR = new LatLng(51.471547, -0.460052); - - private static final int MAX_WIDTH_PX = 100; - private static final int MAX_HUE_DEGREES = 360; - private static final int MAX_ALPHA = 255; - private static final int CUSTOM_CAP_IMAGE_REF_WIDTH_PX = 50; - private static final int INITIAL_STROKE_WIDTH_PX = 5; - - private static final int PATTERN_DASH_LENGTH_PX = 50; - private static final int PATTERN_GAP_LENGTH_PX = 20; - private static final Dot DOT = new Dot(); - private static final Dash DASH = new Dash(PATTERN_DASH_LENGTH_PX); - private static final Gap GAP = new Gap(PATTERN_GAP_LENGTH_PX); - private static final List PATTERN_DOTTED = Arrays.asList(DOT, GAP); - private static final List PATTERN_DASHED = Arrays.asList(DASH, GAP); - private static final List PATTERN_MIXED = Arrays.asList(DOT, GAP, DOT, DASH, GAP); - - private Polyline mutablePolyline; - private SeekBar hueBar; - private SeekBar alphaBar; - private SeekBar widthBar; - private Spinner startCapSpinner; - private Spinner endCapSpinner; - private Spinner jointTypeSpinner; - private Spinner patternSpinner; - private CheckBox clickabilityCheckbox; - - // These are the options for polyline caps, joints and patterns. We use their - // string resource IDs as identifiers. - - private static final int[] CAP_TYPE_NAME_RESOURCE_IDS = { - R.string.cap_butt, // Default - R.string.cap_round, - R.string.cap_square, - R.string.cap_image, - }; - - private static final int[] JOINT_TYPE_NAME_RESOURCE_IDS = { - R.string.joint_type_default, // Default - R.string.joint_type_bevel, - R.string.joint_type_round, - }; - - private static final int[] PATTERN_TYPE_NAME_RESOURCE_IDS = { - R.string.pattern_solid, // Default - R.string.pattern_dashed, - R.string.pattern_dotted, - R.string.pattern_mixed, - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.polyline_demo); - - hueBar = findViewById(R.id.hueSeekBar); - hueBar.setMax(MAX_HUE_DEGREES); - hueBar.setProgress(0); - - alphaBar = findViewById(R.id.alphaSeekBar); - alphaBar.setMax(MAX_ALPHA); - alphaBar.setProgress(MAX_ALPHA); - - widthBar = findViewById(R.id.widthSeekBar); - widthBar.setMax(MAX_WIDTH_PX); - widthBar.setProgress(MAX_WIDTH_PX / 2); - - startCapSpinner = findViewById(R.id.startCapSpinner); - startCapSpinner.setAdapter(new ArrayAdapter<>( - this, android.R.layout.simple_spinner_item, - getResourceStrings(CAP_TYPE_NAME_RESOURCE_IDS))); - - endCapSpinner = findViewById(R.id.endCapSpinner); - endCapSpinner.setAdapter(new ArrayAdapter<>( - this, android.R.layout.simple_spinner_item, - getResourceStrings(CAP_TYPE_NAME_RESOURCE_IDS))); - - jointTypeSpinner = findViewById(R.id.jointTypeSpinner); - jointTypeSpinner.setAdapter(new ArrayAdapter<>( - this, android.R.layout.simple_spinner_item, - getResourceStrings(JOINT_TYPE_NAME_RESOURCE_IDS))); - - patternSpinner = findViewById(R.id.patternSpinner); - patternSpinner.setAdapter(new ArrayAdapter<>( - this, android.R.layout.simple_spinner_item, - getResourceStrings(PATTERN_TYPE_NAME_RESOURCE_IDS))); - - clickabilityCheckbox = findViewById(R.id.toggleClickability); - - SupportMapFragment mapFragment = - (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); - mapFragment.getMapAsync(this); - } - - private String[] getResourceStrings(int[] resourceIds) { - String[] strings = new String[resourceIds.length]; - for (int i = 0; i < resourceIds.length; i++) { - strings[i] = getString(resourceIds[i]); - } - return strings; - } - - @Override - public void onMapReady(GoogleMap map) { - - // Override the default content description on the view, for accessibility mode. - map.setContentDescription(getString(R.string.polyline_demo_description)); - - // A geodesic polyline that goes around the world. - map.addPolyline(new PolylineOptions() - .add(LHR, AKL, LAX, JFK, LHR) - .width(INITIAL_STROKE_WIDTH_PX) - .color(Color.BLUE) - .geodesic(true) - .clickable(clickabilityCheckbox.isChecked())); - - // A simple polyline across Australia. This polyline will be mutable. - int color = Color.HSVToColor( - alphaBar.getProgress(), new float[]{hueBar.getProgress(), 1, 1}); - mutablePolyline = map.addPolyline(new PolylineOptions() - .color(color) - .width(widthBar.getProgress()) - .clickable(clickabilityCheckbox.isChecked()) - .add(MELBOURNE, ADELAIDE, PERTH, DARWIN)); - - hueBar.setOnSeekBarChangeListener(this); - alphaBar.setOnSeekBarChangeListener(this); - widthBar.setOnSeekBarChangeListener(this); - - startCapSpinner.setOnItemSelectedListener(this); - endCapSpinner.setOnItemSelectedListener(this); - jointTypeSpinner.setOnItemSelectedListener(this); - patternSpinner.setOnItemSelectedListener(this); - - mutablePolyline.setStartCap(getSelectedCap(startCapSpinner.getSelectedItemPosition())); - mutablePolyline.setEndCap(getSelectedCap(endCapSpinner.getSelectedItemPosition())); - mutablePolyline.setJointType(getSelectedJointType(jointTypeSpinner.getSelectedItemPosition())); - mutablePolyline.setPattern(getSelectedPattern(patternSpinner.getSelectedItemPosition())); - - // Move the map so that it is centered on the mutable polyline. - map.moveCamera(CameraUpdateFactory.newLatLngZoom(MELBOURNE, 3)); - - // Add a listener for polyline clicks that changes the clicked polyline's color. - map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { - @Override - public void onPolylineClick(Polyline polyline) { - // Flip the values of the red, green and blue components of the polyline's color. - polyline.setColor(polyline.getColor() ^ 0x00ffffff); - } - }); - } - - private Cap getSelectedCap(int pos) { - switch (CAP_TYPE_NAME_RESOURCE_IDS[pos]) { - case R.string.cap_butt: - return new ButtCap(); - case R.string.cap_square: - return new SquareCap(); - case R.string.cap_round: - return new RoundCap(); - case R.string.cap_image: - return new CustomCap( - BitmapDescriptorFactory.fromResource(R.drawable.chevron), - CUSTOM_CAP_IMAGE_REF_WIDTH_PX); - } - return null; - } - - private int getSelectedJointType(int pos) { - switch (JOINT_TYPE_NAME_RESOURCE_IDS[pos]) { - case R.string.joint_type_bevel: - return JointType.BEVEL; - case R.string.joint_type_round: - return JointType.ROUND; - case R.string.joint_type_default: - return JointType.DEFAULT; - } - return 0; - } - - private List getSelectedPattern(int pos) { - switch (PATTERN_TYPE_NAME_RESOURCE_IDS[pos]) { - case R.string.pattern_solid: - return null; - case R.string.pattern_dotted: - return PATTERN_DOTTED; - case R.string.pattern_dashed: - return PATTERN_DASHED; - case R.string.pattern_mixed: - return PATTERN_MIXED; - default: - return null; - } - } - - @Override - public void onItemSelected(AdapterView parent, View view, int pos, long id) { - switch (parent.getId()) { - case R.id.startCapSpinner: - mutablePolyline.setStartCap(getSelectedCap(pos)); - break; - case R.id.endCapSpinner: - mutablePolyline.setEndCap(getSelectedCap(pos)); - break; - case R.id.jointTypeSpinner: - mutablePolyline.setJointType(getSelectedJointType(pos)); - break; - case R.id.patternSpinner: - mutablePolyline.setPattern(getSelectedPattern(pos)); - break; - } - } - - @Override - public void onNothingSelected(AdapterView parent) { - // Don't do anything here. - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - // Don't do anything here. - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - // Don't do anything here. - } - - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - if (mutablePolyline == null) { - return; - } - - if (seekBar == hueBar) { - mutablePolyline.setColor(Color.HSVToColor( - Color.alpha(mutablePolyline.getColor()), new float[]{progress, 1, 1})); - } else if (seekBar == alphaBar) { - float[] prevHSV = new float[3]; - Color.colorToHSV(mutablePolyline.getColor(), prevHSV); - mutablePolyline.setColor(Color.HSVToColor(progress, prevHSV)); - } else if (seekBar == widthBar) { - mutablePolyline.setWidth(progress); - } - } - - /** - * Toggles the clickability of the polyline based on the state of the View that triggered this - * call. - * This callback is defined on the CheckBox in the layout for this Activity. - */ - public void toggleClickability(View view) { - if (mutablePolyline != null) { - mutablePolyline.setClickable(((CheckBox) view).isChecked()); - } - } -} \ No newline at end of file diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/ProgrammaticDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/ProgrammaticDemoActivity.java index 1a901ece..4cc43482 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/ProgrammaticDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/ProgrammaticDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,9 +22,8 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; - -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; +import androidx.appcompat.app.AppCompatActivity; /** * Demonstrates how to instantiate a SupportMapFragment programmatically and add a marker to it. diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RawMapViewDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RawMapViewDemoActivity.java index 66f2acdc..75520e85 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RawMapViewDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RawMapViewDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +22,6 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RetainMapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RetainMapDemoActivity.java index fb8a6837..65800dea 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RetainMapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/RetainMapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +22,6 @@ import com.google.android.libraries.maps.model.LatLng; import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SaveStateDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SaveStateDemoActivity.java index 4c3b58d1..26b0aa84 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SaveStateDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SaveStateDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,7 +29,6 @@ import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; - import androidx.appcompat.app.AppCompatActivity; import java.util.Random; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SnapshotDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SnapshotDemoActivity.java index 185bef4c..1d908708 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SnapshotDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SnapshotDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,12 +23,11 @@ import com.google.android.libraries.maps.SupportMapFragment; import android.graphics.Bitmap; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.ImageView; -import androidx.appcompat.app.AppCompatActivity; - /** * This shows how to take a snapshot of the map. */ diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SplitStreetViewPanoramaAndMapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SplitStreetViewPanoramaAndMapDemoActivity.java index a278be82..40d92608 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SplitStreetViewPanoramaAndMapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/SplitStreetViewPanoramaAndMapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,7 +30,6 @@ import com.google.android.libraries.maps.model.MarkerOptions; import com.google.android.libraries.maps.model.StreetViewPanoramaLocation; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaBasicDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaBasicDemoActivity.java index d1119121..7d6c9bc9 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaBasicDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaBasicDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +21,6 @@ import com.google.android.libraries.maps.SupportStreetViewPanoramaFragment; import com.google.android.libraries.maps.model.LatLng; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; /** diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaEventsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaEventsDemoActivity.java index 3d21a97e..a905d883 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaEventsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaEventsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaNavigationDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaNavigationDemoActivity.java index 39814351..f7d578ab 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaNavigationDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaNavigationDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,13 +24,11 @@ import com.google.android.libraries.maps.model.StreetViewPanoramaLink; import com.google.android.libraries.maps.model.StreetViewPanoramaLocation; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.SeekBar; import android.widget.Toast; -import androidx.appcompat.app.AppCompatActivity; - - /** * This shows how to create an activity with access to all the options in Panorama * which can be adjusted dynamically diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaOptionsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaOptionsDemoActivity.java index 4ad0c5e0..d596fd7f 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaOptionsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaOptionsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,12 +16,11 @@ package com.example.mapdemo; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.Toast; -import androidx.appcompat.app.AppCompatActivity; - import com.google.android.libraries.maps.StreetViewPanorama; import com.google.android.libraries.maps.SupportStreetViewPanoramaFragment; import com.google.android.libraries.maps.model.LatLng; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaViewDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaViewDemoActivity.java index 6ed964c2..27ce10ec 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaViewDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StreetViewPanoramaViewDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StyledMapDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StyledMapDemoActivity.java index 8de72185..dd08bf76 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StyledMapDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/StyledMapDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,14 +24,13 @@ import com.google.android.libraries.maps.model.MapStyleOptions; import android.content.DialogInterface; import android.os.Bundle; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; - import java.util.ArrayList; import java.util.List; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TagsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TagsDemoActivity.java index b8a9ae94..fd022829 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TagsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TagsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +17,8 @@ package com.example.mapdemo; import android.graphics.Color; import android.os.Bundle; -import android.widget.TextView; - import androidx.appcompat.app.AppCompatActivity; - +import android.widget.TextView; import com.google.android.libraries.maps.CameraUpdateFactory; import com.google.android.libraries.maps.GoogleMap; import com.google.android.libraries.maps.GoogleMap.OnCircleClickListener; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileCoordinateDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileCoordinateDemoActivity.java index 2772ee81..23ad6006 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileCoordinateDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileCoordinateDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +27,6 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; - import androidx.appcompat.app.AppCompatActivity; import java.io.ByteArrayOutputStream; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileOverlayDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileOverlayDemoActivity.java index 3bf1da67..24319f0e 100644 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileOverlayDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/TileOverlayDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +13,7 @@ // limitations under the License. + package com.example.mapdemo; import com.google.android.libraries.maps.GoogleMap; @@ -31,13 +25,12 @@ import com.google.android.libraries.maps.model.TileProvider; import com.google.android.libraries.maps.model.UrlTileProvider; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; -import androidx.appcompat.app.AppCompatActivity; - import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -52,7 +45,7 @@ public class TileOverlayDemoActivity extends AppCompatActivity /** This returns moon tiles. */ private static final String MOON_MAP_URL_FORMAT = - "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw/%d/%d/%d.jpg"; + "http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw/%d/%d/%d.jpg"; private TileOverlay mMoonTiles; private SeekBar mTransparencyBar; @@ -116,4 +109,4 @@ public class TileOverlayDemoActivity extends AppCompatActivity mMoonTiles.setTransparency((float) progress / (float) TRANSPARENCY_MAX); } } -} +} \ No newline at end of file diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/UiSettingsDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/UiSettingsDemoActivity.java index b79f6c24..cfe8cb92 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/UiSettingsDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/UiSettingsDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. + + package com.example.mapdemo; import com.google.android.libraries.maps.GoogleMap; @@ -29,11 +24,10 @@ import com.google.android.libraries.maps.UiSettings; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; - import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.Toast; diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/VisibleRegionDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/VisibleRegionDemoActivity.java index e190086a..81bc31a1 100755 --- a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/VisibleRegionDemoActivity.java +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/VisibleRegionDemoActivity.java @@ -1,10 +1,3 @@ -/** - * DO NOT EDIT THIS FILE. - * - * This source code was autogenerated from source code within the `app/src/gms` directory - * and is not intended for modifications. If any edits should be made, please do so in the - * corresponding file under the `app/src/gms` directory. - */ // Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,14 +25,13 @@ import com.google.android.libraries.maps.model.MarkerOptions; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.view.animation.Interpolator; import android.view.animation.OvershootInterpolator; import android.widget.TextView; import android.widget.Toast; -import androidx.appcompat.app.AppCompatActivity; - /** * This shows how to use setPadding to allow overlays that obscure part of the map without * obscuring the map UI or copyright notices. diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/anim/AnimationManager.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/anim/AnimationManager.java new file mode 100644 index 00000000..db3c9f42 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/anim/AnimationManager.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.anim; + +import android.os.Handler; +import android.os.Looper; + +/** Simple manager for UI-thread animation. All methods must be invoked on the UI thread only. */ +public class AnimationManager { + private static final double INITIAL_FRAME_RATE_FPS = 60.0; + + private final Handler animationHandler; + private final Runnable animationRunnable; + + private double frameRateFps; + private boolean running; + + public AnimationManager(final Runnable frameRunnable) { + frameRateFps = INITIAL_FRAME_RATE_FPS; + running = false; + animationHandler = new Handler(Looper.getMainLooper()); + + animationRunnable = + () -> { + if (!running) { + return; + } + frameRunnable.run(); + requestAnimationFrame(); + }; + } + + private void requestAnimationFrame() { + if (frameRateFps <= 0.0) { + return; + } + + long delayMs = (long) Math.floor(1000.0 / frameRateFps); + animationHandler.postDelayed(animationRunnable, delayMs); + } + + public void startAnimation() { + if (running) { + return; + } + + requestAnimationFrame(); + running = true; + } + + public void stopAnimation() { + if (!running) { + return; + } + + animationHandler.removeCallbacks(animationRunnable); + running = false; + } + + public void setFrameRateFps(double frameRateFps) { + this.frameRateFps = frameRateFps; + } + + public double getFrameRateFps() { + return frameRateFps; + } +} \ No newline at end of file diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/model/MoveDirection.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/model/MoveDirection.java new file mode 100644 index 00000000..d24b2dae --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/model/MoveDirection.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.model; + +import com.google.android.libraries.maps.model.LatLng; +import java.util.ArrayList; +import java.util.List; + +/** + * Helper to translate all given LatLngs by the same amount in one of the predefined directions. + */ +public enum MoveDirection { + UP(1, 0), + DOWN(-1, 0), + LEFT(0, -1), + RIGHT(0, 1); + + private final int numLatSteps; + private final int numLngSteps; + + MoveDirection(int numLatSteps, int numLngSteps) { + this.numLatSteps = numLatSteps; + this.numLngSteps = numLngSteps; + } + + public double getLatDistance(double stepSizeDeg) { + return numLatSteps * stepSizeDeg; + } + + public double getLngDistance(double stepSizeDeg) { + return numLngSteps * stepSizeDeg; + } + + private static LatLng movePoint(LatLng oldPoint, double latMoveDistance, + double lngMoveDistance) { + return new LatLng(oldPoint.latitude + latMoveDistance, + oldPoint.longitude + lngMoveDistance); + } + + public static List movePointsInList( + List oldPoints, double latMoveDistance, double lngMoveDistance) { + List newPoints = new ArrayList<>(oldPoints.size()); + for (LatLng oldPoint : oldPoints) { + newPoints.add(movePoint(oldPoint, latMoveDistance, lngMoveDistance)); + } + + return newPoints; + } + + public static List> movePointsInNestedList( + List> oldPointLists, double latMoveDistance, double lngMoveDistance) { + List> newPointLists = new ArrayList<>(oldPointLists.size()); + for (List oldPointList : oldPointLists) { + newPointLists.add(movePointsInList(oldPointList, latMoveDistance, lngMoveDistance)); + } + + return newPointLists; + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineCapControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineCapControlFragment.java new file mode 100644 index 00000000..3979037b --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineCapControlFragment.java @@ -0,0 +1,168 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioGroup; +import android.widget.RadioGroup.OnCheckedChangeListener; +import com.example.mapdemo.R; +import com.google.android.libraries.maps.model.BitmapDescriptorFactory; +import com.google.android.libraries.maps.model.ButtCap; +import com.google.android.libraries.maps.model.Cap; +import com.google.android.libraries.maps.model.CustomCap; +import com.google.android.libraries.maps.model.RoundCap; +import com.google.android.libraries.maps.model.SquareCap; +import java.util.HashMap; +import java.util.Map; + +/** + * Fragment with "cap" UI controls for Polylines, to be used in ViewPager. + */ +public class PolylineCapControlFragment extends PolylineControlFragment implements + OnCheckedChangeListener { + + // We require Ook's refWidth > chevron's refWidth so isOok(CustomCap) can distinguish + // between the two CustomCaps by simple comparison of CustomCap.getBitmapRefWidth() against + // CHEVRON_VERSUS_OOK_REF_WIDTH_THRESHOLD, for the purpose of refreshing "cap" UI radio + // buttons. See isOok() for details on why this is necessary. + private static final float CHEVRON_REF_WIDTH = 15.0f; + private static final float OOK_REF_WIDTH = 32.0f; + private static final float CHEVRON_VERSUS_OOK_REF_WIDTH_THRESHOLD = + 0.5f * (CHEVRON_REF_WIDTH + OOK_REF_WIDTH); + + private final Map radioIdToStartCap = new HashMap<>(); + private final Map radioIdToEndCap = new HashMap<>(); + + private RadioGroup startCapRadioGroup; + private RadioGroup endCapRadioGroup; + + public PolylineCapControlFragment() { + radioIdToStartCap.put(R.id.start_cap_radio_butt, new ButtCap()); + radioIdToStartCap.put(R.id.start_cap_radio_square, new SquareCap()); + radioIdToStartCap.put(R.id.start_cap_radio_round, new RoundCap()); + radioIdToStartCap.put( + R.id.start_cap_radio_custom_chevron, + new CustomCap(BitmapDescriptorFactory.fromResource(R.drawable.chevron), + CHEVRON_REF_WIDTH)); + radioIdToStartCap.put( + R.id.start_cap_radio_custom_ook, + new CustomCap(BitmapDescriptorFactory.fromResource(R.drawable.ook), OOK_REF_WIDTH)); + + radioIdToEndCap.put(R.id.end_cap_radio_butt, new ButtCap()); + radioIdToEndCap.put(R.id.end_cap_radio_square, new SquareCap()); + radioIdToEndCap.put(R.id.end_cap_radio_round, new RoundCap()); + radioIdToEndCap.put( + R.id.end_cap_radio_custom_chevron, + new CustomCap(BitmapDescriptorFactory.fromResource(R.drawable.chevron), + CHEVRON_REF_WIDTH)); + radioIdToEndCap.put( + R.id.end_cap_radio_custom_ook, + new CustomCap(BitmapDescriptorFactory.fromResource(R.drawable.ook), OOK_REF_WIDTH)); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_cap_control_fragment, container, false); + + startCapRadioGroup = view.findViewById(R.id.start_cap_radio); + endCapRadioGroup = view.findViewById(R.id.end_cap_radio); + + startCapRadioGroup.setOnCheckedChangeListener(this); + endCapRadioGroup.setOnCheckedChangeListener(this); + return view; + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + if (polyline == null) { + return; + } + + int groupId = group.getId(); + if (groupId == R.id.start_cap_radio) { + Cap startCap = radioIdToStartCap.get(checkedId); + if (startCap != null) { + polyline.setStartCap(startCap); + } + } else if (groupId == R.id.end_cap_radio) { + Cap endCap = radioIdToEndCap.get(checkedId); + if (endCap != null) { + polyline.setEndCap(endCap); + } + } + } + + @Override + public void refresh() { + if (polyline == null) { + startCapRadioGroup.clearCheck(); + for (int i = 0; i < startCapRadioGroup.getChildCount(); i++) { + startCapRadioGroup.getChildAt(i).setEnabled(false); + } + endCapRadioGroup.clearCheck(); + for (int i = 0; i < endCapRadioGroup.getChildCount(); i++) { + endCapRadioGroup.getChildAt(i).setEnabled(false); + } + return; + } + + for (int i = 0; i < startCapRadioGroup.getChildCount(); i++) { + startCapRadioGroup.getChildAt(i).setEnabled(true); + } + Cap startCap = polyline.getStartCap(); + if (startCap instanceof ButtCap) { + startCapRadioGroup.check(R.id.start_cap_radio_butt); + } else if (startCap instanceof SquareCap) { + startCapRadioGroup.check(R.id.start_cap_radio_square); + } else if (startCap instanceof RoundCap) { + startCapRadioGroup.check(R.id.start_cap_radio_round); + } else if (startCap instanceof CustomCap) { + startCapRadioGroup.check( + isOok((CustomCap) startCap) + ? R.id.start_cap_radio_custom_ook + : R.id.start_cap_radio_custom_chevron); + } else { + startCapRadioGroup.clearCheck(); + } + + for (int i = 0; i < endCapRadioGroup.getChildCount(); i++) { + endCapRadioGroup.getChildAt(i).setEnabled(true); + } + Cap endCap = polyline.getEndCap(); + if (endCap instanceof ButtCap) { + endCapRadioGroup.check(R.id.end_cap_radio_butt); + } else if (endCap instanceof SquareCap) { + endCapRadioGroup.check(R.id.end_cap_radio_square); + } else if (endCap instanceof RoundCap) { + endCapRadioGroup.check(R.id.end_cap_radio_round); + } else if (endCap instanceof CustomCap) { + endCapRadioGroup.check( + isOok((CustomCap) endCap) + ? R.id.end_cap_radio_custom_ook + : R.id.end_cap_radio_custom_chevron); + } else { + endCapRadioGroup.clearCheck(); + } + } + + private static boolean isOok(CustomCap customCap) { + return (customCap.refWidth >= CHEVRON_VERSUS_OOK_REF_WIDTH_THRESHOLD); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineColorControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineColorControlFragment.java new file mode 100644 index 00000000..e3368ee8 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineColorControlFragment.java @@ -0,0 +1,104 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.TextView; +import com.example.mapdemo.R; + +/** Fragment with "color" UI controls for Polylines, to be used in ViewPager. */ +public class PolylineColorControlFragment extends PolylineControlFragment implements OnSeekBarChangeListener { + private static final int HUE_MAX = 359; + private static final int ALPHA_MAX = 255; + + private SeekBar alphaBar; + private SeekBar hueBar; + private TextView argbTextView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_color_control_fragment, container, false); + + alphaBar = view.findViewById(R.id.alphaSeekBar); + alphaBar.setMax(ALPHA_MAX); + alphaBar.setOnSeekBarChangeListener(this); + + hueBar = view.findViewById(R.id.hueSeekBar); + hueBar.setMax(HUE_MAX); + hueBar.setOnSeekBarChangeListener(this); + + argbTextView = (TextView) view.findViewById(R.id.argbTextView); + return view; + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (polyline == null || !fromUser) { + return; + } + + if (seekBar == hueBar) { + polyline.setColor( + Color.HSVToColor(Color.alpha(polyline.getColor()), new float[] {progress, 1, 1})); + } else if (seekBar == alphaBar) { + float[] prevHSV = new float[3]; + Color.colorToHSV(polyline.getColor(), prevHSV); + polyline.setColor(Color.HSVToColor(progress, prevHSV)); + } + + argbTextView.setText(String.format("0x%08X", polyline.getColor())); + } + + @Override + public void refresh() { + if (polyline == null) { + alphaBar.setEnabled(false); + alphaBar.setProgress(0); + hueBar.setEnabled(false); + hueBar.setProgress(0); + argbTextView.setText(""); + return; + } + + int color = polyline.getColor(); + alphaBar.setEnabled(true); + alphaBar.setProgress(Color.alpha(color)); + + float[] hsv = new float[3]; + Color.colorToHSV(color, hsv); + hueBar.setEnabled(true); + hueBar.setProgress((int) hsv[0]); + + argbTextView.setText(String.format("0x%08X", color)); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragment.java new file mode 100644 index 00000000..2cb6779c --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragment.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import androidx.fragment.app.Fragment; +import com.google.android.libraries.maps.model.Polyline; + +public abstract class PolylineControlFragment extends Fragment { + protected Polyline polyline; + + public void setPolyline(Polyline polyline) { + this.polyline = polyline; + refresh(); + } + + public abstract void refresh(); +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragmentPagerAdapter.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragmentPagerAdapter.java new file mode 100644 index 00000000..21250065 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineControlFragmentPagerAdapter.java @@ -0,0 +1,109 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.view.ViewGroup; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import java.util.HashMap; +import java.util.Map; + +public class PolylineControlFragmentPagerAdapter extends FragmentPagerAdapter { + private static final int NUM_ITEMS = 8; + + private final Map positionsToFragments; + private final boolean isLiteMode; + + public PolylineControlFragmentPagerAdapter(FragmentManager fragmentManager, boolean isLiteMode) { + super(fragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); + positionsToFragments = new HashMap<>(); + this.isLiteMode = isLiteMode; + } + + @Override + public int getCount() { + return NUM_ITEMS; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + PolylineControlFragment fragment = + (PolylineControlFragment) super.instantiateItem(container, position); + positionsToFragments.put(position, fragment); + return fragment; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + super.destroyItem(container, position, object); + positionsToFragments.remove(position); + } + + @Override + public Fragment getItem(int position) { + switch (position) { + case 0: + return new PolylineColorControlFragment(); + case 1: + return new PolylineWidthControlFragment(); + case 2: + return new PolylineCapControlFragment(); + case 3: + return new PolylineJointControlFragment(); + case 4: + return new PolylinePatternControlFragment(); + case 5: + return new PolylinePointsControlFragment(); + case 6: + return PolylineSpansControlFragment.newInstance(isLiteMode); + case 7: + return new PolylineOtherOptionsControlFragment(); + default: + return new Fragment(); + } + } + + @Override + public CharSequence getPageTitle(int position) { + // Ideally these strings should be localised, but let's not bother for a demo app. + switch (position) { + case 0: + return "Color"; + case 1: + return "Width"; + case 2: + return "Cap"; + case 3: + return "Joint"; + case 4: + return "Pattern"; + case 5: + return "Points"; + case 6: + return "Spans"; + case 7: + return "Other Options"; + default: + return null; + } + } + + public PolylineControlFragment getFragmentAtPosition(int position) { + return positionsToFragments.get(position); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineDemoActivity.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineDemoActivity.java new file mode 100644 index 00000000..8703f043 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineDemoActivity.java @@ -0,0 +1,215 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.graphics.Color; +import android.os.Bundle; +import android.widget.RadioGroup; +import android.widget.RadioGroup.OnCheckedChangeListener; +import androidx.appcompat.app.AppCompatActivity; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager.widget.ViewPager.OnPageChangeListener; +import com.example.mapdemo.R; +import com.google.android.libraries.maps.CameraUpdateFactory; +import com.google.android.libraries.maps.GoogleMap; +import com.google.android.libraries.maps.GoogleMap.OnPolylineClickListener; +import com.google.android.libraries.maps.OnMapReadyCallback; +import com.google.android.libraries.maps.SupportMapFragment; +import com.google.android.libraries.maps.model.Dash; +import com.google.android.libraries.maps.model.Dot; +import com.google.android.libraries.maps.model.Gap; +import com.google.android.libraries.maps.model.LatLng; +import com.google.android.libraries.maps.model.Polyline; +import com.google.android.libraries.maps.model.PolylineOptions; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * This shows how to apply multiple colors on a polyline. + */ +public class PolylineDemoActivity extends AppCompatActivity implements + OnMapReadyCallback, OnPageChangeListener, OnCheckedChangeListener, OnPolylineClickListener { + + public static final String TAG = PolylineDemoActivity.class.getSimpleName(); + + private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298); + private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689); + private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995); + private static final LatLng PERTH = new LatLng(-31.95285, 115.85734); + private static final LatLng LONDON = new LatLng(51.471547, -0.460052); + private static final LatLng LOS_ANGELES = new LatLng(33.936524, -118.377686); + private static final LatLng NEW_YORK = new LatLng(40.641051, -73.777485); + private static final LatLng AUCKLAND = new LatLng(-37.006254, 174.783018); + + private Polyline australiaPolyline; + private Polyline melbournePolyline; + private Polyline sydneyPolyline; + private Polyline worldPolyline; + private Polyline selectedPolyline; + + private ViewPager pager; // TODO use ViewPager2 + private PolylineControlFragmentPagerAdapter pagerAdapter; + private RadioGroup polylineRadio; + + private final Set spanResetPolylines = new HashSet<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.polyline_demo); + + pagerAdapter = + new PolylineControlFragmentPagerAdapter( + getSupportFragmentManager(), /* isLiteMode= */ false); + pager = findViewById(R.id.pager); + pager.setAdapter(pagerAdapter); + + // onPageSelected(0) isn't invoked once views are ready, so post a Runnable to + // refreshControlPanel() for the first time instead... + pager.post(this::refreshControlPanel); + + polylineRadio = findViewById(R.id.polyline_radio); + + SupportMapFragment mapFragment = + (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(GoogleMap map) { + // For accessibility mode. Ideally this string would be localised. + map.setContentDescription("Google Map with polylines."); + + // Non-loop polyline that goes past Australian cities. Added before sydneyPolyline and would + // normally be underneath, but increase Z-Index so that this line is on top. + australiaPolyline = + map.addPolyline( + new PolylineOptions() + .add(PERTH, ADELAIDE, SYDNEY, MELBOURNE) + .pattern(Arrays.asList(new Dot(), new Gap(20.0f))) + .color(Color.MAGENTA) + .zIndex(1)); + + // Geodesic polyline that goes around the world. + worldPolyline = + map.addPolyline( + new PolylineOptions() + .add(LONDON, AUCKLAND, LOS_ANGELES, NEW_YORK, LONDON) + .width(5) + .color(Color.BLUE) + .geodesic(true) + .clickable(true)); + + // Loop polyline centered at Sydney. + int radius = 4; + sydneyPolyline = + map.addPolyline( + new PolylineOptions() + .add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)) + .add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude - radius)) + .add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude - radius)) + .add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude)) + .add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude + radius)) + .add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)) + .pattern(Arrays.asList(new Dash(45.0f), new Gap(10.0f))) + .color(Color.RED) + .width(5) + .clickable(true)); + + // Create Melbourne polyline to show layering of polylines with same Z-Index. This is added + // second so it will be layered on top of the Sydney polyline (both have Z-Index == 0). + melbournePolyline = + map.addPolyline( + new PolylineOptions() + .add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)) + .add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude - radius)) + .add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude - radius)) + .add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude)) + .add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude + radius)) + .add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)) + .color(Color.GREEN) + .width(5) + .clickable(true)); + + map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY)); + selectedPolyline = australiaPolyline; + polylineRadio.check(R.id.polyline_radio_australia); + + pager.addOnPageChangeListener(this); + polylineRadio.setOnCheckedChangeListener(this); + map.setOnPolylineClickListener(this); + } + + @Override + public void onPolylineClick(Polyline polyline) { + // Flip the values of the r, g and b components of the polyline's color. + int strokeColor = polyline.getColor() ^ 0x00ffffff; + polyline.setColor(strokeColor); + polyline.setSpans(new ArrayList<>()); + spanResetPolylines.add(polyline); + refreshControlPanel(); + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + if (checkedId == R.id.polyline_radio_australia) { + selectedPolyline = australiaPolyline; + } else if (checkedId == R.id.polyline_radio_sydney) { + selectedPolyline = sydneyPolyline; + } else if (checkedId == R.id.polyline_radio_melbourne) { + selectedPolyline = melbournePolyline; + } else if (checkedId == R.id.polyline_radio_world) { + selectedPolyline = worldPolyline; + } + refreshControlPanel(); + } + + @Override + public void onPageSelected(int position) { + refreshControlPanel(); + } + + private void refreshControlPanel() { + PolylineControlFragment fragment = pagerAdapter.getFragmentAtPosition(pager.getCurrentItem()); + if (fragment != null) { + if (fragment instanceof PolylineSpansControlFragment + && spanResetPolylines.contains(selectedPolyline)) { + PolylineSpansControlFragment spansControlFragment = (PolylineSpansControlFragment) fragment; + spansControlFragment.resetSpanState(selectedPolyline); + spanResetPolylines.remove(selectedPolyline); + } + fragment.setPolyline(selectedPolyline); + } + } + + @Override + public void onPageScrollStateChanged(int state) { + // Don't do anything here. + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + // Don't do anything here. + } + + @Override + public void onPointerCaptureChanged(boolean hasCapture) { + + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineJointControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineJointControlFragment.java new file mode 100644 index 00000000..01424728 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineJointControlFragment.java @@ -0,0 +1,93 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RadioGroup; +import android.widget.RadioGroup.OnCheckedChangeListener; +import com.example.mapdemo.R; +import com.google.android.libraries.maps.model.JointType; +import java.util.HashMap; +import java.util.Map; + +/** + * Fragment with "joint" UI controls for Polylines, to be used in ViewPager. + */ +public class PolylineJointControlFragment extends PolylineControlFragment implements + OnCheckedChangeListener { + + private final Map radioIdToJointType = new HashMap<>(); + private RadioGroup jointRadioGroup; + + public PolylineJointControlFragment() { + radioIdToJointType.put(R.id.joint_radio_default, JointType.DEFAULT); + radioIdToJointType.put(R.id.joint_radio_bevel, JointType.BEVEL); + radioIdToJointType.put(R.id.joint_radio_round, JointType.ROUND); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_joint_control_fragment, container, false); + jointRadioGroup = view.findViewById(R.id.joint_radio); + jointRadioGroup.setOnCheckedChangeListener(this); + return view; + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + if (polyline == null) { + return; + } + + Integer jointType = radioIdToJointType.get(checkedId); + if (jointType != null) { + polyline.setJointType(jointType); + } + } + + @Override + public void refresh() { + if (polyline == null) { + jointRadioGroup.clearCheck(); + for (int i = 0; i < jointRadioGroup.getChildCount(); i++) { + jointRadioGroup.getChildAt(i).setEnabled(false); + } + return; + } + + for (int i = 0; i < jointRadioGroup.getChildCount(); i++) { + jointRadioGroup.getChildAt(i).setEnabled(true); + } + + switch (polyline.getJointType()) { + case JointType.DEFAULT: + jointRadioGroup.check(R.id.joint_radio_default); + break; + case JointType.BEVEL: + jointRadioGroup.check(R.id.joint_radio_bevel); + break; + case JointType.ROUND: + jointRadioGroup.check(R.id.joint_radio_round); + break; + default: + jointRadioGroup.clearCheck(); + } + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineOtherOptionsControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineOtherOptionsControlFragment.java new file mode 100644 index 00000000..75880b69 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineOtherOptionsControlFragment.java @@ -0,0 +1,54 @@ +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import com.example.mapdemo.R; + +/** + * Fragment with clickability, geodesic, and visibility UI controls for Polylines, to be used in + * ViewPager. + */ +public class PolylineOtherOptionsControlFragment extends PolylineControlFragment + implements View.OnClickListener { + + private CheckBox clickabilityCheckBox; + private CheckBox geodesicCheckBox; + private CheckBox visibilityCheckBox; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_other_options_control_fragment, container, false); + clickabilityCheckBox = view.findViewById(R.id.clickabilityCheckBox); + clickabilityCheckBox.setOnClickListener(this); + geodesicCheckBox = view.findViewById(R.id.geodesicCheckBox); + geodesicCheckBox.setOnClickListener(this); + visibilityCheckBox = view.findViewById(R.id.visibilityCheckBox); + visibilityCheckBox.setOnClickListener(this); + return view; + } + + @Override + public void onClick(View view) { + if (polyline == null) { + return; + } + if (view == clickabilityCheckBox) { + polyline.setClickable(clickabilityCheckBox.isChecked()); + } else if (view == geodesicCheckBox) { + polyline.setGeodesic(geodesicCheckBox.isChecked()); + } else if (view == visibilityCheckBox) { + polyline.setVisible(visibilityCheckBox.isChecked()); + } + } + + @Override + public void refresh() { + clickabilityCheckBox.setChecked((polyline != null) && polyline.isClickable()); + geodesicCheckBox.setChecked((polyline != null) && polyline.isGeodesic()); + visibilityCheckBox.setChecked((polyline != null) && polyline.isVisible()); + } +} + diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePatternControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePatternControlFragment.java new file mode 100644 index 00000000..497703bb --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePatternControlFragment.java @@ -0,0 +1,133 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import com.example.mapdemo.R; +import com.google.android.libraries.maps.model.Dash; +import com.google.android.libraries.maps.model.Dot; +import com.google.android.libraries.maps.model.Gap; +import com.google.android.libraries.maps.model.PatternItem; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +/** Fragment with "pattern" UI controls for Polylines, to be used in ViewPager. */ +public class PolylinePatternControlFragment extends PolylineControlFragment implements + OnClickListener { + + private static final int MAX_PATTERN_SIZE = 6; + private static final int MAX_DASH_LENGTH = 200; + private static final int MAX_GAP_LENGTH = 100; + private static final Random RANDOM = new Random(); + + private Button patternSolidBtn; + private Button patternDottedBtn; + private Button patternDashedBtn; + private Button patternMixedBtn; + private TextView patternTextView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_pattern_control_fragment, container, false); + patternTextView = view.findViewById(R.id.patternTextView); + + patternSolidBtn = view.findViewById(R.id.patternSolidBtn); + patternDottedBtn = view.findViewById(R.id.patternDottedBtn); + patternDashedBtn = view.findViewById(R.id.patternDashedBtn); + patternMixedBtn = view.findViewById(R.id.patternMixedBtn); + + patternSolidBtn.setOnClickListener(this); + patternDottedBtn.setOnClickListener(this); + patternDashedBtn.setOnClickListener(this); + patternMixedBtn.setOnClickListener(this); + return view; + } + + @Override + public void onClick(View view) { + if (polyline == null) { + return; + } + + int id = view.getId(); + List pattern; + if (id == R.id.patternSolidBtn) { + pattern = null; + } else if (id == R.id.patternDottedBtn) { + pattern = Arrays.asList(new Dot(), new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH)); + } else if (id == R.id.patternDashedBtn) { + pattern = + Arrays.asList( + new Dash(RANDOM.nextFloat() * MAX_DASH_LENGTH), + new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH)); + } else if (id == R.id.patternMixedBtn) { + int size = 2 * (1 + RANDOM.nextInt(MAX_PATTERN_SIZE / 2)); + pattern = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + if ((i % 2) == 0) { + pattern.add( + RANDOM.nextBoolean() ? new Dot() : new Dash(RANDOM.nextFloat() * MAX_DASH_LENGTH)); + } else { + pattern.add(new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH)); + } + } + } else { + throw new IllegalStateException("Unknown button"); + } + + polyline.setPattern(pattern); + patternTextView.setText(toString(pattern)); + } + + @Override + public void refresh() { + boolean enabled = (polyline != null); + patternSolidBtn.setEnabled(enabled); + patternDottedBtn.setEnabled(enabled); + patternDashedBtn.setEnabled(enabled); + patternMixedBtn.setEnabled(enabled); + patternTextView.setText((polyline == null) ? "" : toString(polyline.getPattern())); + } + + private static String toString(List pattern) { + if (pattern == null) { + return ""; + } + + StringBuilder sb = new StringBuilder(""); + for (PatternItem item : pattern) { + if (item instanceof Dot) { + sb.append("DOT"); + } else if (item instanceof Dash) { + sb.append(String.format("%.1fpx-DASH", ((Dash) item).length)); + } else if (item instanceof Gap) { + sb.append(String.format("%.1fpx-GAP", ((Gap) item).length)); + } + sb.append(" "); + } + sb.append(""); + return sb.toString(); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePointsControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePointsControlFragment.java new file mode 100644 index 00000000..766b7a13 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylinePointsControlFragment.java @@ -0,0 +1,169 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.TextView; +import com.example.mapdemo.R; +import com.example.mapdemo.anim.AnimationManager; +import com.example.mapdemo.model.MoveDirection; +import com.google.android.libraries.maps.model.LatLng; +import java.util.List; + +/** Fragment with "points" UI controls for Polylines, to be used in ViewPager. */ +public class PolylinePointsControlFragment extends PolylineControlFragment implements View.OnTouchListener, View.OnFocusChangeListener, TextView.OnEditorActionListener { + + private MoveDirection moveDirection; + private double stepSizeDeg; + private List originalPoints; + private double latDistance = 0; + private double lngDistance = 0; + + private final AnimationManager animationManager = + new AnimationManager( + new Runnable() { + @Override + public void run() { + if ((polyline == null) || (moveDirection == null)) { + return; + } + // When the polyline moves offscreen, its coordinates will be clamped and caused the + // shape to change. Using the original points for computing new points to make sure + // the shape can be retained after the polyline moves offscreen. + latDistance += moveDirection.getLatDistance(stepSizeDeg); + lngDistance += moveDirection.getLngDistance(stepSizeDeg); + polyline.setPoints( + MoveDirection.movePointsInList(originalPoints, latDistance, lngDistance)); + } + }); + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_points_control_fragment, container, false); + + view.findViewById(R.id.move_up).setOnTouchListener(this); + view.findViewById(R.id.move_down).setOnTouchListener(this); + view.findViewById(R.id.move_left).setOnTouchListener(this); + view.findViewById(R.id.move_right).setOnTouchListener(this); + + EditText fpsEditText = (EditText) view.findViewById(R.id.fps_edittext); + fpsEditText.setOnEditorActionListener(this); + fpsEditText.setOnFocusChangeListener(this); + setFrameRate(fpsEditText); + + EditText stepEditText = (EditText) view.findViewById(R.id.step_edittext); + stepEditText.setOnEditorActionListener(this); + stepEditText.setOnFocusChangeListener(this); + setStepSize(stepEditText); + + moveDirection = null; + return view; + } + + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + setMoveDirection(view.getId()); + animationManager.startAnimation(); + return true; + case MotionEvent.ACTION_CANCEL: + case MotionEvent.ACTION_UP: + moveDirection = null; + animationManager.stopAnimation(); + return true; + default: + return false; + } + } + + private void setMoveDirection(int buttonId) { + if (buttonId == R.id.move_up) { + moveDirection = MoveDirection.UP; + } else if (buttonId == R.id.move_down) { + moveDirection = MoveDirection.DOWN; + } else if (buttonId == R.id.move_left) { + moveDirection = MoveDirection.LEFT; + } else if (buttonId == R.id.move_right) { + moveDirection = MoveDirection.RIGHT; + } else { + moveDirection = null; + } + } + + @Override + public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) { + // Only handle "Done" action triggered by the user tapping "Enter" on the keyboard. + if (actionId != EditorInfo.IME_ACTION_DONE) { + return false; + } + + int textViewId = textView.getId(); + if (textViewId == R.id.fps_edittext) { + setFrameRate(textView); + } else if (textViewId == R.id.step_edittext) { + setStepSize(textView); + } + return false; + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (hasFocus) { + return; + } + + int viewId = view.getId(); + if (viewId == R.id.fps_edittext) { + setFrameRate((TextView) view); + } else if (viewId == R.id.step_edittext) { + setStepSize((TextView) view); + } + } + + private void setFrameRate(TextView textView) { + String newValue = String.valueOf(textView.getText()); + try { + animationManager.setFrameRateFps(Double.parseDouble(newValue)); + } catch (NumberFormatException e) { + textView.setText(Double.toString(animationManager.getFrameRateFps())); + } + } + + private void setStepSize(TextView textView) { + String newValue = String.valueOf(textView.getText()); + try { + stepSizeDeg = Double.parseDouble(newValue); + } catch (NumberFormatException e) { + textView.setText(Double.toString(stepSizeDeg)); + } + } + + @Override + public void refresh() { + latDistance = 0; + lngDistance = 0; + originalPoints = polyline.getPoints(); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineSpansControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineSpansControlFragment.java new file mode 100644 index 00000000..4352c90e --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineSpansControlFragment.java @@ -0,0 +1,207 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CompoundButton; +import android.widget.RadioGroup; +import android.widget.SeekBar; +import android.widget.TextView; +import com.example.mapdemo.R; +import com.google.android.libraries.maps.model.BitmapDescriptorFactory; +import com.google.android.libraries.maps.model.Polyline; +import com.google.android.libraries.maps.model.StrokeStyle; +import com.google.android.libraries.maps.model.StyleSpan; +import com.google.android.libraries.maps.model.TextureStyle; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Fragment with span count UI controls for {@link com.google.android.libraries.maps.model.Polyline}, to + * be used in ViewPager. + * + *

When span count is updated from the slider, the selected polyline will be updated with that + * number of spans. Each span will either have polyline color or the inverted color, and span + * lengths are equally divided by number of segments in the polyline. + */ +public class PolylineSpansControlFragment extends PolylineControlFragment + implements SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener { + + private static final String IS_LITE_MODE_KEY = "isLiteMode"; + private static final int SPAN_COUNT_MAX = 20; + private SeekBar spanCountBar; + private TextView spanCountTextView; + private CompoundButton gradientToggle; + private int spanCount = 0; + private final Map polylineSpanCounts = new HashMap<>(); + private final Map polylineGradientStates = new HashMap<>(); + private boolean isLiteMode = false; + private int selectedStampStyleId; + private RadioGroup polylineStampStyleRadioGroup; + + static PolylineSpansControlFragment newInstance(boolean isLiteMode) { + PolylineSpansControlFragment polylineSpansControlFragment = new PolylineSpansControlFragment(); + + Bundle args = new Bundle(); + args.putBoolean(IS_LITE_MODE_KEY, isLiteMode); + polylineSpansControlFragment.setArguments(args); + + return polylineSpansControlFragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + isLiteMode = getArguments().getBoolean(IS_LITE_MODE_KEY); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_spans_control_fragment, container, false); + + spanCountBar = view.findViewById(R.id.spansSeekBar); + spanCountBar.setMax(SPAN_COUNT_MAX); + spanCountBar.setOnSeekBarChangeListener(this); + + spanCountTextView = view.findViewById(R.id.spansTextView); + + gradientToggle = view.findViewById(R.id.gradientToggle); + gradientToggle.setOnCheckedChangeListener( + (buttonView, isChecked) -> { + polylineGradientStates.put(polyline, isChecked); + updateSpans(); + }); + + polylineStampStyleRadioGroup = view.findViewById(R.id.polyline_stamp_style_radio_group); + polylineStampStyleRadioGroup.setVisibility(View.INVISIBLE); + + if (isLiteMode) { + gradientToggle.setVisibility(View.INVISIBLE); + polylineStampStyleRadioGroup.setVisibility(View.INVISIBLE); + } + + polylineSpanCounts.clear(); + polylineGradientStates.clear(); + selectedStampStyleId = 0; + polylineStampStyleRadioGroup.setOnCheckedChangeListener(this); + return view; + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + spanCount = progress; + polylineSpanCounts.put(polyline, spanCount); + spanCountTextView.setText(String.valueOf(spanCount)); + updateSpans(); + } + + private List generateSpans(int count) { + int invertedPolylineColor = polyline.getColor() ^ 0x00ffffff; + List newSpans = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + int color = i % 2 == 0 ? polyline.getColor() : invertedPolylineColor; + double segmentCount = (double) (polyline.getPoints().size() - 1) / count; + StrokeStyle.Builder strokeStyleBuilder = + gradientToggle.isChecked() + ? StrokeStyle.gradientBuilder(polyline.getColor(), invertedPolylineColor) + : StrokeStyle.colorBuilder(color); + + if (selectedStampStyleId == R.id.polyline_texture_style) { + strokeStyleBuilder.stamp( + TextureStyle.newBuilder(BitmapDescriptorFactory.fromResource(R.drawable.ook)) + .build()); + } + + newSpans.add(new StyleSpan(strokeStyleBuilder.build(), segmentCount)); + } + return newSpans; + } + + private void updateSpans() { + if (polyline == null) { + return; + } + + polyline.setSpans(generateSpans(spanCount)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void refresh() { + if (polyline == null) { + spanCountBar.setEnabled(false); + spanCountBar.setProgress(0); + spanCountTextView.setText(""); + gradientToggle.setChecked(false); + gradientToggle.setEnabled(false); + polylineStampStyleRadioGroup.clearCheck(); + polylineStampStyleRadioGroup.setEnabled(false); + return; + } + + if (!polylineSpanCounts.containsKey(polyline)) { + polylineSpanCounts.put(polyline, 0); + } + if (!polylineGradientStates.containsKey(polyline)) { + polylineGradientStates.put(polyline, false); + } + + spanCountBar.setEnabled(true); + spanCountBar.setProgress(polylineSpanCounts.get(polyline)); + spanCountTextView.setText(String.valueOf(polylineSpanCounts.get(polyline))); + + if (!isLiteMode) { + gradientToggle.setEnabled(true); + gradientToggle.setChecked(polylineGradientStates.get(polyline)); + + polylineStampStyleRadioGroup.setEnabled(true); + polylineStampStyleRadioGroup.check(selectedStampStyleId); + } + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + selectedStampStyleId = checkedId; + updateSpans(); + } + + /** + * Resets the span states of a polyline. + * + *

Because there's no getter for polyline spans, this is needed for the polyline demo + * activity + * to update span control UI components. + */ + void resetSpanState(Polyline polyline) { + polylineSpanCounts.remove(polyline); + polylineGradientStates.remove(polyline); + } +} diff --git a/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineWidthControlFragment.java b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineWidthControlFragment.java new file mode 100644 index 00000000..b69348d4 --- /dev/null +++ b/ApiDemos/java/app/src/v3/java/com/example/mapdemo/polyline/PolylineWidthControlFragment.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.mapdemo.polyline; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.SeekBar; +import android.widget.TextView; +import com.example.mapdemo.R; + +/** + * Fragment with "width" UI controls for Polylines, to be used in ViewPager. + */ +public class PolylineWidthControlFragment extends PolylineControlFragment implements + SeekBar.OnSeekBarChangeListener { + + private static final int WIDTH_MAX = 50; + private SeekBar widthBar; + private TextView widthTextView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.polyline_width_control_fragment, container, false); + widthBar = view.findViewById(R.id.widthSeekBar); + widthBar.setMax(WIDTH_MAX); + widthBar.setOnSeekBarChangeListener(this); + widthTextView = view.findViewById(R.id.widthTextView); + return view; + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Don't do anything here. + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (polyline == null) { + return; + } + + polyline.setWidth(progress); + widthTextView.setText(polyline.getWidth() + "px"); + } + + @Override + public void refresh() { + if (polyline == null) { + widthBar.setEnabled(false); + widthBar.setProgress(0); + widthTextView.setText(""); + return; + } + + widthBar.setEnabled(true); + float width = polyline.getWidth(); + widthBar.setProgress((int) width); + widthTextView.setText(width + "px"); + } +} diff --git a/ApiDemos/java/app/src/v3/res/layout/cloud_styling_basic_demo.xml b/ApiDemos/java/app/src/v3/res/layout/cloud_styling_basic_demo.xml new file mode 100644 index 00000000..cac50733 --- /dev/null +++ b/ApiDemos/java/app/src/v3/res/layout/cloud_styling_basic_demo.xml @@ -0,0 +1,49 @@ + + + + + + +