Skip to content

Commit 14bc347

Browse files
dkhawkkikoso
andauthored
feat: Overhaul snippets app into a multi-activity demo (#955)
* 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: Upgrade Places SDK to 5.0.0 This commit upgrades the Places SDK for Android from version 4.4.1 to 5.0.0. Key changes include: - Updating all build.gradle.kts and libs.versions.toml files to use the new SDK version. - Migrating from deprecated Place fields. - Adopting centralized SDK versioning in libs.versions.toml for better consistency across modules. * fix: fixed checksum * fix: minSdk * chore: modified .gitignore (#961) * feat: replace enums * chore: removed dependabot flow (#962) * 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: Upgrade Places SDK to 5.0.0 This commit upgrades the Places SDK for Android from version 4.4.1 to 5.0.0. Key changes include: - Updating all build.gradle.kts and libs.versions.toml files to use the new SDK version. - Migrating from deprecated Place fields. - Adopting centralized SDK versioning in libs.versions.toml for better consistency across modules. * fix: fixed checksum * fix: minSdk * feat: replace enums * docs: Correct snippet region tags for autocomplete intent * docs: Correct snippet tags in PlaceAutocompleteActivity * docs: Fixes some missing region tags Moved the "maps_places_place_details_simple" tag into executed code to ensure it works as expected. Key changes: - **Place Details**: - The `PlaceDetailsActivity` (both Java and Kotlin) now requests the `Place.Field.LOCATION` field. - The fetched `LatLng` coordinates are now displayed in the UI, providing a more complete example of the data available. - **Place Autocomplete**: - The `PlaceAutocompleteActivity` (both Java and Kotlin) now requests and displays the `FORMATTED_ADDRESS` of the selected place. - The autocomplete intent example now filters for the `ESTABLISHMENT` type instead of `ADDRESS`. - **Current Place**: - The code in `CurrentPlaceActivity` (both Java and Kotlin) has been wrapped in `maps_places_current_place` snippet tags and annotated with comments to improve its utility as a documentation example. --------- Co-authored-by: Enrique López-Mañas <eenriquelopez@gmail.com>
1 parent 7464ebe commit 14bc347

File tree

55 files changed

+2087
-589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2087
-589
lines changed

PlaceDetailsUIKit/gradle/libs.versions.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
# https://docs.gradle.org/current/userguide/version_catalog_basics.html
55

66
[versions]
7+
# --- Android SDK Versions ---
8+
# These versions define the API levels for compiling, targeting, and running the app.
9+
# By centralizing them here, we ensure all modules in the project are aligned.
10+
compileSdk = "36"
11+
minSdk = "27"
12+
targetSdk = "36"
13+
714
# --- Core Android & Kotlin ---
815
# These are the fundamental versions for building the Android app.
916
agp = "8.13.0"

demo-java/app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ plugins {
2121

2222
android {
2323
namespace = "com.example.placesdemo"
24-
compileSdk = 36
24+
compileSdk = libs.versions.sdk.compile.get().toInt()
2525

2626
defaultConfig {
2727
applicationId = "com.example.placesdemo"
28-
minSdk = 23
29-
targetSdk = 36
28+
minSdk = libs.versions.sdk.min.get().toInt()
29+
targetSdk = libs.versions.sdk.target.get().toInt()
3030
versionCode = 1
3131
versionName = "1.0"
3232

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@
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.TypeFilter;
5655
import com.google.android.libraries.places.api.net.PlacesClient;
5756
import com.google.android.libraries.places.widget.Autocomplete;
5857
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;
5958

60-
import java.util.ArrayList;
6159
import java.util.Arrays;
6260
import java.util.List;
6361

@@ -154,14 +152,12 @@ private void startAutocompleteIntent() {
154152
// Set the fields to specify which types of place data to
155153
// return after the user has made a selection.
156154
List<Place.Field> fields = Arrays.asList(Place.Field.ADDRESS_COMPONENTS,
157-
Place.Field.LAT_LNG, Place.Field.VIEWPORT);
155+
Place.Field.LOCATION, Place.Field.VIEWPORT);
158156

159157
// Build the autocomplete intent with field, country, and type filters applied
160158
Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields)
161-
.setCountries(Arrays.asList("US"))
162-
.setTypesFilter(new ArrayList<String>() {{
163-
add(TypeFilter.ADDRESS.toString().toLowerCase());
164-
}})
159+
.setCountries(List.of("US"))
160+
.setTypesFilter(List.of("establishment"))
165161
.build(this);
166162
startAutocomplete.launch(intent);
167163
}
@@ -251,7 +247,7 @@ private void fillInAddress(Place place) {
251247

252248
// [START maps_solutions_android_autocomplete_map_add]
253249
private void showMap(Place place) {
254-
coordinates = place.getLatLng();
250+
coordinates = place.getLocation();
255251

256252
// It isn't possible to set a fragment's id programmatically so we set a tag instead and
257253
// search for it using that.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
110110
Field.EDITORIAL_SUMMARY,
111111
Field.INTERNATIONAL_PHONE_NUMBER,
112112
Field.OPENING_HOURS,
113-
Field.PHONE_NUMBER,
114113
Field.RESERVABLE,
115114
Field.SECONDARY_OPENING_HOURS,
116115
Field.SERVES_BEER,
@@ -122,8 +121,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
122121
Field.SERVES_WINE,
123122
Field.TAKEOUT,
124123
Field.UTC_OFFSET,
125-
Field.WEBSITE_URI,
126-
Field.WHEELCHAIR_ACCESSIBLE_ENTRANCE
124+
Field.WEBSITE_URI
127125
);
128126
fieldSelector = new FieldSelector(
129127
binding.useCustomFields,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import android.content.Context;
3333
import android.graphics.Bitmap;
34+
import android.graphics.Color;
3435
import android.os.Bundle;
3536
import android.text.TextUtils;
3637
import android.view.View;
@@ -159,8 +160,9 @@ private void attemptFetchPhoto(Place place) {
159160

160161
private void attemptFetchIcon(Place place) {
161162
binding.icon.setImageBitmap(null);
162-
binding.icon.setBackgroundColor(place.getIconBackgroundColor());
163-
String url = place.getIconUrl();
163+
Integer bc = place.getIconBackgroundColor();
164+
binding.icon.setBackgroundColor(bc == null ? Color.TRANSPARENT : bc);
165+
String url = place.getIconMaskUrl();
164166
Glide.with(this).load(url).into(binding.icon);
165167
}
166168

@@ -234,7 +236,7 @@ private boolean validateInputs(boolean isFetchPhotoChecked, boolean isFetchIconC
234236
"Using 'Custom photo reference', but 'Also fetch photo?' is not selected.");
235237
return false;
236238
}
237-
if (isFetchIconChecked && !placeFields.contains(Field.ICON_URL)) {
239+
if (isFetchIconChecked && !placeFields.contains(Field.ICON_MASK_URL)) {
238240
binding.response.setText(R.string.fetch_icon_missing_fields_warning);
239241
return false;
240242
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ private List<Field> getPlaceFields() {
230230
return fieldSelector.getSelectedFields();
231231
} else {
232232
return new ArrayList<>(Arrays.asList(
233-
Field.ADDRESS,
233+
Field.FORMATTED_ADDRESS,
234234
Field.BUSINESS_STATUS,
235235
Field.CURRENT_OPENING_HOURS,
236236
Field.ID,
237-
Field.NAME,
237+
Field.DISPLAY_NAME,
238238
Field.OPENING_HOURS,
239239
Field.UTC_OFFSET
240240
));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ static String stringify(FindCurrentPlaceResponse response, boolean raw) {
142142
}
143143

144144
static String stringify(Place place) {
145-
return place.getName()
145+
return place.getDisplayName()
146146
+ " ("
147-
+ place.getAddress()
147+
+ place.getFormattedAddress()
148148
+ ")";
149149
}
150150

demo-java/gradle/libs.versions.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
[versions]
2-
activity = "1.10.1"
2+
sdk-compile = "36"
3+
sdk-min = "24"
4+
sdk-target = "36"
5+
6+
activity = "1.11.0"
37
androidGradlePlugin = "8.13.0"
4-
androidMapsUtils = "3.16.0"
8+
androidMapsUtils = "3.19.0"
59
appcompat = "1.7.1"
610
constraintlayout = "2.2.1"
711
fragment = "1.8.9"
8-
glide = "5.0.4"
12+
glide = "5.0.5"
913
mapsSecretsGradlePlugin = "2.0.1"
1014
material = "1.13.0"
1115
multidex = "2.0.1"
12-
navigationFragment = "2.9.3"
13-
places = "4.4.1"
16+
navigationFragment = "2.9.5"
17+
places = "5.0.0"
1418
playServicesMaps = "19.2.0"
1519
viewbinding = "8.13.0"
1620
volley = "1.2.1"

demo-kotlin/app/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727

2828
defaultConfig {
2929
applicationId = "com.example.placesdemo"
30-
minSdk = 23
30+
minSdk = 24
3131
targetSdk = 36
3232
versionCode = 1
3333
versionName = "1.0"
@@ -43,6 +43,7 @@ android {
4343

4444
buildFeatures {
4545
viewBinding = true
46+
buildConfig = true
4647
}
4748
}
4849

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class AutocompleteAddressActivity : BaseActivity(),
9595
// return after the user has made a selection.
9696
val fields = listOf(
9797
Place.Field.ADDRESS_COMPONENTS,
98-
Place.Field.LAT_LNG, Place.Field.VIEWPORT
98+
Place.Field.LOCATION, Place.Field.VIEWPORT
9999
)
100100

101101
// Build the autocomplete intent with field, country, and type filters applied
@@ -227,7 +227,7 @@ class AutocompleteAddressActivity : BaseActivity(),
227227

228228
// [START maps_solutions_android_autocomplete_map_add]
229229
private fun showMap(place: Place) {
230-
coordinates = place.latLng as LatLng
230+
coordinates = place.location as LatLng
231231

232232
// It isn't possible to set a fragment's id programmatically so we set a tag instead and
233233
// search for it using that.

0 commit comments

Comments
 (0)