Skip to content

Commit

Permalink
feat: added Kotlin MapColorScheme sample (#1712)
Browse files Browse the repository at this point in the history
* feat: added Kotlin MapColorScheme sample

* chore: added header in XML file

* feat: added Kotlin MapColorScheme sample

* feat: Java demo
  • Loading branch information
kikoso authored Jul 22, 2024
1 parent 58cf1c3 commit 4297488
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 68 deletions.
5 changes: 4 additions & 1 deletion ApiDemos/java/app/src/gms/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@
<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" />
<activity
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package com.example.mapdemo;

import com.example.mapdemo.polyline.PolylineDemoActivity;

/**
* A list of all the demos we have available.
*/
Expand Down Expand Up @@ -79,6 +77,9 @@ private 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.widget.ListAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

/**
Expand All @@ -45,8 +46,9 @@ public CustomArrayAdapter(Context context, DemoDetails[] demos) {
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;
Expand Down Expand Up @@ -75,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {

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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions ApiDemos/java/app/src/main/res/layout/map_color_scheme_demo.xml
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 6 additions & 0 deletions ApiDemos/java/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
5 changes: 2 additions & 3 deletions ApiDemos/kotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
113 changes: 57 additions & 56 deletions ApiDemos/kotlin/app/src/gms/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 4297488

Please sign in to comment.