Skip to content

Commit 4297488

Browse files
authored
feat: added Kotlin MapColorScheme sample (#1712)
* feat: added Kotlin MapColorScheme sample * chore: added header in XML file * feat: added Kotlin MapColorScheme sample * feat: Java demo
1 parent 58cf1c3 commit 4297488

File tree

14 files changed

+335
-68
lines changed

14 files changed

+335
-68
lines changed

ApiDemos/java/app/src/gms/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@
7777
<activity
7878
android:name=".MapInPagerDemoActivity"
7979
android:label="@string/map_in_pager_demo_label" />
80+
<activity
81+
android:name=".MapColorSchemeActivity"
82+
android:label="@string/marker_demo_label" />
8083
<activity
8184
android:name=".MarkerDemoActivity"
8285
android:label="@string/marker_demo_label" />
8386
<activity
8487
android:name=".MarkerCloseInfoWindowOnRetapDemoActivity"
8588
android:label="@string/marker_close_info_window_on_retap_demo_label" />
8689
<activity
87-
android:name=".polyline.PolylineDemoActivity"
90+
android:name=".PolylineDemoActivity"
8891
android:label="@string/polyline_demo_label" />
8992
<activity
9093
android:name=".MultiMapDemoActivity"

ApiDemos/java/app/src/gms/java/com/example/mapdemo/DemoDetailsList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
package com.example.mapdemo;
1717

18-
import com.example.mapdemo.polyline.PolylineDemoActivity;
19-
2018
/**
2119
* A list of all the demos we have available.
2220
*/
@@ -79,6 +77,9 @@ private DemoDetailsList() {
7977
new DemoDetails(R.string.map_in_pager_demo_label,
8078
R.string.map_in_pager_demo_description,
8179
MapInPagerDemoActivity.class),
80+
new DemoDetails(R.string.map_color_scheme_demo_label,
81+
R.string.map_color_scheme_demo_description,
82+
MapColorSchemeActivity.class),
8283
new DemoDetails(R.string.marker_demo_label,
8384
R.string.marker_demo_description,
8485
MarkerDemoActivity.class),

ApiDemos/java/app/src/gms/java/com/example/mapdemo/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.widget.ListAdapter;
2727
import android.widget.ListView;
2828

29+
import androidx.annotation.NonNull;
2930
import androidx.appcompat.app.AppCompatActivity;
3031

3132
/**
@@ -45,8 +46,9 @@ public CustomArrayAdapter(Context context, DemoDetails[] demos) {
4546
super(context, R.layout.feature, R.id.title, demos);
4647
}
4748

49+
@NonNull
4850
@Override
49-
public View getView(int position, View convertView, ViewGroup parent) {
51+
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
5052
FeatureView featureView;
5153
if (convertView instanceof FeatureView) {
5254
featureView = (FeatureView) convertView;
@@ -75,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
7577

7678
ListAdapter adapter = new CustomArrayAdapter(this, DemoDetailsList.DEMOS);
7779

78-
ListView demoListView = (ListView) findViewById(R.id.list);
80+
ListView demoListView = findViewById(R.id.list);
7981
if (demoListView != null) {
8082
demoListView.setAdapter(adapter);
8183
demoListView.setOnItemClickListener(
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024 Google LLC
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+
* https://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+
17+
package com.example.mapdemo;
18+
19+
import android.os.Bundle;
20+
import android.widget.Button;
21+
22+
import androidx.annotation.NonNull;
23+
import androidx.appcompat.app.AppCompatActivity;
24+
25+
import com.google.android.gms.maps.GoogleMap;
26+
import com.google.android.gms.maps.OnMapReadyCallback;
27+
import com.google.android.gms.maps.SupportMapFragment;
28+
import com.google.android.gms.maps.model.MapColorScheme;
29+
30+
public class MapColorSchemeActivity extends AppCompatActivity implements OnMapReadyCallback {
31+
32+
private Button buttonLight;
33+
private Button buttonDark;
34+
private Button buttonFollowSystem;
35+
36+
@Override
37+
protected void onCreate(Bundle savedInstanceState) {
38+
super.onCreate(savedInstanceState);
39+
setContentView(R.layout.map_color_scheme_demo);
40+
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
41+
if (mapFragment != null) {
42+
mapFragment.getMapAsync(this);
43+
}
44+
buttonLight = findViewById(R.id.map_color_light_mode);
45+
buttonDark = findViewById(R.id.map_color_dark_mode);
46+
buttonFollowSystem = findViewById(R.id.map_color_follow_system_mode);
47+
}
48+
49+
@Override
50+
public void onMapReady(@NonNull GoogleMap googleMap) {
51+
52+
googleMap.setMapColorScheme(MapColorScheme.DARK);
53+
54+
buttonLight.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.LIGHT));
55+
56+
buttonDark.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.DARK));
57+
58+
buttonFollowSystem.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.FOLLOW_SYSTEM));
59+
}
60+
}

ApiDemos/java/app/src/gms/java/com/example/mapdemo/PolylineDemoActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515

16-
package com.example.mapdemo.polyline;
16+
package com.example.mapdemo;
1717

1818
import android.graphics.Color;
1919
import android.os.Bundle;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2024 Google LLC
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+
https://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
-->
14+
15+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
xmlns:map="http://schemas.android.com/apk/res-auto"
17+
android:layout_width="match_parent"
18+
android:layout_height="match_parent">
19+
<!--We need to add the map id to make advanced markers work. For more information,
20+
check out https://developers.google.com/maps/documentation/get-map-id#create-a-map-id. -->
21+
<fragment
22+
android:id="@+id/map"
23+
class="com.google.android.gms.maps.SupportMapFragment"
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"
26+
map:backgroundColor="#fff0b2dd"
27+
map:mapId="@string/map_id" />
28+
29+
<LinearLayout
30+
android:id="@+id/cloud_styling_basic_demo_mode_buttons"
31+
style="?android:attr/buttonBarStyle"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:background="#D000"
35+
android:orientation="horizontal">
36+
37+
<Button
38+
android:id="@+id/map_color_light_mode"
39+
style="?android:attr/buttonBarButtonStyle"
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:text="@string/map_color_light_mode" />
43+
44+
<Button
45+
android:id="@+id/map_color_dark_mode"
46+
style="?android:attr/buttonBarButtonStyle"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:text="@string/map_color_dark_mode" />
50+
51+
<Button
52+
android:id="@+id/map_color_follow_system_mode"
53+
style="?android:attr/buttonBarButtonStyle"
54+
android:layout_width="wrap_content"
55+
android:layout_height="wrap_content"
56+
android:text="@string/map_color_follow_system_mode" />
57+
</LinearLayout>
58+
</RelativeLayout>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
<string name="map_not_ready">Map is not ready yet</string>
7979
<string name="map_in_pager_demo_label">Map In Pager</string>
8080
<string name="map_in_pager_demo_description">Demonstrates how to add a map to a ViewPager.</string>
81+
<string name="map_color_scheme_demo_description">Demonstrates how to use the MapColorScheme.</string>
82+
<string name="map_color_scheme_demo_label">MapColorScheme</string>
8183
<string name="marker_demo_label">Markers</string>
8284
<string name="marker_close_info_window_on_retap_demo_label">Marker Close Info Window on Retap</string>
8385
<string name="marker_close_info_window_on_retap_demo_description">Demonstrates how to close the info window when the currently selected marker is retapped.</string>
@@ -287,4 +289,8 @@
287289
description="Text displayed below the Background Color Customization - Programmatic demo title.">Demonstrates how to programmatically set a custom background color to a map.</string>
288290
<string name="show_map_tiles">Show Map Tiles</string>
289291

292+
<!-- Map Color Scheme -->
293+
<string name="map_color_light_mode">Light</string>
294+
<string name="map_color_dark_mode">Dark</string>
295+
<string name="map_color_follow_system_mode">Follow System\n</string>
290296
</resources>

ApiDemos/kotlin/app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@ android {
4949
}
5050

5151
dependencies {
52-
implementation fileTree(dir: 'libs', include: ['*.jar'])
5352
api 'androidx.appcompat:appcompat:1.7.0'
5453
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5554
implementation "androidx.cardview:cardview:1.0.0"
56-
implementation "androidx.recyclerview:recyclerview:1.3.1"
55+
implementation "androidx.recyclerview:recyclerview:1.3.2"
5756
implementation 'androidx.multidex:multidex:2.0.1'
5857
implementation 'com.android.volley:volley:1.2.1'
5958

6059
// GMS
6160
gmsImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.3'
62-
gmsImplementation 'com.google.maps.android:maps-ktx:5.1.0'
61+
gmsImplementation 'com.google.maps.android:maps-ktx:5.1.1'
6362

6463
// Below is used to run the easypermissions library to manage location permissions
6564
// EasyPermissions is needed to help us request for permission to access location

ApiDemos/kotlin/app/src/gms/AndroidManifest.xml

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,63 @@
1515
-->
1616
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
1717

18-
<application
19-
android:allowBackup="true"
20-
android:icon="@mipmap/ic_launcher"
21-
android:label="@string/app_name"
22-
android:roundIcon="@mipmap/ic_launcher_round"
23-
android:supportsRtl="true"
24-
android:theme="@style/AppTheme">
18+
<application
19+
android:allowBackup="true"
20+
android:icon="@mipmap/ic_launcher"
21+
android:label="@string/app_name"
22+
android:roundIcon="@mipmap/ic_launcher_round"
23+
android:supportsRtl="true"
24+
android:theme="@style/AppTheme">
2525

26-
<activity android:name=".MainActivity"
27-
android:exported="true">
28-
<intent-filter>
29-
<action android:name="android.intent.action.MAIN" />
30-
31-
<category android:name="android.intent.category.LAUNCHER" />
32-
</intent-filter>
33-
</activity>
34-
<activity android:name=".AdvancedMarkersDemoActivity" />
35-
<activity android:name=".BasicMapDemoActivity" />
36-
<activity android:name=".BackgroundColorCustomizationDemoActivity" />
37-
<activity android:name=".BackgroundColorCustomizationProgrammaticDemoActivity" />
38-
<activity android:name=".CameraDemoActivity" />
39-
<activity android:name=".CameraClampingDemoActivity" />
40-
<activity android:name=".CloudBasedMapStylingDemoActivity" />
41-
<activity android:name=".CircleDemoActivity" />
42-
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
43-
<activity android:name=".EventsDemoActivity" />
44-
<activity android:name=".GroundOverlayDemoActivity" />
45-
<activity android:name=".IndoorDemoActivity" />
46-
<activity android:name=".LayersDemoActivity" />
47-
<activity android:name=".LiteDemoActivity" />
48-
<activity android:name=".LiteListDemoActivity" />
49-
<activity android:name=".LocationSourceDemoActivity" />
50-
<activity android:name=".MapInPagerDemoActivity" />
51-
<activity android:name=".MarkerDemoActivity" />
52-
<activity android:name=".MultiMapDemoActivity" />
53-
<activity android:name=".MyLocationDemoActivity" />
54-
<activity android:name=".OptionsDemoActivity" />
55-
<activity android:name=".PolygonDemoActivity" />
56-
<activity android:name=".ProgrammaticDemoActivity" />
57-
<activity android:name=".RawMapViewDemoActivity" />
58-
<activity android:name=".RetainMapDemoActivity" />
59-
<activity android:name=".SaveStateDemoActivity" />
60-
<activity android:name=".SnapshotDemoActivity" />
61-
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
62-
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
63-
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
64-
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
65-
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
66-
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
67-
<activity android:name=".StyledMapDemoActivity" />
68-
<activity android:name=".TagsDemoActivity" />
69-
<activity android:name=".TileCoordinateDemoActivity" />
70-
<activity android:name=".TileOverlayDemoActivity" />
71-
<activity android:name=".UiSettingsDemoActivity" />
72-
<activity android:name=".VisibleRegionDemoActivity" />
73-
<activity android:name=".polyline.PolylineDemoActivity" />
74-
</application>
26+
<activity
27+
android:name=".MainActivity"
28+
android:exported="true">
29+
<intent-filter>
30+
<action android:name="android.intent.action.MAIN" />
31+
<category android:name="android.intent.category.LAUNCHER" />
32+
</intent-filter>
33+
</activity>
34+
<activity android:name=".AdvancedMarkersDemoActivity" />
35+
<activity android:name=".BasicMapDemoActivity" />
36+
<activity android:name=".BackgroundColorCustomizationDemoActivity" />
37+
<activity android:name=".BackgroundColorCustomizationProgrammaticDemoActivity" />
38+
<activity android:name=".CameraDemoActivity" />
39+
<activity android:name=".CameraClampingDemoActivity" />
40+
<activity android:name=".CloudBasedMapStylingDemoActivity" />
41+
<activity android:name=".CircleDemoActivity" />
42+
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
43+
<activity android:name=".EventsDemoActivity" />
44+
<activity android:name=".GroundOverlayDemoActivity" />
45+
<activity android:name=".IndoorDemoActivity" />
46+
<activity android:name=".LayersDemoActivity" />
47+
<activity android:name=".LiteDemoActivity" />
48+
<activity android:name=".LiteListDemoActivity" />
49+
<activity android:name=".LocationSourceDemoActivity" />
50+
<activity android:name=".MapInPagerDemoActivity" />
51+
<activity android:name=".MapColorSchemeActivity" />
52+
<activity android:name=".MarkerDemoActivity" />
53+
<activity android:name=".MultiMapDemoActivity" />
54+
<activity android:name=".MyLocationDemoActivity" />
55+
<activity android:name=".OptionsDemoActivity" />
56+
<activity android:name=".PolygonDemoActivity" />
57+
<activity android:name=".ProgrammaticDemoActivity" />
58+
<activity android:name=".RawMapViewDemoActivity" />
59+
<activity android:name=".RetainMapDemoActivity" />
60+
<activity android:name=".SaveStateDemoActivity" />
61+
<activity android:name=".SnapshotDemoActivity" />
62+
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
63+
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
64+
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
65+
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
66+
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
67+
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
68+
<activity android:name=".StyledMapDemoActivity" />
69+
<activity android:name=".TagsDemoActivity" />
70+
<activity android:name=".TileCoordinateDemoActivity" />
71+
<activity android:name=".TileOverlayDemoActivity" />
72+
<activity android:name=".UiSettingsDemoActivity" />
73+
<activity android:name=".VisibleRegionDemoActivity" />
74+
<activity android:name=".polyline.PolylineDemoActivity" />
75+
</application>
7576

7677
</manifest>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ private val TAG = AdvancedMarkersDemoActivity::class.java.name
4848
*/
4949
// [START maps_android_sample_marker_advanced]
5050
class AdvancedMarkersDemoActivity : AppCompatActivity(), OnMapReadyCallback {
51+
5152
override fun onCreate(savedInstanceState: Bundle?) {
5253
super.onCreate(savedInstanceState)
5354
setContentView(R.layout.advanced_markers_demo)
5455
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
5556
mapFragment?.getMapAsync(this)
56-
57-
5857
}
5958

6059
override fun onMapReady(map: GoogleMap) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ class DemoDetailsList {
107107
R.string.map_in_pager_demo_description,
108108
MapInPagerDemoActivity::class.java
109109
),
110+
DemoDetails(
111+
R.string.map_color_scheme_demo_label,
112+
R.string.map_color_scheme_demo_description,
113+
MapColorSchemeActivity::class.java
114+
),
110115
DemoDetails(
111116
R.string.markers_demo_label,
112117
R.string.markers_demo_description,
113-
MarkerDemoActivity::class.java
118+
MapColorSchemeActivity::class.java
114119
),
115120
DemoDetails(
116121
R.string.multi_map_demo_label,

0 commit comments

Comments
 (0)