From 87f37c0320047a971d7cf241bdeda8f79aa26482 Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Tue, 26 Jan 2021 14:54:21 -0800 Subject: [PATCH] feat: Adding sample for MapInPagerDemoActivity and MultiMapDemoActivity (#429) * Adding sample for MapInPagerDemoActivity * Bump to gradle 6.5 * Adding MultiMapDemoActivity. --- .../example/kotlindemos/DemoDetailsList.kt | 6 ++ .../kotlindemos/MapInPagerDemoActivity.kt | 71 +++++++++++++++++ .../kotlindemos/MultiMapDemoActivity.kt | 27 +++++++ .../src/gms/res/layout/map_in_pager_demo.xml | 19 +++++ .../app/src/gms/res/layout/multimap_demo.xml | 78 +++++++++++++++++++ .../app/src/gms/res/layout/text_fragment.xml | 21 +++++ .../app/src/main/res/values/strings.xml | 9 +++ .../kotlin/MapWithMarker/app/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- 9 files changed, 234 insertions(+), 3 deletions(-) create mode 100755 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MapInPagerDemoActivity.kt create mode 100644 ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MultiMapDemoActivity.kt create mode 100755 ApiDemos/kotlin/app/src/gms/res/layout/map_in_pager_demo.xml create mode 100644 ApiDemos/kotlin/app/src/gms/res/layout/multimap_demo.xml create mode 100755 ApiDemos/kotlin/app/src/gms/res/layout/text_fragment.xml diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt index 8cd2c27c..d0d9b70d 100644 --- a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt @@ -59,9 +59,15 @@ class DemoDetailsList { DemoDetails(R.string.lite_list_demo_label, R.string.lite_list_demo_details, LiteListDemoActivity::class.java), + DemoDetails(R.string.map_in_pager_demo_label, + R.string.map_in_pager_demo_description, + MapInPagerDemoActivity::class.java), DemoDetails(R.string.markers_demo_label, R.string.markers_demo_description, MarkerDemoActivity::class.java), + DemoDetails(R.string.multi_map_demo_label, + R.string.multi_map_demo_description, + MultiMapDemoActivity::class.java), DemoDetails(R.string.my_location_demo_label, R.string.my_location_demo_details, MyLocationDemoActivity::class.java), diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MapInPagerDemoActivity.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MapInPagerDemoActivity.kt new file mode 100755 index 00000000..c44f1198 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MapInPagerDemoActivity.kt @@ -0,0 +1,71 @@ +// 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.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 com.google.android.gms.maps.SupportMapFragment + +/** + * This shows how to add a map to a ViewPager. Note the use of + * [ViewGroup.requestTransparentRegion] to reduce jankiness. + */ +class MapInPagerDemoActivity : AppCompatActivity() { + + /** Called when the activity is first created. */ + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.map_in_pager_demo) + val adapter = MyAdapter(supportFragmentManager) + val pager = findViewById(R.id.pager) + pager.adapter = adapter + + // 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) + } + + /** A simple fragment that displays a TextView. */ + class TextFragment : Fragment() { + override fun onCreateView(inflater: LayoutInflater, + container: ViewGroup?, + bundle: Bundle?): View? { + return inflater.inflate(R.layout.text_fragment, container, false) + } + } + + /** A simple FragmentPagerAdapter that returns two TextFragment and a SupportMapFragment. */ + class MyAdapter(fm: FragmentManager) : + FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { + + override fun getCount(): Int { + return 3 + } + + override fun getItem(position: Int): Fragment { + return when (position) { + 0, 1 -> TextFragment() + 2 -> SupportMapFragment.newInstance() + else -> Fragment() + } + } + } +} \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MultiMapDemoActivity.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MultiMapDemoActivity.kt new file mode 100644 index 00000000..e8dcb965 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/MultiMapDemoActivity.kt @@ -0,0 +1,27 @@ +// 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 + +/** + * This shows how to create a simple activity with multiple maps on screen. + */ +class MultiMapDemoActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.multimap_demo) + } +} \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/gms/res/layout/map_in_pager_demo.xml b/ApiDemos/kotlin/app/src/gms/res/layout/map_in_pager_demo.xml new file mode 100755 index 00000000..ec2274a6 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/res/layout/map_in_pager_demo.xml @@ -0,0 +1,19 @@ + + diff --git a/ApiDemos/kotlin/app/src/gms/res/layout/multimap_demo.xml b/ApiDemos/kotlin/app/src/gms/res/layout/multimap_demo.xml new file mode 100644 index 00000000..95e48e64 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/res/layout/multimap_demo.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + diff --git a/ApiDemos/kotlin/app/src/gms/res/layout/text_fragment.xml b/ApiDemos/kotlin/app/src/gms/res/layout/text_fragment.xml new file mode 100755 index 00000000..5fcc62a2 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/res/layout/text_fragment.xml @@ -0,0 +1,21 @@ + + + diff --git a/ApiDemos/kotlin/app/src/main/res/values/strings.xml b/ApiDemos/kotlin/app/src/main/res/values/strings.xml index fee9153c..bc520924 100644 --- a/ApiDemos/kotlin/app/src/main/res/values/strings.xml +++ b/ApiDemos/kotlin/app/src/main/res/values/strings.xml @@ -289,4 +289,13 @@ Location Source Demo Demonstrates how to use a custom location source. + + Map In Pager + Demonstrates how to add a map to a ViewPager. + \u2190 Swipe \u2192 + + + Multiple Maps + Demonstrates how to show multiple maps in a single activity. + \ No newline at end of file diff --git a/tutorials/kotlin/MapWithMarker/app/build.gradle b/tutorials/kotlin/MapWithMarker/app/build.gradle index c97b7e49..9a51ac11 100644 --- a/tutorials/kotlin/MapWithMarker/app/build.gradle +++ b/tutorials/kotlin/MapWithMarker/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' // Set the properties within `local.properties` into a `Properties` class so // that values within `local.properties` (e.g. Maps API key) are accessible in diff --git a/tutorials/kotlin/MapWithMarker/gradle/wrapper/gradle-wrapper.properties b/tutorials/kotlin/MapWithMarker/gradle/wrapper/gradle-wrapper.properties index 76613236..d1c2b404 100644 --- a/tutorials/kotlin/MapWithMarker/gradle/wrapper/gradle-wrapper.properties +++ b/tutorials/kotlin/MapWithMarker/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jul 27 14:05:56 PDT 2020 +#Tue Jan 26 13:55:26 PST 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip