From 1fd41a2ca7edb2588855d2242fc412477b0425bf Mon Sep 17 00:00:00 2001
From: Dale Hawkins <107309+dkhawk@users.noreply.github.com>
Date: Tue, 18 Aug 2026 15:44:58 -0600
Subject: [PATCH] feat(demos): polish Events, LocationSource, Marker, and
Layers demo activities
- Modernize EventsDemoActivity with Material text view styles and coordinate formatting
- Fix toolbar title and custom location provider handling in LocationSourceDemoActivity
- Clean up layout constraints, borderless button styling, and checkbox state in MarkerDemo and LayersDemo
---
.../src/main/res/layout/events_demo.xml | 11 +-
.../src/main/res/layout/layers_demo.xml | 18 +--
.../src/main/res/layout/marker_demo.xml | 123 ++++++++++--------
.../example/mapdemo/EventsDemoActivity.java | 40 +++++-
.../example/mapdemo/LayersDemoActivity.java | 11 +-
.../mapdemo/LocationSourceDemoActivity.java | 7 +-
.../example/mapdemo/MarkerDemoActivity.java | 11 +-
.../example/mapdemo/MarkerDemoActivity.java | 11 +-
.../example/kotlindemos/EventsDemoActivity.kt | 34 ++++-
.../example/kotlindemos/LayersDemoActivity.kt | 12 +-
.../kotlindemos/LocationSourceDemoActivity.kt | 22 ++--
.../example/kotlindemos/MarkerDemoActivity.kt | 16 ++-
.../example/kotlindemos/MarkerDemoActivity.kt | 16 ++-
13 files changed, 220 insertions(+), 112 deletions(-)
diff --git a/ApiDemos/project/common-ui/src/main/res/layout/events_demo.xml b/ApiDemos/project/common-ui/src/main/res/layout/events_demo.xml
index d53a3ed44..709d4b2fc 100644
--- a/ApiDemos/project/common-ui/src/main/res/layout/events_demo.xml
+++ b/ApiDemos/project/common-ui/src/main/res/layout/events_demo.xml
@@ -1,5 +1,5 @@
-
+ app:title="@string/marker_demo_label"
+ app:titleTextColor="?attr/colorOnPrimary" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:id="@+id/map_frame"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/top_controls">
+ android:padding="8dp">
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/EventsDemoActivity.java b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/EventsDemoActivity.java
index 6699be4ee..5114f7d36 100644
--- a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/EventsDemoActivity.java
+++ b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/EventsDemoActivity.java
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
import android.os.Bundle;
import android.widget.TextView;
+import java.util.Locale;
import androidx.appcompat.app.AppCompatActivity;
@@ -34,7 +35,7 @@
// [START maps_android_sample_events]
public class EventsDemoActivity extends SamplesBaseActivity
implements OnMapClickListener, OnMapLongClickListener, OnCameraIdleListener,
- OnMapReadyCallback {
+ GoogleMap.OnCameraMoveListener, OnMapReadyCallback {
private TextView tapTextView;
private TextView cameraTextView;
@@ -59,22 +60,51 @@ public void onMapReady(GoogleMap map) {
this.map = map;
this.map.setOnMapClickListener(this);
this.map.setOnMapLongClickListener(this);
+ this.map.setOnCameraMoveListener(this);
this.map.setOnCameraIdleListener(this);
+ updateCameraPosition();
}
@Override
public void onMapClick(LatLng point) {
- tapTextView.setText("tapped, point=" + point);
+ String lat = String.format(Locale.US, "%.6f", point.latitude);
+ String lng = String.format(Locale.US, "%.6f", point.longitude);
+ tapTextView.setText(getString(com.example.common_ui.R.string.events_tapped_format, lat, lng));
}
@Override
public void onMapLongClick(LatLng point) {
- tapTextView.setText("long pressed, point=" + point);
+ String lat = String.format(Locale.US, "%.6f", point.latitude);
+ String lng = String.format(Locale.US, "%.6f", point.longitude);
+ tapTextView.setText(getString(com.example.common_ui.R.string.events_long_pressed_format, lat, lng));
+ }
+
+ @Override
+ public void onCameraMove() {
+ updateCameraPosition();
}
@Override
public void onCameraIdle() {
- cameraTextView.setText(map.getCameraPosition().toString());
+ updateCameraPosition();
+ }
+
+ private void updateCameraPosition() {
+ if (map == null) return;
+ com.google.android.gms.maps.model.CameraPosition pos = map.getCameraPosition();
+ String lat = String.format(Locale.US, "%.6f", pos.target.latitude);
+ String lng = String.format(Locale.US, "%.6f", pos.target.longitude);
+ String zoom = String.format(Locale.US, "%.1f", pos.zoom);
+ String tilt = String.format(Locale.US, "%.1f", pos.tilt);
+ String bearing = String.format(Locale.US, "%.1f", pos.bearing);
+ cameraTextView.setText(getString(
+ com.example.common_ui.R.string.events_camera_position_format,
+ lat,
+ lng,
+ zoom,
+ tilt,
+ bearing
+ ));
}
}
// [END maps_android_sample_events]
\ No newline at end of file
diff --git a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LayersDemoActivity.java b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LayersDemoActivity.java
index c10f19823..259bdec86 100755
--- a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LayersDemoActivity.java
+++ b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LayersDemoActivity.java
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -88,6 +88,15 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
+
+ com.google.android.gms.maps.model.CameraPosition initialPosition =
+ new com.google.android.gms.maps.model.CameraPosition.Builder()
+ .target(new com.google.android.gms.maps.model.LatLng(-33.8688, 151.2093))
+ .zoom(16.5f)
+ .tilt(40.0f)
+ .build();
+ mMap.moveCamera(com.google.android.gms.maps.CameraUpdateFactory.newCameraPosition(initialPosition));
+
updateMapType();
updateTraffic();
updateMyLocation();
diff --git a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LocationSourceDemoActivity.java b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LocationSourceDemoActivity.java
index d3e3fd53b..e3c6e4825 100644
--- a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LocationSourceDemoActivity.java
+++ b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/LocationSourceDemoActivity.java
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -90,6 +90,11 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.example.common_ui.R.layout.basic_demo);
+ androidx.appcompat.widget.Toolbar toolbar = findViewById(com.example.common_ui.R.id.top_bar);
+ if (toolbar != null) {
+ toolbar.setTitle(com.example.common_ui.R.string.location_source_demo_label);
+ }
+
mLocationSource = new LongPressLocationSource();
SupportMapFragment mapFragment =
diff --git a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java
index b3609b4c4..5ce1ba105 100644
--- a/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java
+++ b/ApiDemos/project/java-app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Looper;
import android.os.SystemClock;
import com.example.common_ui.R;
@@ -429,7 +430,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(mPerth)) {
// This causes the marker at Perth to bounce into position when it is clicked.
- final Handler handler = new Handler();
+ final Handler handler = new Handler(Looper.getMainLooper());
final long start = SystemClock.uptimeMillis();
final long duration = 1500;
@@ -485,17 +486,17 @@ public void onInfoWindowLongClick(Marker marker) {
@Override
public void onMarkerDragStart(Marker marker) {
- binding.topText.setText("onMarkerDragStart");
+ binding.topText.setText(R.string.on_marker_drag_start);
}
@Override
public void onMarkerDragEnd(Marker marker) {
- binding.topText.setText("onMarkerDragEnd");
+ binding.topText.setText(R.string.on_marker_drag_end);
}
@Override
public void onMarkerDrag(Marker marker) {
- binding.topText.setText("onMarkerDrag. Current Position: " + marker.getPosition());
+ binding.topText.setText(getString(R.string.on_marker_drag, marker.getPosition().latitude, marker.getPosition().longitude));
}
}
diff --git a/ApiDemos/project/java-app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java b/ApiDemos/project/java-app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java
index 79c5a1f64..1a266fe08 100644
--- a/ApiDemos/project/java-app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java
+++ b/ApiDemos/project/java-app/src/v3/java/com/example/mapdemo/MarkerDemoActivity.java
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
@@ -435,7 +436,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(mPerth)) {
// This causes the marker at Perth to bounce into position when it is clicked.
- final Handler handler = new Handler();
+ final Handler handler = new Handler(Looper.getMainLooper());
final long start = SystemClock.uptimeMillis();
final long duration = 1500;
@@ -491,17 +492,17 @@ public void onInfoWindowLongClick(Marker marker) {
@Override
public void onMarkerDragStart(Marker marker) {
- mTopText.setText("onMarkerDragStart");
+ mTopText.setText(com.example.common_ui.R.string.on_marker_drag_start);
}
@Override
public void onMarkerDragEnd(Marker marker) {
- mTopText.setText("onMarkerDragEnd");
+ mTopText.setText(com.example.common_ui.R.string.on_marker_drag_end);
}
@Override
public void onMarkerDrag(Marker marker) {
- mTopText.setText("onMarkerDrag. Current Position: " + marker.getPosition());
+ mTopText.setText(getString(com.example.common_ui.R.string.on_marker_drag, marker.getPosition().latitude, marker.getPosition().longitude));
}
}
diff --git a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/EventsDemoActivity.kt b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/EventsDemoActivity.kt
index 384eba27a..1658f11ad 100644
--- a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/EventsDemoActivity.kt
+++ b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/EventsDemoActivity.kt
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.example.common_ui.R
+import java.util.Locale
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMap.*
@@ -29,7 +30,7 @@ import com.google.android.gms.maps.model.LatLng
*/
// [START maps_android_sample_events]
class EventsDemoActivity : SamplesBaseActivity(), OnMapClickListener,
- OnMapLongClickListener, OnCameraIdleListener, OnMapReadyCallback {
+ OnMapLongClickListener, OnCameraIdleListener, OnCameraMoveListener, OnMapReadyCallback {
private lateinit var tapTextView: TextView
private lateinit var cameraTextView: TextView
@@ -42,28 +43,47 @@ class EventsDemoActivity : SamplesBaseActivity(), OnMapClickListener,
cameraTextView = findViewById(R.id.camera_text)
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(this)
- applyInsets(findViewById(R.id.map_container))
+ applyInsets(findViewById(R.id.map_container))
}
override fun onMapReady(googleMap: GoogleMap) {
- // return early if the map was not initialised properly
map = googleMap
map.setOnMapClickListener(this)
map.setOnMapLongClickListener(this)
+ map.setOnCameraMoveListener(this)
map.setOnCameraIdleListener(this)
+ updateCameraPosition()
}
override fun onMapClick(point: LatLng) {
- tapTextView.text = "tapped, point=$point"
+ val lat = String.format(Locale.US, "%.6f", point.latitude)
+ val lng = String.format(Locale.US, "%.6f", point.longitude)
+ tapTextView.text = getString(R.string.events_tapped_format, lat, lng)
}
override fun onMapLongClick(point: LatLng) {
- tapTextView.text = "long pressed, point=$point"
+ val lat = String.format(Locale.US, "%.6f", point.latitude)
+ val lng = String.format(Locale.US, "%.6f", point.longitude)
+ tapTextView.text = getString(R.string.events_long_pressed_format, lat, lng)
+ }
+
+ override fun onCameraMove() {
+ updateCameraPosition()
}
override fun onCameraIdle() {
+ updateCameraPosition()
+ }
+
+ private fun updateCameraPosition() {
if (!::map.isInitialized) return
- cameraTextView.text = map.cameraPosition.toString()
+ val pos = map.cameraPosition
+ val lat = String.format(Locale.US, "%.6f", pos.target.latitude)
+ val lng = String.format(Locale.US, "%.6f", pos.target.longitude)
+ val zoom = String.format(Locale.US, "%.1f", pos.zoom)
+ val tilt = String.format(Locale.US, "%.1f", pos.tilt)
+ val bearing = String.format(Locale.US, "%.1f", pos.bearing)
+ cameraTextView.text = getString(R.string.events_camera_position_format, lat, lng, zoom, tilt, bearing)
}
}
// [END maps_android_sample_events]
\ No newline at end of file
diff --git a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LayersDemoActivity.kt b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LayersDemoActivity.kt
index 42167e088..35d2c64fe 100644
--- a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LayersDemoActivity.kt
+++ b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LayersDemoActivity.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Google LLC
+ * Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import android.widget.CheckBox
import android.widget.Spinner
import com.example.common_ui.R
+import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_HYBRID
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_NONE
@@ -36,6 +37,8 @@ import com.google.android.gms.maps.GoogleMap.MAP_TYPE_SATELLITE
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_TERRAIN
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
+import com.google.android.gms.maps.model.CameraPosition
+import com.google.android.gms.maps.model.LatLng
import pub.devrel.easypermissions.AfterPermissionGranted
import pub.devrel.easypermissions.EasyPermissions
@@ -106,6 +109,13 @@ class LayersDemoActivity :
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
+ val initialPosition = CameraPosition.builder()
+ .target(LatLng(-33.8688, 151.2093))
+ .zoom(16.5f)
+ .tilt(40.0f)
+ .build()
+ map.moveCamera(CameraUpdateFactory.newCameraPosition(initialPosition))
+
updateMapType()
// check the state of all checkboxes and update the map accordingly
diff --git a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LocationSourceDemoActivity.kt b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LocationSourceDemoActivity.kt
index 21fad59e8..55cb9d63f 100644
--- a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LocationSourceDemoActivity.kt
+++ b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/LocationSourceDemoActivity.kt
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -21,9 +21,8 @@ import android.os.Bundle
import android.view.View
import androidx.core.app.ActivityCompat
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.LifecycleObserver
-import androidx.lifecycle.OnLifecycleEvent
+import androidx.lifecycle.DefaultLifecycleObserver
+import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.example.common_ui.R
import com.google.android.gms.maps.GoogleMap
@@ -34,6 +33,8 @@ import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.ktx.awaitMap
+import kotlinx.coroutines.launch
+
/**
* This shows how to use a custom location source.
*/
@@ -44,13 +45,14 @@ class LocationSourceDemoActivity : SamplesBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.basic_demo)
+ findViewById(R.id.top_bar)?.setTitle(R.string.location_source_demo_label)
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
- lifecycleScope.launchWhenCreated {
+ lifecycleScope.launch {
val map = mapFragment.awaitMap()
init(map = map)
}
lifecycle.addObserver(locationSource)
- applyInsets(findViewById(R.id.map_container))
+ applyInsets(findViewById(R.id.map_container))
}
@SuppressLint("MissingPermission")
@@ -72,7 +74,7 @@ class LocationSourceDemoActivity : SamplesBaseActivity() {
* at
* the point at which a user long pressed the map.
*/
-private class LongPressLocationSource : LocationSource, OnMapLongClickListener, LifecycleObserver {
+private class LongPressLocationSource : LocationSource, OnMapLongClickListener, DefaultLifecycleObserver {
private var listener: OnLocationChangedListener? = null
@@ -104,13 +106,11 @@ private class LongPressLocationSource : LocationSource, OnMapLongClickListener,
listener?.onLocationChanged(location)
}
- @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
- fun onPause() {
+ override fun onPause(owner: LifecycleOwner) {
paused = true
}
- @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
- fun onResume() {
+ override fun onResume(owner: LifecycleOwner) {
paused = false
}
}
diff --git a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt
index ce22a382e..61915601f 100644
--- a/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt
+++ b/ApiDemos/project/kotlin-app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Google LLC
+ * Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
+import android.os.Looper
import android.os.SystemClock
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
@@ -36,7 +37,9 @@ import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.content.res.ResourcesCompat
+import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.DrawableCompat
+import androidx.core.graphics.toColorInt
import com.example.common_ui.R
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
@@ -290,7 +293,7 @@ class MarkerDemoActivity :
position = places.getValue("ALICE_SPRINGS"),
title = "Alice Springs",
icon = vectorToBitmap(
- R.drawable.ic_android, Color.parseColor("#A4C639"))
+ R.drawable.ic_android, "#A4C639".toColorInt())
),
// More markers for good measure
@@ -363,8 +366,11 @@ class MarkerDemoActivity :
Log.e(TAG, "Resource not found")
return BitmapDescriptorFactory.defaultMarker()
}
- val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth,
- vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
+ val bitmap = createBitmap(
+ vectorDrawable.intrinsicWidth,
+ vectorDrawable.intrinsicHeight,
+ Bitmap.Config.ARGB_8888
+ )
val canvas = Canvas(bitmap)
vectorDrawable.setBounds(0, 0, canvas.width, canvas.height)
DrawableCompat.setTint(vectorDrawable, color)
@@ -401,7 +407,7 @@ class MarkerDemoActivity :
if (marker.position == places.getValue("PERTH")) {
// This causes the marker at Perth to bounce into position when it is clicked.
- val handler = Handler()
+ val handler = Handler(Looper.getMainLooper())
val start = SystemClock.uptimeMillis()
val duration = 1500
diff --git a/ApiDemos/project/kotlin-app/src/v3/java/com/example/kotlindemos/MarkerDemoActivity.kt b/ApiDemos/project/kotlin-app/src/v3/java/com/example/kotlindemos/MarkerDemoActivity.kt
index 19db8ca20..afdc121fa 100644
--- a/ApiDemos/project/kotlin-app/src/v3/java/com/example/kotlindemos/MarkerDemoActivity.kt
+++ b/ApiDemos/project/kotlin-app/src/v3/java/com/example/kotlindemos/MarkerDemoActivity.kt
@@ -6,7 +6,7 @@
* corresponding file under the `app/src/gms` directory.
*/
/*
- * Copyright 2018 Google LLC
+ * Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
+import android.os.Looper
import android.os.SystemClock
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
@@ -46,7 +47,9 @@ import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
+import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.DrawableCompat
+import androidx.core.graphics.toColorInt
import com.google.android.libraries.maps.CameraUpdateFactory
import com.google.android.libraries.maps.GoogleMap
import com.google.android.libraries.maps.GoogleMap.InfoWindowAdapter
@@ -299,7 +302,7 @@ class MarkerDemoActivity :
position = places.getValue("ALICE_SPRINGS"),
title = "Alice Springs",
icon = vectorToBitmap(
- com.example.common_ui.R.drawable.ic_android, Color.parseColor("#A4C639"))
+ com.example.common_ui.R.drawable.ic_android, "#A4C639".toColorInt())
),
// More markers for good measure
@@ -371,8 +374,11 @@ class MarkerDemoActivity :
Log.e(TAG, "Resource not found")
return BitmapDescriptorFactory.defaultMarker()
}
- val bitmap = Bitmap.createBitmap(vectorDrawable.intrinsicWidth,
- vectorDrawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
+ val bitmap = createBitmap(
+ vectorDrawable.intrinsicWidth,
+ vectorDrawable.intrinsicHeight,
+ Bitmap.Config.ARGB_8888
+ )
val canvas = Canvas(bitmap)
vectorDrawable.setBounds(0, 0, canvas.width, canvas.height)
DrawableCompat.setTint(vectorDrawable, color)
@@ -415,7 +421,7 @@ class MarkerDemoActivity :
if (marker.position == places.getValue("PERTH")) {
// This causes the marker at Perth to bounce into position when it is clicked.
- val handler = Handler()
+ val handler = Handler(Looper.getMainLooper())
val start = SystemClock.uptimeMillis()
val duration = 1500