Skip to content

Commit 32f2c9f

Browse files
kikosodkhawk
andauthored
feat: updated places 5.0.0 (#960)
* feat: Overhaul snippets app into a multi-activity demo This commit transforms the snippets project from a single-activity example into a comprehensive, multi-activity demonstration app. It now serves as a catalog of Places SDK features, with separate, self-contained examples for both Java and Kotlin. Key changes: - **New App Structure**: - `KotlinMainActivity` is the new launcher, presenting a `RecyclerView` of available demos. A parallel `JavaMainActivity` is also included. - A `MainApplication` class now handles the centralized initialization of the Places SDK. - The app now supports an edge-to-edge display theme. - **New Demo Activities**: - **Current Place**: Finds and displays a list of likely places near the user's current location, handling permission requests. - **Place Autocomplete**: Demonstrates the `AutocompleteSupportFragment`, the autocomplete intent, and programmatic predictions, with a toggle for location bias vs. restriction. - **Place Details**: Fetches and displays basic details for a specific Place ID. - **Place Photos**: Fetches and displays a photo and its attributions for a place. - **Places Icon**: Shows how to retrieve and display a place's icon mask and background color. - **Is Open**: Checks if a place is open, using both a `Place` object and a Place ID. - **UI and Layouts**: - Added dedicated XML layouts for each new activity and for `RecyclerView` list items. - Implemented standard UI patterns with `MaterialToolbar`, `RecyclerView`, and `ConstraintLayout`. - **Build & Dependency Updates**: - Upgraded Gradle to version 9.1.0. - Updated various AndroidX and Material Design library versions. - Added `core-ktx` dependency. * feat: updated places to 5.0.0 * feat: added PlaceDetailsCompose * feat: added PlaceDetailsUIKit * feat: added PlacesUIKit3D * feat: snippets * feat: updated CurrentPlace, PlaceDetails * feat: header * feat: place autocomplete * fix: removed duplicated --------- Co-authored-by: dkhawk <107309+dkhawk@users.noreply.github.com>
1 parent 14bc347 commit 32f2c9f

File tree

21 files changed

+175
-105
lines changed

21 files changed

+175
-105
lines changed

PlaceDetailsCompose/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ dependencies {
116116
implementation(libs.androidx.activity.compose)
117117
implementation(libs.androidx.lifecycle.viewmodel.compose)
118118
implementation(libs.androidx.fragment.ktx)
119+
implementation(libs.androidx.compose.material.icons.core)
119120

120121
// --- Google Play Services ---
121122
// These are the essential libraries for this sample, providing Maps and Places functionality.

PlaceDetailsCompose/gradle/libs.versions.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@
77
# --- Core Android & Kotlin ---
88
# These are the fundamental versions for building the Android app.
99
agp = "8.13.0"
10-
kotlin = "2.2.10"
10+
kotlin = "2.2.20"
1111
coreKtx = "1.17.0"
1212
fragmentKtx = "1.8.9"
1313
material = "1.13.0"
14-
lifecycleViewModelCompose = "2.9.3"
14+
lifecycleViewModelCompose = "2.9.4"
15+
material-icons = "1.7.8"
1516

1617
# --- Jetpack Compose ---
1718
# Versions for Jetpack Compose, Android's modern UI toolkit.
1819
# The Compose BOM (Bill of Materials) manages the versions of different Compose libraries
1920
# to ensure they are compatible with each other.
20-
composeBom = "2025.08.01"
21-
activityCompose = "1.10.1"
22-
ui = "1.9.0"
23-
uiTooling = "1.9.0"
24-
uiViewbinding = "1.9.0"
21+
composeBom = "2025.09.01"
22+
activityCompose = "1.11.0"
23+
androidxUi = "1.9.2"
2524

2625
# --- Google Services (Maps, Places, Location) ---
2726
# Versions for Google Play Services libraries, which are essential for this sample.
2827
googleMaps = "19.2.0"
29-
places = "4.4.1"
28+
places = "5.0.0"
3029
playServicesLocation = "21.3.0" # Required for the FusedLocationProviderClient to get the device's location.
31-
mapsCompose = "6.10.0"
30+
mapsCompose = "6.11.0"
3231

3332
# --- Testing ---
3433
# Versions for testing libraries.
@@ -50,16 +49,17 @@ androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref =
5049
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewModelCompose" }
5150
androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "fragmentKtx" }
5251
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
52+
androidx-compose-material-icons-core = { module = "androidx.compose.material:material-icons-core", version.ref = "material-icons" }
5353

5454
# --- Jetpack Compose ---
5555
# The Compose BOM (Bill of Materials) simplifies dependency management by coordinating the versions of various Compose libraries.
5656
# By using platform(), we don't need to specify versions for individual Compose artifacts.
5757
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
5858
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
5959
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
60-
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" }
61-
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "ui" }
62-
androidx-ui-viewbinding = { group = "androidx.compose.ui", name = "ui-viewbinding", version.ref = "uiViewbinding" }
60+
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidxUi" }
61+
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidxUi" }
62+
androidx-ui-viewbinding = { group = "androidx.compose.ui", name = "ui-viewbinding", version.ref = "androidxUi" }
6363

