Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update Places SDK for Android to 4.1.0 #795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions demo-java/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]
activity = "1.9.3"
androidGradlePlugin = "8.6.1"
androidMapsUtils = "3.8.2"
androidGradlePlugin = "8.7.3"
androidMapsUtils = "3.9.0"
appcompat = "1.7.0"
constraintlayout = "2.2.0"
fragment = "1.8.5"
glide = "4.16.0"
mapsSecretsGradlePlugin = "2.0.1"
material = "1.12.0"
multidex = "2.0.1"
navigationFragment = "2.8.3"
places = "4.0.0"
navigationFragment = "2.8.5"
places = "4.1.0"
playServicesMaps = "19.0.0"
viewbinding = "8.7.2"
viewbinding = "8.7.3"
volley = "1.2.1"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion demo-java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 28 15:43:44 PDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import com.google.android.libraries.places.api.model.PlaceTypes
import com.google.android.libraries.places.widget.Autocomplete
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode
import com.google.maps.android.SphericalUtil.computeDistanceBetween
import java.util.*

/**
* Activity for using Place Autocomplete to assist filling out an address form.
Expand Down Expand Up @@ -95,7 +94,7 @@ class AutocompleteAddressActivity : AppCompatActivity(R.layout.autocomplete_addr
// return after the user has made a selection.
val fields = listOf(
Place.Field.ADDRESS_COMPONENTS,
Place.Field.LAT_LNG, Place.Field.VIEWPORT
Place.Field.LOCATION, Place.Field.VIEWPORT
)

// Build the autocomplete intent with field, country, and type filters applied
Expand Down Expand Up @@ -241,7 +240,7 @@ class AutocompleteAddressActivity : AppCompatActivity(R.layout.autocomplete_addr

// [START maps_solutions_android_autocomplete_map_add]
private fun showMap(place: Place) {
coordinates = place.latLng as LatLng
coordinates = place.location as LatLng

// It isn't possible to set a fragment's id programmatically so we set a tag instead and
// search for it using that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ import androidx.appcompat.app.AlertDialog
import com.google.android.libraries.places.api.model.Place
import java.util.*

/** Helper class for selecting [Field] values. */
/** Helper class for selecting [Place.Field] values. */
class FieldSelector(
enableView: CheckBox,
outputView: TextView,
savedState: Bundle?,
validFields: List<Place.Field> = listOf(*Place.Field.values())
validFields: List<Place.Field> = Place.Field.entries
) {

private val fieldStates: MutableMap<Place.Field, State>
private val fieldStates: MutableMap<Place.Field, State> = EnumMap(Place.Field::class.java)
private val outputView: TextView

/**
* Shows dialog to allow user to select [Field] values they want.
* Shows dialog to allow user to select [Place.Field] values they want.
*/
fun showDialog(context: Context?) {
private fun showDialog(context: Context?) {
val listView = ListView(context)
val adapter = PlaceFieldArrayAdapter(context, fieldStates.values.toList())
listView.adapter = adapter
Expand All @@ -59,13 +59,13 @@ class FieldSelector(
}

/**
* Returns all [Field] that are selectable.
* Returns all [Place.Field] that are selectable.
*/
val allFields: List<Place.Field>
get() = ArrayList(fieldStates.keys)

/**
* Returns all [Field] values the user selected.
* Returns all [Place.Field] values the user selected.
*/
val selectedFields: List<Place.Field>
get() {
Expand All @@ -79,9 +79,9 @@ class FieldSelector(
}

/**
* Returns a String representation of all selected [Field] values. See [ ][.getSelectedFields].
* Returns a String representation of all selected [Place.Field] values. See [ ][.getSelectedFields].
*/
val selectedString: String
private val selectedString: String
get() {
val builder = StringBuilder()
for (eachField in selectedFields) {
Expand All @@ -101,7 +101,7 @@ class FieldSelector(

private fun restoreState(selectedFields: List<Int>) {
for (serializedField in selectedFields) {
val field = Place.Field.values()[serializedField]
val field = Place.Field.entries[serializedField]
val state = fieldStates[field]
if (state != null) {
state.checked = true
Expand Down Expand Up @@ -153,22 +153,21 @@ class FieldSelector(
private const val SELECTED_PLACE_FIELDS_KEY = "selected_place_fields"

/**
* Returns all [Field] values except those passed in.
* Returns all [Place.Field] values except those passed in.
*
*
* Convenience method for when most [Field] values are desired. Useful for APIs that do
* no support all [Field] values.
* Convenience method for when most [Place.Field] values are desired. Useful for APIs that do
* no support all [Place.Field] values.
*/
fun allExcept(vararg placeFieldsToOmit: Place.Field): List<Place.Field> {
// Arrays.asList is immutable, create a mutable list to allow removing fields
val placeFields: MutableList<Place.Field> = ArrayList(Arrays.asList(*Place.Field.values()))
placeFields.removeAll(placeFieldsToOmit)
val placeFields: MutableList<Place.Field> = ArrayList(listOf(*Place.Field.entries.toTypedArray()))
placeFields.removeAll(placeFieldsToOmit.toSet())
return placeFields
}
}

init {
fieldStates = HashMap()
for (field in validFields) {
fieldStates[field] = State(field)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class PlaceAutocompleteActivity : AppCompatActivity() {
setLoading(false)
}

override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
fieldSelector.onSaveInstanceState(bundle)
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
fieldSelector.onSaveInstanceState(outState)
}

private fun setupAutocompleteSupportFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class PlaceDetailsAndPhotosActivity : AppCompatActivity() {
}
}

override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
fieldSelector.onSaveInstanceState(bundle)
bundle.putParcelable(FETCHED_PHOTO_KEY, photo)
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
fieldSelector.onSaveInstanceState(outState)
outState.putParcelable(FETCHED_PHOTO_KEY, photo)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class PlaceIsOpenActivity : AppCompatActivity() {
updateIsOpenTime()
}

override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
fieldSelector.onSaveInstanceState(bundle)
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
fieldSelector.onSaveInstanceState(outState)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ import org.json.JSONArray
import org.json.JSONException

/**
* An Activity that demonstrates programmatic as-you-type place predictions. The parameters of the
* request are currently hard coded in this Activity, to modify these parameters (e.g. location
* bias, place types, etc.), see [ProgrammaticAutocompleteGeocodingActivity.getPlacePredictions]
* An Activity that demonstrates programmatic as-you-type place predictions.
* The parameters of the request are currently hard coded in this Activity.
* To modify these parameters (e.g. location bias, place types, etc.),
* see [ProgrammaticAutocompleteGeocodingActivity.getPlacePredictions].
*
* @see https://developers.google.com/places/android-sdk/autocomplete#get_place_predictions_programmatically
* @see <a href="https://developers.google.com/places/android-sdk/autocomplete#get_place_predictions_programmatically">Get Place Predictions Programmatically</a>
*/
class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() {

Expand Down Expand Up @@ -181,9 +182,9 @@ class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() {

/**
* Performs a Geocoding API request and displays the result in a dialog.
* Be sure to enable Geocoding API in your project and API key restrictions.
* Be sure to enable the Geocoding API in your project and set API key restrictions.
*
* @see https://developers.google.com/places/android-sdk/autocomplete#get_place_predictions_programmatically
* @see <a href="https://developers.google.com/maps/documentation/geocoding/overview">Geocoding API</a>
*/
private fun geocodePlaceAndDisplay(placePrediction: AutocompletePrediction) {
// Construct the request URL
Expand Down Expand Up @@ -231,7 +232,7 @@ class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() {
/**
* Performs a Place Details request and displays the result in a dialog.
*
* @see https://developers.google.com/maps/documentation/places/android-sdk/place-details#maps_places_get_place_by_id-kotlin
* @see <a href="https://developers.google.com/maps/documentation/places/android-sdk/place-details">Place Details</a>
*/
private fun fetchPlaceAndDisplay(placePrediction: AutocompletePrediction) {
// Specify the fields to return.
Expand All @@ -256,7 +257,6 @@ class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() {
}
}


companion object {
private val TAG = ProgrammaticAutocompleteGeocodingActivity::class.java.simpleName
}
Expand Down
8 changes: 4 additions & 4 deletions demo-kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
androidGradlePlugin = "8.6.1"
androidGradlePlugin = "8.7.3"
appcompat = "1.7.0"
coreKtx = "1.15.0"
glide = "4.16.0"
kotlin = "2.0.20"
kotlin = "2.0.21"
mapsSecretsGradlePlugin = "2.0.1"
mapsUtilsKtx = "5.1.1"
material = "1.12.0"
multidex = "2.0.1"
places = "4.0.0"
viewbinding = "8.7.2"
places = "4.1.0"
viewbinding = "8.7.3"
volley = "1.2.1"
kotlinParcelize = "1.9.24"

Expand Down
2 changes: 1 addition & 1 deletion demo-kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 28 15:44:27 PDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
4 changes: 2 additions & 2 deletions demo-kotlin/local.defaults.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PLACES_API_KEY="YOUR_API_KEY"
MAPS_API_KEY="YOUR_API_KEY"
PLACES_API_KEY=YOUR_API_KEY
MAPS_API_KEY=YOUR_API_KEY
35 changes: 22 additions & 13 deletions snippets/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'

android {
compileSdk 34
namespace 'com.google.places'
compileSdk 35

defaultConfig {
applicationId "com.google.places"
minSdk 21
targetSdk 34
minSdk 23
targetSdk 35
versionCode 1
versionName "1.0"

Expand All @@ -23,13 +25,14 @@ android {

buildFeatures {
viewBinding = true
buildConfig = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
namespace 'com.google.places'
}

// [START maps_android_places_install_snippet]
Expand All @@ -39,17 +42,23 @@ dependencies {
// [START_EXCLUDE silent]
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'com.android.volley:volley:1.2.1'
implementation "com.github.bumptech.glide:glide:4.16.0"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
// [END_EXCLUDE]
// [START maps_android_places_upgrade_snippet]
implementation 'com.google.android.libraries.places:places:3.3.0'
implementation 'com.google.android.libraries.places:places:4.1.0'
// [END maps_android_places_upgrade_snippet]
}
// [END maps_android_places_install_snippet]

// Secrets for Google Maps API Keys
secrets {
defaultPropertiesFileName = "local.defaults.properties"
propertiesFileName = "secrets.properties"
}
4 changes: 3 additions & 1 deletion snippets/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep class com.google.places.CurrentPlaceActivity { *; }
10 changes: 5 additions & 5 deletions snippets/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +17,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
Expand All @@ -27,8 +26,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".kotlin.GetStartedActivity"
android:exported="true">
<activity
android:name=".kotlin.GetStartedActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Loading
Loading