Skip to content

Commit

Permalink
feat: added Kotlin MapColorScheme sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoso committed Jul 22, 2024
1 parent 58cf1c3 commit 5c40f93
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
60 changes: 60 additions & 0 deletions ApiDemos/kotlin/app/src/gms/res/layout/map_color_scheme_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--
Copyright 2023 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.
-->

<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>

0 comments on commit 5c40f93

Please sign in to comment.