chore: Adding kotlin demo of raw MapView.

This commit is contained in:
Chris Arriola 2020-09-08 10:19:16 -07:00
parent f4e66de6ff
commit 9a8dff4c2b
9 changed files with 296 additions and 22 deletions

View File

@ -57,6 +57,10 @@ class DemoDetailsList {
PolygonDemoActivity::class.java),
DemoDetails(R.string.polyline_demo_label, R.string.polyline_demo_description,
PolylineDemoActivity::class.java),
DemoDetails(
R.string.raw_map_view_demo_label,
R.string.raw_map_view_demo_description,
RawMapViewDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_basic_demo_label,
R.string.street_view_panorama_basic_demo_details,

View File

@ -0,0 +1,89 @@
// 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.kotlindemos
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
/**
* This shows how to create a simple activity with a raw MapView and add a marker to it. This
* requires forwarding all the important lifecycle methods onto MapView.
*/
class RawMapViewDemoActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mapView: MapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.raw_mapview_demo)
// *** IMPORTANT ***
// MapView requires that the Bundle you pass contain _ONLY_ MapView SDK
// objects or sub-Bundles.
val mapViewBundle = savedInstanceState?.getBundle(MAPVIEW_BUNDLE_KEY)
mapView = findViewById(R.id.map)
mapView.onCreate(mapViewBundle)
mapView.getMapAsync(this)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY) ?: Bundle().apply {
putBundle(MAPVIEW_BUNDLE_KEY, this)
}
mapView.onSaveInstanceState(mapViewBundle)
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onMapReady(map: GoogleMap) {
map.addMarker(MarkerOptions().position(LatLng(0.0, 0.0)).title("Marker"))
}
override fun onPause() {
mapView.onPause()
super.onPause()
}
override fun onDestroy() {
mapView.onDestroy()
super.onDestroy()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
companion object {
private const val MAPVIEW_BUNDLE_KEY = "MapViewBundleKey"
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project
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.
--><!-- This can go anywhere in your layout. -->
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -57,6 +57,7 @@
<activity android:name=".MarkerDemoActivity"/>
<activity android:name=".MyLocationDemoActivity" />
<activity android:name=".PolygonDemoActivity"/>
<activity android:name=".RawMapViewDemoActivity"/>
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />

View File

@ -234,6 +234,10 @@
<string name="cloud_styling_label">Cloud Styling</string>
<string name="cloud_styling_description">Demonstrates how to use a simple map using Cloud Styling.</string>
<!-- Raw MapView Demo -->
<string name="raw_map_view_demo_label">Raw MapView</string>
<string name="raw_map_view_demo_description">Demonstrates how to use a raw MapView.</string>
<!-- Polylines Demo -->
<string name="alpha">Alpha</string>
<string name="cap_butt">Butt</string>

View File

@ -23,7 +23,7 @@
package com.example.kotlindemos
import com.example.kotlindemos.polyline.PolylineDemoActivity;
import com.example.kotlindemos.polyline.PolylineDemoActivity
/**
* A list of all the demos we have available.
@ -31,40 +31,83 @@ import com.example.kotlindemos.polyline.PolylineDemoActivity;
class DemoDetailsList {
companion object {
val DEMOS = listOf<DemoDetails>(
DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details,
DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details,
BasicMapDemoActivity::class.java),
DemoDetails(R.string.camera_demo_label, R.string.camera_demo_description,
DemoDetails(R.string.camera_demo_label, R.string.camera_demo_description,
CameraDemoActivity::class.java),
DemoDetails(R.string.circle_demo_label, R.string.circle_demo_details,
DemoDetails(R.string.circle_demo_label, R.string.circle_demo_details,
CircleDemoActivity::class.java),
DemoDetails(R.string.close_info_window_demo_label,
DemoDetails(R.string.close_info_window_demo_label,
R.string.close_info_window_demo_details,
CloseInfoWindowDemoActivity::class.java),
DemoDetails(R.string.cloud_styling_label,
R.string.cloud_styling_description,
CloudBasedMapStylingDemoActivity::class.java),
DemoDetails(R.string.layers_demo_label, R.string.layers_demo_description,
DemoDetails(
R.string.events_demo_label,
R.string.events_demo_details,
EventsDemoActivity::class.java),
DemoDetails(
R.string.ground_overlay_demo_label,
R.string.ground_overlay_demo_details,
GroundOverlayDemoActivity::class.java),
DemoDetails(R.string.indoor_demo_label, R.string.indoor_demo_details,
IndoorDemoActivity::class.java),
DemoDetails(R.string.layers_demo_label, R.string.layers_demo_description,
LayersDemoActivity::class.java),
DemoDetails(R.string.lite_list_demo_label, R.string.lite_list_demo_details,
DemoDetails(R.string.lite_demo_label, R.string.lite_demo_details,
LiteDemoActivity::class.java),
DemoDetails(R.string.lite_list_demo_label, R.string.lite_list_demo_details,
LiteListDemoActivity::class.java),
DemoDetails(R.string.marker_collision_label,
R.string.marker_collision_description,
MarkerCollisionDemoActivity::class.java),
DemoDetails(R.string.markers_demo_label, R.string.markers_demo_description,
DemoDetails(R.string.markers_demo_label, R.string.markers_demo_description,
MarkerDemoActivity::class.java),
DemoDetails(R.string.polygon_demo_label, R.string.polygon_demo_details,
DemoDetails(R.string.my_location_demo_label, R.string.my_location_demo_details,
MyLocationDemoActivity::class.java),
DemoDetails(R.string.polygon_demo_label, R.string.polygon_demo_details,
PolygonDemoActivity::class.java),
DemoDetails(R.string.polyline_demo_label, R.string.polyline_demo_description,
PolylineDemoActivity::class.java),
DemoDetails(
DemoDetails(R.string.polyline_demo_label, R.string.polyline_demo_description,
PolylineDemoActivity::class.java),
DemoDetails(
R.string.raw_map_view_demo_label,
R.string.raw_map_view_demo_description,
RawMapViewDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_basic_demo_label,
R.string.street_view_panorama_basic_demo_details,
StreetViewPanoramaBasicDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_navigation_demo_label,
R.string.street_view_panorama_navigation_demo_details,
StreetViewPanoramaNavigationDemoActivity::class.java),
DemoDetails(R.string.tags_demo_label, R.string.tags_demo_details,
DemoDetails(
R.string.split_street_view_panorama_and_map_demo_label,
R.string.split_street_view_panorama_and_map_demo_details,
SplitStreetViewPanoramaAndMapDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_options_demo_label,
R.string.street_view_panorama_options_demo_details,
StreetViewPanoramaOptionsDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_events_demo_label,
R.string.street_view_panorama_events_demo_details,
StreetViewPanoramaEventsDemoActivity::class.java),
DemoDetails(
R.string.street_view_panorama_view_demo_label,
R.string.street_view_panorama_view_demo_details,
StreetViewPanoramaViewDemoActivity::class.java
),
DemoDetails(R.string.tags_demo_label, R.string.tags_demo_details,
TagsDemoActivity::class.java),
DemoDetails(R.string.ui_settings_demo_label, R.string.ui_settings_demo_details,
DemoDetails(
R.string.tile_coordinate_demo_label,
R.string.tile_coordinate_demo_description,
TileCoordinateDemoActivity::class.java
),
DemoDetails(
R.string.tile_overlay_demo_label,
R.string.tile_overlay_demo_description,
TileOverlayDemoActivity::class.java
),
DemoDetails(R.string.ui_settings_demo_label, R.string.ui_settings_demo_details,
UiSettingsDemoActivity::class.java),
DemoDetails(R.string.region_demo_label, R.string.region_demo_details,
DemoDetails(R.string.region_demo_label, R.string.region_demo_details,
VisibleRegionDemoActivity::class.java)
)
}

View File

@ -0,0 +1,96 @@
/**
* 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.kotlindemos
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.libraries.maps.GoogleMap
import com.google.android.libraries.maps.MapView
import com.google.android.libraries.maps.OnMapReadyCallback
import com.google.android.libraries.maps.model.LatLng
import com.google.android.libraries.maps.model.MarkerOptions
/**
* This shows how to create a simple activity with a raw MapView and add a marker to it. This
* requires forwarding all the important lifecycle methods onto MapView.
*/
class RawMapViewDemoActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mapView: MapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.raw_mapview_demo)
// *** IMPORTANT ***
// MapView requires that the Bundle you pass contain _ONLY_ MapView SDK
// objects or sub-Bundles.
val mapViewBundle = savedInstanceState?.getBundle(MAPVIEW_BUNDLE_KEY)
mapView = findViewById(R.id.map)
mapView.onCreate(mapViewBundle)
mapView.getMapAsync(this)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY) ?: Bundle().apply {
putBundle(MAPVIEW_BUNDLE_KEY, this)
}
mapView.onSaveInstanceState(mapViewBundle)
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onMapReady(map: GoogleMap) {
map.addMarker(MarkerOptions().position(LatLng(0.0, 0.0)).title("Marker"))
}
override fun onPause() {
mapView.onPause()
super.onPause()
}
override fun onDestroy() {
mapView.onDestroy()
super.onDestroy()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
companion object {
private const val MAPVIEW_BUNDLE_KEY = "MapViewBundleKey"
}
}

View File

@ -20,7 +20,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.kotlindemos
import android.content.Context

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project
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.
--><!-- This can go anywhere in your layout. -->
<com.google.android.libraries.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />