Skip to content

Commit 87f37c0

Browse files
authored
feat: Adding sample for MapInPagerDemoActivity and MultiMapDemoActivity (#429)
* Adding sample for MapInPagerDemoActivity * Bump to gradle 6.5 * Adding MultiMapDemoActivity.
1 parent 4768bab commit 87f37c0

File tree

9 files changed

+234
-3
lines changed

9 files changed

+234
-3
lines changed

ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ class DemoDetailsList {
5959
DemoDetails(R.string.lite_list_demo_label,
6060
R.string.lite_list_demo_details,
6161
LiteListDemoActivity::class.java),
62+
DemoDetails(R.string.map_in_pager_demo_label,
63+
R.string.map_in_pager_demo_description,
64+
MapInPagerDemoActivity::class.java),
6265
DemoDetails(R.string.markers_demo_label,
6366
R.string.markers_demo_description,
6467
MarkerDemoActivity::class.java),
68+
DemoDetails(R.string.multi_map_demo_label,
69+
R.string.multi_map_demo_description,
70+
MultiMapDemoActivity::class.java),
6571
DemoDetails(R.string.my_location_demo_label,
6672
R.string.my_location_demo_details,
6773
MyLocationDemoActivity::class.java),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.example.kotlindemos
15+
16+
import android.os.Bundle
17+
import android.view.LayoutInflater
18+
import android.view.View
19+
import android.view.ViewGroup
20+
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.fragment.app.Fragment
22+
import androidx.fragment.app.FragmentManager
23+
import androidx.fragment.app.FragmentPagerAdapter
24+
import androidx.viewpager.widget.ViewPager
25+
import com.google.android.gms.maps.SupportMapFragment
26+
27+
/**
28+
* This shows how to add a map to a ViewPager. Note the use of
29+
* [ViewGroup.requestTransparentRegion] to reduce jankiness.
30+
*/
31+
class MapInPagerDemoActivity : AppCompatActivity() {
32+
33+
/** Called when the activity is first created. */
34+
public override fun onCreate(savedInstanceState: Bundle?) {
35+
super.onCreate(savedInstanceState)
36+
setContentView(R.layout.map_in_pager_demo)
37+
val adapter = MyAdapter(supportFragmentManager)
38+
val pager = findViewById<ViewPager>(R.id.pager)
39+
pager.adapter = adapter
40+
41+
// This is required to avoid a black flash when the map is loaded. The flash is due
42+
// to the use of a SurfaceView as the underlying view of the map.
43+
pager.requestTransparentRegion(pager)
44+
}
45+
46+
/** A simple fragment that displays a TextView. */
47+
class TextFragment : Fragment() {
48+
override fun onCreateView(inflater: LayoutInflater,
49+
container: ViewGroup?,
50+
bundle: Bundle?): View? {
51+
return inflater.inflate(R.layout.text_fragment, container, false)
52+
}
53+
}
54+
55+
/** A simple FragmentPagerAdapter that returns two TextFragment and a SupportMapFragment. */
56+
class MyAdapter(fm: FragmentManager) :
57+
FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
58+
59+
override fun getCount(): Int {
60+
return 3
61+
}
62+
63+
override fun getItem(position: Int): Fragment {
64+
return when (position) {
65+
0, 1 -> TextFragment()
66+
2 -> SupportMapFragment.newInstance()
67+
else -> Fragment()
68+
}
69+
}
70+
}
71+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.example.kotlindemos
15+
16+
import android.os.Bundle
17+
import androidx.appcompat.app.AppCompatActivity
18+
19+
/**
20+
* This shows how to create a simple activity with multiple maps on screen.
21+
*/
22+
class MultiMapDemoActivity : AppCompatActivity() {
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
setContentView(R.layout.multimap_demo)
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<androidx.viewpager.widget.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:id="@+id/pager"
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent" />
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
17+
xmlns:map="http://schemas.android.com/apk/res-auto"
18+
android:id="@+id/map_container"
19+
android:layout_width="match_parent"
20+
android:layout_height="match_parent"
21+
android:orientation="vertical">
22+
23+
<LinearLayout
24+
android:id="@+id/map_container1"
25+
android:layout_width="match_parent"
26+
android:layout_height="match_parent"
27+
android:layout_weight="0.5"
28+
android:orientation="horizontal">
29+
30+
<fragment
31+
android:id="@+id/map1"
32+
android:layout_width="match_parent"
33+
android:layout_height="match_parent"
34+
android:layout_weight="0.5"
35+
class="com.google.android.gms.maps.SupportMapFragment"
36+
map:cameraTargetLat="40.72"
37+
map:cameraTargetLng="-74.00"
38+
map:cameraZoom="8" />
39+
40+
<fragment
41+
android:id="@+id/map2"
42+
android:layout_width="match_parent"
43+
android:layout_height="match_parent"
44+
android:layout_weight="0.5"
45+
class="com.google.android.gms.maps.SupportMapFragment"
46+
map:cameraTargetLat="51.51"
47+
map:cameraTargetLng="-0.12"
48+
map:cameraZoom="8" />
49+
</LinearLayout>
50+
51+
<LinearLayout
52+
android:id="@+id/map_container2"
53+
android:layout_width="match_parent"
54+
android:layout_height="match_parent"
55+
android:layout_weight="0.5"
56+
android:orientation="horizontal">
57+
58+
<fragment
59+
android:id="@+id/map3"
60+
android:layout_width="match_parent"
61+
android:layout_height="match_parent"
62+
android:layout_weight="0.5"
63+
class="com.google.android.gms.maps.SupportMapFragment"
64+
map:cameraTargetLat="48.85"
65+
map:cameraTargetLng="2.35"
66+
map:cameraZoom="8" />
67+
68+
<fragment
69+
android:id="@+id/map4"
70+
android:layout_width="match_parent"
71+
android:layout_height="match_parent"
72+
android:layout_weight="0.5"
73+
class="com.google.android.gms.maps.SupportMapFragment"
74+
map:cameraTargetLat="35.69"
75+
map:cameraTargetLng="139.69"
76+
map:cameraZoom="8" />
77+
</LinearLayout>
78+
</LinearLayout>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2012 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent"
20+
android:gravity="center"
21+
android:text="@string/swipe" />

ApiDemos/kotlin/app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,13 @@
289289
<string name="location_source_demo_label">Location Source Demo</string>
290290
<string name="location_source_demo_description">Demonstrates how to use a custom location source.</string>
291291

292+
<!-- Map in Pager -->
293+
<string name="map_in_pager_demo_label">Map In Pager</string>
294+
<string name="map_in_pager_demo_description">Demonstrates how to add a map to a ViewPager.</string>
295+
<string name="swipe">\u2190 Swipe \u2192</string>
296+
297+
<!-- Multi Map -->
298+
<string name="multi_map_demo_label">Multiple Maps</string>
299+
<string name="multi_map_demo_description">Demonstrates how to show multiple maps in a single activity.</string>
300+
292301
</resources>

tutorials/kotlin/MapWithMarker/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'kotlin-android-extensions'
32
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
44

55
// Set the properties within `local.properties` into a `Properties` class so
66
// that values within `local.properties` (e.g. Maps API key) are accessible in
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Jul 27 14:05:56 PDT 2020
1+
#Tue Jan 26 13:55:26 PST 2021
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

0 commit comments

Comments
 (0)