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
This commit is contained in:
Enrique López Mañas 2024-07-22 23:27:22 +02:00 committed by GitHub
parent 58cf1c3892
commit 4297488454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 335 additions and 68 deletions

View File

@ -77,6 +77,9 @@
<activity
android:name=".MapInPagerDemoActivity"
android:label="@string/map_in_pager_demo_label" />
<activity
android:name=".MapColorSchemeActivity"
android:label="@string/marker_demo_label" />
<activity
android:name=".MarkerDemoActivity"
android:label="@string/marker_demo_label" />
@ -84,7 +87,7 @@
android:name=".MarkerCloseInfoWindowOnRetapDemoActivity"
android:label="@string/marker_close_info_window_on_retap_demo_label" />
<activity
android:name=".polyline.PolylineDemoActivity"
android:name=".PolylineDemoActivity"
android:label="@string/polyline_demo_label" />
<activity
android:name=".MultiMapDemoActivity"

View File

@ -15,8 +15,6 @@
package com.example.mapdemo;
import com.example.mapdemo.polyline.PolylineDemoActivity;
/**
* A list of all the demos we have available.
*/
@ -79,6 +77,9 @@ public final class DemoDetailsList {
new DemoDetails(R.string.map_in_pager_demo_label,
R.string.map_in_pager_demo_description,
MapInPagerDemoActivity.class),
new DemoDetails(R.string.map_color_scheme_demo_label,
R.string.map_color_scheme_demo_description,
MapColorSchemeActivity.class),
new DemoDetails(R.string.marker_demo_label,
R.string.marker_demo_description,
MarkerDemoActivity.class),

View File

@ -26,6 +26,7 @@ import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
/**
@ -45,8 +46,9 @@ public final class MainActivity extends AppCompatActivity {
super(context, R.layout.feature, R.id.title, demos);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
FeatureView featureView;
if (convertView instanceof FeatureView) {
featureView = (FeatureView) convertView;
@ -75,7 +77,7 @@ public final class MainActivity extends AppCompatActivity {
ListAdapter adapter = new CustomArrayAdapter(this, DemoDetailsList.DEMOS);
ListView demoListView = (ListView) findViewById(R.id.list);
ListView demoListView = findViewById(R.id.list);
if (demoListView != null) {
demoListView.setAdapter(adapter);
demoListView.setOnItemClickListener(

View File

@ -0,0 +1,60 @@
/*
* Copyright 2024 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
*
* https://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.mapdemo;
import android.os.Bundle;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.MapColorScheme;
public class MapColorSchemeActivity extends AppCompatActivity implements OnMapReadyCallback {
private Button buttonLight;
private Button buttonDark;
private Button buttonFollowSystem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_color_scheme_demo);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) {
mapFragment.getMapAsync(this);
}
buttonLight = findViewById(R.id.map_color_light_mode);
buttonDark = findViewById(R.id.map_color_dark_mode);
buttonFollowSystem = findViewById(R.id.map_color_follow_system_mode);
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
googleMap.setMapColorScheme(MapColorScheme.DARK);
buttonLight.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.LIGHT));
buttonDark.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.DARK));
buttonFollowSystem.setOnClickListener(view -> googleMap.setMapColorScheme(MapColorScheme.FOLLOW_SYSTEM));
}
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
package com.example.mapdemo.polyline;
package com.example.mapdemo;
import android.graphics.Color;
import android.os.Bundle;

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 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
https://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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--We need to add the map id to make advanced markers work. For more information,
check out https://developers.google.com/maps/documentation/get-map-id#create-a-map-id. -->
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:backgroundColor="#fff0b2dd"
map:mapId="@string/map_id" />
<LinearLayout
android:id="@+id/cloud_styling_basic_demo_mode_buttons"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#D000"
android:orientation="horizontal">
<Button
android:id="@+id/map_color_light_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_light_mode" />
<Button
android:id="@+id/map_color_dark_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_dark_mode" />
<Button
android:id="@+id/map_color_follow_system_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_follow_system_mode" />
</LinearLayout>
</RelativeLayout>

View File

@ -78,6 +78,8 @@
<string name="map_not_ready">Map is not ready yet</string>
<string name="map_in_pager_demo_label">Map In Pager</string>
<string name="map_in_pager_demo_description">Demonstrates how to add a map to a ViewPager.</string>
<string name="map_color_scheme_demo_description">Demonstrates how to use the MapColorScheme.</string>
<string name="map_color_scheme_demo_label">MapColorScheme</string>
<string name="marker_demo_label">Markers</string>
<string name="marker_close_info_window_on_retap_demo_label">Marker Close Info Window on Retap</string>
<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 @@
description="Text displayed below the Background Color Customization - Programmatic demo title.">Demonstrates how to programmatically set a custom background color to a map.</string>
<string name="show_map_tiles">Show Map Tiles</string>
<!-- Map Color Scheme -->
<string name="map_color_light_mode">Light</string>
<string name="map_color_dark_mode">Dark</string>
<string name="map_color_follow_system_mode">Follow System\n</string>
</resources>

View File

@ -49,17 +49,16 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'androidx.appcompat:appcompat:1.7.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.3.1"
implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.android.volley:volley:1.2.1'
// GMS
gmsImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.3'
gmsImplementation 'com.google.maps.android:maps-ktx:5.1.0'
gmsImplementation 'com.google.maps.android:maps-ktx:5.1.1'
// Below is used to run the easypermissions library to manage location permissions
// EasyPermissions is needed to help us request for permission to access location

View File

@ -15,62 +15,63 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AdvancedMarkersDemoActivity" />
<activity android:name=".BasicMapDemoActivity" />
<activity android:name=".BackgroundColorCustomizationDemoActivity" />
<activity android:name=".BackgroundColorCustomizationProgrammaticDemoActivity" />
<activity android:name=".CameraDemoActivity" />
<activity android:name=".CameraClampingDemoActivity" />
<activity android:name=".CloudBasedMapStylingDemoActivity" />
<activity android:name=".CircleDemoActivity" />
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
<activity android:name=".EventsDemoActivity" />
<activity android:name=".GroundOverlayDemoActivity" />
<activity android:name=".IndoorDemoActivity" />
<activity android:name=".LayersDemoActivity" />
<activity android:name=".LiteDemoActivity" />
<activity android:name=".LiteListDemoActivity" />
<activity android:name=".LocationSourceDemoActivity" />
<activity android:name=".MapInPagerDemoActivity" />
<activity android:name=".MarkerDemoActivity" />
<activity android:name=".MultiMapDemoActivity" />
<activity android:name=".MyLocationDemoActivity" />
<activity android:name=".OptionsDemoActivity" />
<activity android:name=".PolygonDemoActivity" />
<activity android:name=".ProgrammaticDemoActivity" />
<activity android:name=".RawMapViewDemoActivity" />
<activity android:name=".RetainMapDemoActivity" />
<activity android:name=".SaveStateDemoActivity" />
<activity android:name=".SnapshotDemoActivity" />
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
<activity android:name=".StyledMapDemoActivity" />
<activity android:name=".TagsDemoActivity" />
<activity android:name=".TileCoordinateDemoActivity" />
<activity android:name=".TileOverlayDemoActivity" />
<activity android:name=".UiSettingsDemoActivity" />
<activity android:name=".VisibleRegionDemoActivity" />
<activity android:name=".polyline.PolylineDemoActivity" />
</application>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AdvancedMarkersDemoActivity" />
<activity android:name=".BasicMapDemoActivity" />
<activity android:name=".BackgroundColorCustomizationDemoActivity" />
<activity android:name=".BackgroundColorCustomizationProgrammaticDemoActivity" />
<activity android:name=".CameraDemoActivity" />
<activity android:name=".CameraClampingDemoActivity" />
<activity android:name=".CloudBasedMapStylingDemoActivity" />
<activity android:name=".CircleDemoActivity" />
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
<activity android:name=".EventsDemoActivity" />
<activity android:name=".GroundOverlayDemoActivity" />
<activity android:name=".IndoorDemoActivity" />
<activity android:name=".LayersDemoActivity" />
<activity android:name=".LiteDemoActivity" />
<activity android:name=".LiteListDemoActivity" />
<activity android:name=".LocationSourceDemoActivity" />
<activity android:name=".MapInPagerDemoActivity" />
<activity android:name=".MapColorSchemeActivity" />
<activity android:name=".MarkerDemoActivity" />
<activity android:name=".MultiMapDemoActivity" />
<activity android:name=".MyLocationDemoActivity" />
<activity android:name=".OptionsDemoActivity" />
<activity android:name=".PolygonDemoActivity" />
<activity android:name=".ProgrammaticDemoActivity" />
<activity android:name=".RawMapViewDemoActivity" />
<activity android:name=".RetainMapDemoActivity" />
<activity android:name=".SaveStateDemoActivity" />
<activity android:name=".SnapshotDemoActivity" />
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
<activity android:name=".StyledMapDemoActivity" />
<activity android:name=".TagsDemoActivity" />
<activity android:name=".TileCoordinateDemoActivity" />
<activity android:name=".TileOverlayDemoActivity" />
<activity android:name=".UiSettingsDemoActivity" />
<activity android:name=".VisibleRegionDemoActivity" />
<activity android:name=".polyline.PolylineDemoActivity" />
</application>
</manifest>

View File

@ -48,13 +48,12 @@ private val TAG = AdvancedMarkersDemoActivity::class.java.name
*/
// [START maps_android_sample_marker_advanced]
class AdvancedMarkersDemoActivity : AppCompatActivity(), OnMapReadyCallback {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.advanced_markers_demo)
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(this)
}
override fun onMapReady(map: GoogleMap) {

View File

@ -107,10 +107,15 @@ class DemoDetailsList {
R.string.map_in_pager_demo_description,
MapInPagerDemoActivity::class.java
),
DemoDetails(
R.string.map_color_scheme_demo_label,
R.string.map_color_scheme_demo_description,
MapColorSchemeActivity::class.java
),
DemoDetails(
R.string.markers_demo_label,
R.string.markers_demo_description,
MarkerDemoActivity::class.java
MapColorSchemeActivity::class.java
),
DemoDetails(
R.string.multi_map_demo_label,

View File

@ -0,0 +1,67 @@
/*
* Copyright 2024 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
*
* https://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.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.MapColorScheme
class MapColorSchemeActivity :
AppCompatActivity(), OnMapReadyCallback {
/** This is ok to be lateinit as it is initialised in onMapReady */
private lateinit var map: GoogleMap
private lateinit var buttonLight: Button
private lateinit var buttonDark: Button
private lateinit var buttonFollowSystem: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.map_color_scheme_demo)
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(this)
buttonLight = findViewById(R.id.map_color_light_mode)
buttonDark = findViewById(R.id.map_color_dark_mode)
buttonFollowSystem = findViewById(R.id.map_color_follow_system_mode)
}
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
map.mapColorScheme = MapColorScheme.DARK
buttonLight.setOnClickListener {
map.mapColorScheme = MapColorScheme.LIGHT
}
buttonDark.setOnClickListener {
map.mapColorScheme = MapColorScheme.DARK
}
buttonFollowSystem.setOnClickListener {
map.mapColorScheme = MapColorScheme.FOLLOW_SYSTEM
}
}
}

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 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
https://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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--We need to add the map id to make advanced markers work. For more information,
check out https://developers.google.com/maps/documentation/get-map-id#create-a-map-id. -->
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:backgroundColor="#fff0b2dd"
map:mapId="@string/map_id" />
<LinearLayout
android:id="@+id/cloud_styling_basic_demo_mode_buttons"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#D000"
android:orientation="horizontal">
<Button
android:id="@+id/map_color_light_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_light_mode" />
<Button
android:id="@+id/map_color_dark_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_dark_mode" />
<Button
android:id="@+id/map_color_follow_system_mode"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_color_follow_system_mode" />
</LinearLayout>
</RelativeLayout>

View File

@ -127,6 +127,8 @@
<string name="flat">Flat</string>
<string name="reset_map">Reset</string>
<string name="map_not_ready">Map is not ready</string>
<string name="map_color_scheme_demo_description">Demonstrates how to use the MapColorScheme.</string>
<string name="map_color_scheme_demo_label">MapColorScheme</string>
<string name="markers_demo_description">Demonstrates how to add Markers to a map.</string>
<string name="markers_demo_label">Markers</string>
<string name="on_marker_drag">onMarkerDrag. Current Position: (%1$f, %2$f)</string>
@ -351,6 +353,9 @@
<string name="style_label_default">Default</string>
<string name="style_choose">Choose style</string>
<string name="style_set_to">Style set to: %1$s</string>
<string name="map_color_light_mode">Light</string>
<string name="map_color_dark_mode">Dark</string>
<string name="map_color_follow_system_mode">Follow System\n</string>
</resources>