From b3a807dedcae2c2268d03c66880a8f806b59f349 Mon Sep 17 00:00:00 2001 From: dkhawk <107309+dkhawk@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:44:41 -0700 Subject: [PATCH] chore: Update Places SDK for Android to 4.1.0 This commit updates the Places SDK for Android to version 4.1.0 and updates the project to use the latest Android Gradle Plugin and Kotlin version. - Updated Places SDK for Android to 4.1.0 - Updated Android Gradle Plugin to 8.7.3 - Updated Kotlin to 2.0.21 - Updated Gradle wrapper to 8.11.1 - Updated various dependencies to their latest versions - Updated Java language version to 21 - Fixed deprecated Place.Field.LAT_LNG to Place.Field.LOCATION - Removed unnecessary imports and variables - Improved code readability and consistency - Updated documentation and comments --- demo-java/gradle/libs.versions.toml | 10 +++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../placesdemo/AutocompleteAddressActivity.kt | 5 ++- .../com/example/placesdemo/FieldSelector.kt | 31 ++++++++-------- .../placesdemo/PlaceAutocompleteActivity.kt | 6 ++-- .../PlaceDetailsAndPhotosActivity.kt | 8 ++--- .../example/placesdemo/PlaceIsOpenActivity.kt | 6 ++-- ...ogrammaticAutocompleteGeocodingActivity.kt | 16 ++++----- demo-kotlin/gradle/libs.versions.toml | 8 ++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- demo-kotlin/local.defaults.properties | 4 +-- snippets/app/build.gradle | 35 ++++++++++++------- snippets/app/proguard-rules.pro | 4 ++- snippets/app/src/main/AndroidManifest.xml | 10 +++--- .../google/places/CurrentPlaceActivity.java | 18 ++++++---- .../com/google/places/GetStartedActivity.java | 2 +- .../places/PlaceAutocompleteActivity.java | 27 ++++++-------- .../google/places/PlacePhotosActivity.java | 3 +- .../places/kotlin/PlaceDetailsActivity.kt | 10 +++--- snippets/build.gradle | 5 +-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- snippets/local.defaults.properties | 1 + 22 files changed, 112 insertions(+), 103 deletions(-) create mode 100644 snippets/local.defaults.properties diff --git a/demo-java/gradle/libs.versions.toml b/demo-java/gradle/libs.versions.toml index 2c2e4460..6da41fb7 100644 --- a/demo-java/gradle/libs.versions.toml +++ b/demo-java/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [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" @@ -9,10 +9,10 @@ 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] diff --git a/demo-java/gradle/wrapper/gradle-wrapper.properties b/demo-java/gradle/wrapper/gradle-wrapper.properties index b90f43be..9530def1 100644 --- a/demo-java/gradle/wrapper/gradle-wrapper.properties +++ b/demo-java/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt index 6380d3e5..4bb4637a 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/AutocompleteAddressActivity.kt @@ -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. @@ -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 @@ -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. diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/FieldSelector.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/FieldSelector.kt index 4e9f4240..2ff5f5b4 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/FieldSelector.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/FieldSelector.kt @@ -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 = listOf(*Place.Field.values()) + validFields: List = Place.Field.entries ) { - private val fieldStates: MutableMap + private val fieldStates: MutableMap = 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 @@ -59,13 +59,13 @@ class FieldSelector( } /** - * Returns all [Field] that are selectable. + * Returns all [Place.Field] that are selectable. */ val allFields: List get() = ArrayList(fieldStates.keys) /** - * Returns all [Field] values the user selected. + * Returns all [Place.Field] values the user selected. */ val selectedFields: List get() { @@ -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) { @@ -101,7 +101,7 @@ class FieldSelector( private fun restoreState(selectedFields: List) { 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 @@ -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 { // Arrays.asList is immutable, create a mutable list to allow removing fields - val placeFields: MutableList = ArrayList(Arrays.asList(*Place.Field.values())) - placeFields.removeAll(placeFieldsToOmit) + val placeFields: MutableList = ArrayList(listOf(*Place.Field.entries.toTypedArray())) + placeFields.removeAll(placeFieldsToOmit.toSet()) return placeFields } } init { - fieldStates = HashMap() for (field in validFields) { fieldStates[field] = State(field) } diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt index b12f823f..378514f4 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt @@ -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() { diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceDetailsAndPhotosActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceDetailsAndPhotosActivity.kt index 77e09044..076f3832 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceDetailsAndPhotosActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceDetailsAndPhotosActivity.kt @@ -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) } /** diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceIsOpenActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceIsOpenActivity.kt index 841786ca..a521e2f8 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceIsOpenActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceIsOpenActivity.kt @@ -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) } /** diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/ProgrammaticAutocompleteGeocodingActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/ProgrammaticAutocompleteGeocodingActivity.kt index 2cf20d09..adb01517 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/ProgrammaticAutocompleteGeocodingActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/ProgrammaticAutocompleteGeocodingActivity.kt @@ -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 Get Place Predictions Programmatically */ class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() { @@ -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 Geocoding API */ private fun geocodePlaceAndDisplay(placePrediction: AutocompletePrediction) { // Construct the request URL @@ -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 Place Details */ private fun fetchPlaceAndDisplay(placePrediction: AutocompletePrediction) { // Specify the fields to return. @@ -256,7 +257,6 @@ class ProgrammaticAutocompleteGeocodingActivity : AppCompatActivity() { } } - companion object { private val TAG = ProgrammaticAutocompleteGeocodingActivity::class.java.simpleName } diff --git a/demo-kotlin/gradle/libs.versions.toml b/demo-kotlin/gradle/libs.versions.toml index 109f0c71..fe629bbf 100644 --- a/demo-kotlin/gradle/libs.versions.toml +++ b/demo-kotlin/gradle/libs.versions.toml @@ -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" diff --git a/demo-kotlin/gradle/wrapper/gradle-wrapper.properties b/demo-kotlin/gradle/wrapper/gradle-wrapper.properties index 693635b8..8b9a1571 100644 --- a/demo-kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/demo-kotlin/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/demo-kotlin/local.defaults.properties b/demo-kotlin/local.defaults.properties index 94e62f95..3b350cc8 100644 --- a/demo-kotlin/local.defaults.properties +++ b/demo-kotlin/local.defaults.properties @@ -1,2 +1,2 @@ -PLACES_API_KEY="YOUR_API_KEY" -MAPS_API_KEY="YOUR_API_KEY" \ No newline at end of file +PLACES_API_KEY=YOUR_API_KEY +MAPS_API_KEY=YOUR_API_KEY \ No newline at end of file diff --git a/snippets/app/build.gradle b/snippets/app/build.gradle index 854e6f98..8171c547 100644 --- a/snippets/app/build.gradle +++ b/snippets/app/build.gradle @@ -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" @@ -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] @@ -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" +} diff --git a/snippets/app/proguard-rules.pro b/snippets/app/proguard-rules.pro index 481bb434..8fba2a13 100644 --- a/snippets/app/proguard-rules.pro +++ b/snippets/app/proguard-rules.pro @@ -18,4 +18,6 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile + +-keep class com.google.places.CurrentPlaceActivity { *; } \ No newline at end of file diff --git a/snippets/app/src/main/AndroidManifest.xml b/snippets/app/src/main/AndroidManifest.xml index a59dfd64..6e3ef8be 100644 --- a/snippets/app/src/main/AndroidManifest.xml +++ b/snippets/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - -