From e6cf1b02021cb4fd391e1c2ee9224e732b306139 Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Mon, 25 Jan 2021 17:03:15 -0800 Subject: [PATCH] feat: Add missing Kotlin samples (#428) * Gradle bump and rename CloseInfoWindowDemoActivity * Adding CameraClampingDemoActivity. * Fix build error. * Add location source. --- ApiDemos/kotlin/app/build.gradle | 2 + .../kotlin/app/src/gms/AndroidManifest.xml | 82 ++++----- .../kotlindemos/CameraClampingDemoActivity.kt | 145 +++++++++++++++ .../CloseInfoWindowDemoActivity.kt | 124 ------------- .../example/kotlindemos/DemoDetailsList.kt | 169 +++++++++--------- .../kotlindemos/LocationSourceDemoActivity.kt | 112 ++++++++++++ ...arkerCloseInfoWindowOnRetapDemoActivity.kt | 124 +++++++++++++ .../kotlindemos/TileOverlayDemoActivity.kt | 2 +- .../gms/res/layout/camera_clamping_demo.xml | 93 ++++++++++ .../app/src/main/res/values/strings.xml | 17 +- .../kotlin/app/src/v3/AndroidManifest.xml | 2 +- ...arkerCloseInfoWindowOnRetapDemoActivity.kt | 131 ++++++++++++++ .../kotlindemos/TileOverlayDemoActivity.kt | 2 +- ApiDemos/kotlin/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- 15 files changed, 759 insertions(+), 254 deletions(-) create mode 100644 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/CameraClampingDemoActivity.kt delete mode 100644 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/CloseInfoWindowDemoActivity.kt create mode 100644 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/LocationSourceDemoActivity.kt create mode 100644 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MarkerCloseInfoWindowOnRetapDemoActivity.kt create mode 100644 ApiDemos/kotlin/app/src/gms/res/layout/camera_clamping_demo.xml create mode 100644 ApiDemos/kotlin/app/src/v3/java/com/example/kotlindemos/MarkerCloseInfoWindowOnRetapDemoActivity.kt diff --git a/ApiDemos/kotlin/app/build.gradle b/ApiDemos/kotlin/app/build.gradle index 3c30b0af..cbb0a95b 100644 --- a/ApiDemos/kotlin/app/build.gradle +++ b/ApiDemos/kotlin/app/build.gradle @@ -67,7 +67,9 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' // GMS + gmsImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0' gmsImplementation 'com.google.android.gms:play-services-maps:17.0.0' + gmsImplementation 'com.google.maps.android:maps-ktx:2.2.0' // V3 v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta' diff --git a/ApiDemos/kotlin/app/src/gms/AndroidManifest.xml b/ApiDemos/kotlin/app/src/gms/AndroidManifest.xml index 35caaa84..be24826f 100644 --- a/ApiDemos/kotlin/app/src/gms/AndroidManifest.xml +++ b/ApiDemos/kotlin/app/src/gms/AndroidManifest.xml @@ -16,47 +16,49 @@ - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/CameraClampingDemoActivity.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/CameraClampingDemoActivity.kt new file mode 100644 index 00000000..a4c3dd16 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/CameraClampingDemoActivity.kt @@ -0,0 +1,145 @@ +// 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 android.util.Log +import android.view.View +import android.widget.Button +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope +import com.google.android.gms.maps.CameraUpdateFactory +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener +import com.google.android.gms.maps.OnMapReadyCallback +import com.google.android.gms.maps.SupportMapFragment +import com.google.android.gms.maps.model.CameraPosition +import com.google.android.gms.maps.model.LatLng +import com.google.android.gms.maps.model.LatLngBounds +import com.google.maps.android.ktx.CameraIdleEvent +import com.google.maps.android.ktx.awaitMap +import com.google.maps.android.ktx.cameraEvents +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch + +/** + * This shows how to constrain the camera to specific boundaries and zoom levels. + */ +class CameraClampingDemoActivity : AppCompatActivity() { + + private lateinit var map: GoogleMap + private lateinit var cameraTextView: TextView + private val buttonIdToLatLngBoundsCameraMap = mapOf( + Pair(R.id.clamp_latlng_adelaide, Pair(ADELAIDE, ADELAIDE_CAMERA)), + Pair(R.id.clamp_latlng_pacific, Pair(PACIFIC, PACIFIC_CAMERA)), + ) + + /** + * Internal min zoom level that can be toggled via the demo. + */ + private var minZoom = DEFAULT_MIN_ZOOM + + /** + * Internal max zoom level that can be toggled via the demo. + */ + private var maxZoom = DEFAULT_MAX_ZOOM + + @ExperimentalCoroutinesApi + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.camera_clamping_demo) + cameraTextView = findViewById(R.id.camera_text) + val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment + lifecycleScope.launchWhenCreated { + map = mapFragment.awaitMap() + launch { + map.cameraEvents().collect { event -> + when (event) { + is CameraIdleEvent -> onCameraIdle() + else -> Log.d(TAG, "Got event: $event") + } + } + } + setButtonClickListeners() + } + } + + private fun setButtonClickListeners() { + // Min/max zooms + findViewById