6464
# --- Google Services (Maps, Places, Location) ---
6565
# These are the key libraries for this sample app, providing map, place details, and location functionalities.

PlaceDetailsUIKit/gradle/libs.versions.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ targetSdk = "36"
1414
# --- Core Android & Kotlin ---
1515
# These are the fundamental versions for building the Android app.
1616
agp = "8.13.0"
17-
kotlin = "2.2.10"
17+
kotlin = "2.2.20"
1818
coreKtx = "1.17.0"
1919
appcompat = "1.7.1"
20-
activity = "1.10.1"
21-
lifecycle = "2.9.3"
20+
activity = "1.11.0"
21+
lifecycle = "2.9.4"
2222
fragmentKtx = "1.8.9"
2323
material = "1.13.0"
2424
constraintlayout = "2.2.1"
@@ -27,15 +27,14 @@ constraintlayout = "2.2.1"
2727
# Versions for Jetpack Compose, Android's modern UI toolkit.
2828
# The Compose BOM (Bill of Materials) manages the versions of different Compose libraries
2929
# to ensure they are compatible with each other.
30-
composeBom = "2025.08.01"
31-
activityCompose = "1.10.1"
32-
ui = "1.9.0"
33-
uiTooling = "1.9.0"
30+
composeBom = "2025.09.01"
31+
activityCompose = "1.11.0"
32+
ui = "1.9.2"
3433

3534
# --- Google Services (Maps, Places, Location) ---
3635
# Versions for Google Play Services libraries, which are essential for this sample.
3736
googleMaps = "19.2.0"
38-
places = "4.4.1"
37+
places = "5.0.0"
3938
playServicesLocation = "21.3.0" # Required for the FusedLocationProviderClient to get the device's location.
4039

4140
# --- Testing ---
@@ -68,7 +67,7 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const
6867
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
6968
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
7069
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
71-
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" }
70+
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "ui" }
7271
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "ui" }
7372

7473
# --- Google Services (Maps, Places, Location) ---

PlacesUIKit3D/gradle/libs.versions.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@
77
# --- Core Android & Kotlin ---
88
# These are the fundamental versions for building the Android app.
99
agp = "8.13.0"
10-
kotlin = "2.2.10"
10+
kotlin = "2.2.20"
1111
coreKtx = "1.17.0"
12-
lifecycleRuntimeKtx = "2.9.3"
12+
lifecycleRuntimeKtx = "2.9.4"
1313
fragmentKtx = "1.8.9"
1414
material = "1.13.0"
1515

1616
# --- Jetpack Compose ---
1717
# Versions for Jetpack Compose, Android's modern UI toolkit.
1818
# The Compose BOM (Bill of Materials) manages the versions of different Compose libraries
1919
# to ensure they are compatible with each other.
20-
composeBom = "2025.08.01"
21-
activityCompose = "1.10.1"
20+
composeBom = "2025.09.01"
21+
activityCompose = "1.11.0"
2222
fragmentCompose = "1.8.9"
2323

2424
# --- Google Services (Maps, Places, Location) ---
2525
# Versions for Google Play Services libraries, which are essential for this sample.
2626
playServicesMaps3d = "0.0.2"
27-
places = "4.4.1"
27+
places = "5.0.0"
2828
mapsUtilsKtx = "5.2.0"
2929

3030
# --- Dependency Injection ---
3131
# Version for Hilt, a dependency injection library for Android.
32-
hilt = "2.57.1"
32+
hilt = "2.57.2"
3333

3434
# --- Testing ---
3535
# Versions for testing libraries.
3636
junit = "4.13.2"
3737
junitVersion = "1.3.0"
3838
espressoCore = "3.7.0"
39-
truth = "1.4.4"
39+
truth = "1.4.5"
4040

4141
# --- Gradle Plugins ---
4242
# Versions for Gradle plugins used in the build process.
4343
secretsGradlePlugin = "2.0.1"
44-
ksp = "2.2.10-2.0.2"
45-
kotlinParcelize = "2.2.10"
44+
ksp = "2.2.20-2.0.3"
45+
kotlinParcelize = "2.2.20"
4646

4747
# --- Miscellaneous ---
4848
# Other libraries used in the project.

demo-java/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.google.android.libraries.places.api.model.AddressComponent;
5353
import com.google.android.libraries.places.api.model.AddressComponents;
5454
import com.google.android.libraries.places.api.model.Place;
55+
import com.google.android.libraries.places.api.model.PlaceTypes;
5556
import com.google.android.libraries.places.api.net.PlacesClient;
5657
import com.google.android.libraries.places.widget.Autocomplete;
5758
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;

demo-kotlin/app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919
alias(libs.plugins.jetbrains.kotlin.android)
2020
alias(libs.plugins.secrets.gradle.plugin)
2121
alias(libs.plugins.jetbrains.kotlin.parcelize)
22+
kotlin("kapt")
2223
}
2324

2425
android {
@@ -54,6 +55,7 @@ dependencies {
5455

5556
implementation(libs.volley)
5657
implementation(libs.glide)
58+
kapt(libs.glide.compiler)
5759
implementation(libs.viewbinding)
5860
implementation(libs.multidex)
5961

demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class AutocompleteAddressActivity : BaseActivity(),
8686
// The user canceled the operation.
8787
Log.i(TAG, "User canceled autocomplete")
8888
}
89-
} as ActivityResultCallback<ActivityResult>)
89+
})
9090
// [END maps_solutions_android_autocomplete_define]
9191

9292
// [START maps_solutions_android_autocomplete_intent]

demo-kotlin/app/src/main/java/com/example/placesdemo/CurrentPlaceActivity.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import androidx.activity.result.contract.ActivityResultContracts
2525
import androidx.annotation.RequiresPermission
2626
import androidx.core.content.ContextCompat
2727
import com.example.placesdemo.databinding.CurrentPlaceActivityBinding
28+
import com.google.android.gms.maps.model.LatLng
2829
import com.google.android.libraries.places.api.Places
30+
import com.google.android.libraries.places.api.model.CircularBounds
2931
import com.google.android.libraries.places.api.model.Place
30-
import com.google.android.libraries.places.api.net.FindCurrentPlaceRequest
31-
import com.google.android.libraries.places.api.net.FindCurrentPlaceResponse
3232
import com.google.android.libraries.places.api.net.PlacesClient
33+
import com.google.android.libraries.places.api.net.SearchNearbyRequest
34+
import com.google.android.libraries.places.api.net.SearchNearbyResponse
3335

3436
/**
3537
* Activity to demonstrate [PlacesClient.findCurrentPlace].
@@ -40,6 +42,9 @@ class CurrentPlaceActivity : BaseActivity() {
4042

4143
private lateinit var binding: CurrentPlaceActivityBinding
4244

45+
val boulderCenter = LatLng(40.01499, -105.27055)
46+
val radiusMeters = 5000.0
47+
4348
@SuppressLint("MissingPermission")
4449
val requestPermissionLauncher =
4550
registerForActivityResult(
@@ -145,9 +150,9 @@ class CurrentPlaceActivity : BaseActivity() {
145150
@RequiresPermission(allOf = [permission.ACCESS_FINE_LOCATION, permission.ACCESS_WIFI_STATE])
146151
private fun findCurrentPlaceWithPermissions() {
147152
setLoading(true)
148-
val currentPlaceRequest = FindCurrentPlaceRequest.newInstance(placeFields)
149-
val currentPlaceTask = placesClient.findCurrentPlace(currentPlaceRequest)
150-
currentPlaceTask.addOnSuccessListener { response: FindCurrentPlaceResponse? ->
153+
val currentPlaceRequest = SearchNearbyRequest.newInstance(CircularBounds.newInstance(boulderCenter, radiusMeters), placeFields)
154+
val currentPlaceTask = placesClient.searchNearby(currentPlaceRequest)
155+
currentPlaceTask.addOnSuccessListener { response: SearchNearbyResponse? ->
151156
response?.let {
152157
binding.response.text = StringUtil.stringify(it, isDisplayRawResultsChecked)
153158
}

demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import com.google.android.libraries.places.api.model.RectangularBounds
3737
import com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest
3838
import com.google.android.libraries.places.api.net.FindAutocompletePredictionsResponse
3939
import com.google.android.libraries.places.api.net.PlacesClient
40-
import com.google.android.libraries.places.widget.Autocomplete
41-
import com.google.android.libraries.places.widget.AutocompleteActivity
40+
import com.google.android.libraries.places.widget.PlaceAutocompleteActivity
4241
import com.google.android.libraries.places.widget.AutocompleteSupportFragment
42+
import com.google.android.libraries.places.widget.PlaceAutocomplete
4343
import com.google.android.libraries.places.widget.listener.PlaceSelectionListener
4444
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode
4545

@@ -140,14 +140,14 @@ class PlaceAutocompleteActivity : BaseActivity() {
140140
RESULT_OK -> {
141141
val data: Intent? = result.data
142142
if (data != null) {
143-
val place = Autocomplete.getPlaceFromIntent(data)
143+
val place = PlaceAutocomplete.getPredictionFromIntent(data)
144144
binding.response.text =
145-
StringUtil.stringifyAutocompleteWidget(place, isDisplayRawResultsChecked)
145+
StringUtil.stringifyAutocompletePrediction(place, isDisplayRawResultsChecked)
146146
}
147147
}
148-
AutocompleteActivity.RESULT_ERROR -> {
149-
val status = Autocomplete.getStatusFromIntent(intent)
150-
binding.response.text = status.statusMessage
148+
PlaceAutocompleteActivity.RESULT_ERROR -> {
149+
val status = PlaceAutocomplete.getResultStatusFromIntent(intent)
150+
binding.response.text = status?.statusMessage
151151
}
152152
RESULT_CANCELED -> {
153153
// The user canceled the operation.
@@ -156,9 +156,8 @@ class PlaceAutocompleteActivity : BaseActivity() {
156156
}
157157

158158
private fun startAutocompleteActivity() {
159-
val autocompleteIntent = Autocomplete.IntentBuilder(mode, placeFields)
159+
val autocompleteIntent = PlaceAutocomplete.IntentBuilder()
160160
.setInitialQuery(query)
161-
.setHint(hint)
162161
.setCountries(countries)
163162
.setLocationBias(locationBias)
164163
.setLocationRestriction(locationRestriction)
@@ -269,6 +268,7 @@ class PlaceAutocompleteActivity : BaseActivity() {
269268
else emptyList()
270269
}
271270

271+
// This Enum is deprecated, but there is no replacement. See https://developers.google.com/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/widget/model/AutocompleteActivityMode
272272
private val mode: AutocompleteActivityMode
273273
get() {
274274
val isOverlayMode =

demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceDetailsAndPhotosActivity.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.example.placesdemo
1717

18-
import android.graphics.Bitmap
1918
import android.os.Bundle
2019
import android.text.TextUtils
2120
import android.view.View
@@ -30,10 +29,10 @@ import com.example.placesdemo.databinding.PlaceDetailsAndPhotosActivityBinding
3029
import com.google.android.libraries.places.api.Places
3130
import com.google.android.libraries.places.api.model.PhotoMetadata
3231
import com.google.android.libraries.places.api.model.Place
33-
import com.google.android.libraries.places.api.net.FetchPhotoRequest
34-
import com.google.android.libraries.places.api.net.FetchPhotoResponse
3532
import com.google.android.libraries.places.api.net.FetchPlaceRequest
3633
import com.google.android.libraries.places.api.net.FetchPlaceResponse
34+
import com.google.android.libraries.places.api.net.FetchResolvedPhotoUriRequest
35+
import com.google.android.libraries.places.api.net.FetchResolvedPhotoUriResponse
3736
import com.google.android.libraries.places.api.net.PlacesClient
3837

3938
/**
@@ -167,7 +166,7 @@ class PlaceDetailsAndPhotosActivity : BaseActivity() {
167166
if (!TextUtils.isEmpty(customPhotoReference)) {
168167
localPhotoMetadata = PhotoMetadata.builder(customPhotoReference).build()
169168
}
170-
val photoRequestBuilder = FetchPhotoRequest.builder(localPhotoMetadata!!)
169+
val photoRequestBuilder = FetchResolvedPhotoUriRequest.builder(localPhotoMetadata!!)
171170
val maxWidth = readIntFromTextView(binding.photoMaxWidth)
172171
if (maxWidth != null) {
173172
photoRequestBuilder.maxWidth = maxWidth
@@ -176,11 +175,18 @@ class PlaceDetailsAndPhotosActivity : BaseActivity() {
176175
if (maxHeight != null) {
177176
photoRequestBuilder.maxHeight = maxHeight
178177
}
179-
val photoTask = placesClient.fetchPhoto(photoRequestBuilder.build())
180-
photoTask.addOnSuccessListener { response: FetchPhotoResponse ->
181-
val bitmap = response.bitmap
182-
binding.photo.setImageBitmap(bitmap)
183-
StringUtil.prepend(binding.photoMetadata, StringUtil.stringify(bitmap))
178+
val photoTask = placesClient.fetchResolvedPhotoUri(photoRequestBuilder.build())
179+
photoTask.addOnSuccessListener { response: FetchResolvedPhotoUriResponse ->
180+
val uri = response.uri
181+
if (uri != null) {
182+
Glide.with(binding.photo.context)
183+
.load(uri)
184+
.into(binding.photo)
185+
186+
StringUtil.prepend(binding.photoMetadata, StringUtil.stringify(uri))
187+
} else {
188+
StringUtil.prepend(binding.photoMetadata, "No photo available")
189+
}
184190
}
185191
photoTask.addOnFailureListener { exception: Exception ->
186192
exception.printStackTrace()
@@ -289,4 +295,4 @@ class PlaceDetailsAndPhotosActivity : BaseActivity() {
289295
companion object {
290296
private const val FETCHED_PHOTO_KEY = "photo_image"
291297
}
292-
}
298+
}

0 commit comments

Comments
 (0)