diff --git a/compat/app/build.gradle b/compat/app/build.gradle index 4c43e3fd..cdbb130b 100644 --- a/compat/app/build.gradle +++ b/compat/app/build.gradle @@ -26,5 +26,5 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.google.android.libraries.places:places-compat:2.1.0' + implementation 'com.google.android.libraries.places:places-compat:2.2.0' } diff --git a/demo/app/build.gradle b/demo/app/build.gradle index 3b5d25ce..832433dc 100644 --- a/demo/app/build.gradle +++ b/demo/app/build.gradle @@ -24,5 +24,5 @@ android { dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.libraries.places:places:2.1.0' + implementation 'com.google.android.libraries.places:places:2.2.0' } diff --git a/demo/app/src/main/java/com/example/placesdemo/AutocompleteTestActivity.java b/demo/app/src/main/java/com/example/placesdemo/AutocompleteTestActivity.java index cb853a2f..ba834b9b 100644 --- a/demo/app/src/main/java/com/example/placesdemo/AutocompleteTestActivity.java +++ b/demo/app/src/main/java/com/example/placesdemo/AutocompleteTestActivity.java @@ -17,6 +17,7 @@ package com.example.placesdemo; import com.google.android.gms.common.api.Status; +import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.tasks.Task; import com.google.android.libraries.places.api.Places; @@ -44,6 +45,7 @@ import android.widget.Spinner; import android.widget.TextView; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -129,7 +131,7 @@ private void setupAutocompleteSupportFragment() { .setPlaceFields(getPlaceFields()) .setText(getQuery()) .setHint(getHint()) - .setCountry(getCountry()) + .setCountries(getCountries()) .setLocationBias(getLocationBias()) .setLocationRestriction(getLocationRestriction()) .setTypeFilter(getTypeFilter()) @@ -181,7 +183,7 @@ private void startAutocompleteActivity() { new Autocomplete.IntentBuilder(getMode(), getPlaceFields()) .setInitialQuery(getQuery()) .setHint(getHint()) - .setCountry(getCountry()) + .setCountries(getCountries()) .setLocationBias(getLocationBias()) .setLocationRestriction(getLocationRestriction()) .setTypeFilter(getTypeFilter()) @@ -195,7 +197,8 @@ private void findAutocompletePredictions() { FindAutocompletePredictionsRequest.Builder requestBuilder = FindAutocompletePredictionsRequest.builder() .setQuery(getQuery()) - .setCountry(getCountry()) + .setCountries(getCountries()) + .setOrigin((getOrigin())) .setLocationBias(getLocationBias()) .setLocationRestriction(getLocationRestriction()) .setTypeFilter(getTypeFilter()); @@ -242,9 +245,14 @@ private String getHint() { return getTextViewValue(R.id.autocomplete_hint); } - @Nullable - private String getCountry() { - return getTextViewValue(R.id.autocomplete_country); + @NonNull + private List getCountries() { + String countryString = getTextViewValue(R.id.autocomplete_country); + if (TextUtils.isEmpty(countryString)) { + return new ArrayList<>(); + } + + return StringUtil.countriesStringToArrayList(countryString); } @Nullable @@ -283,6 +291,23 @@ private RectangularBounds getBounds(int resIdSouthWest, int resIdNorthEast) { return RectangularBounds.newInstance(bounds); } + @Nullable + private LatLng getOrigin() { + String originStr = + ((TextView) findViewById(R.id.autocomplete_location_origin)).getText().toString(); + if (TextUtils.isEmpty(originStr)) { + return null; + } + + LatLng origin = StringUtil.convertToLatLng(originStr); + if (origin == null) { + showErrorAlert(R.string.error_alert_message_invalid_origin); + return null; + } + + return origin; + } + @Nullable private TypeFilter getTypeFilter() { Spinner typeFilter = findViewById(R.id.autocomplete_type_filter); diff --git a/demo/app/src/main/java/com/example/placesdemo/StringUtil.java b/demo/app/src/main/java/com/example/placesdemo/StringUtil.java index 7bf55197..df2c0451 100644 --- a/demo/app/src/main/java/com/example/placesdemo/StringUtil.java +++ b/demo/app/src/main/java/com/example/placesdemo/StringUtil.java @@ -31,6 +31,8 @@ import androidx.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -75,6 +77,15 @@ static LatLng convertToLatLng(@Nullable String value) { } } + static List countriesStringToArrayList(String countriesString) { + // Allow these delimiters: , ; | / \ + List countries = Arrays.asList(countriesString + .replaceAll("\\s", "|") + .split("[,;|/\\\\]",-1)); + + return countries; + } + static String stringify(FindAutocompletePredictionsResponse response, boolean raw) { StringBuilder builder = new StringBuilder(); @@ -83,7 +94,9 @@ static String stringify(FindAutocompletePredictionsResponse response, boolean ra .append(" Autocomplete Predictions Results:"); if (raw) { - appendListToStringBuilder(builder, response.getAutocompletePredictions()); } else { + builder.append(RESULT_SEPARATOR); + appendListToStringBuilder(builder, response.getAutocompletePredictions()); + } else { for (AutocompletePrediction autocompletePrediction : response.getAutocompletePredictions()) { builder .append(RESULT_SEPARATOR) diff --git a/demo/app/src/main/res/layout/autocomplete_test_activity.xml b/demo/app/src/main/res/layout/autocomplete_test_activity.xml index bd26b475..1c03694d 100644 --- a/demo/app/src/main/res/layout/autocomplete_test_activity.xml +++ b/demo/app/src/main/res/layout/autocomplete_test_activity.xml @@ -14,6 +14,20 @@ android:orientation="vertical"> + + + + Uh-Oh! + + Unable to parse Location Origin. Expected format: "33, 128" Unable to parse Location Bias or Location Restriction. Expected format: "33, 128" @@ -38,18 +40,24 @@ Hint - - Country + + Countries (e.g CH, US, RO) Type Filter + + Location Origin (format: -33.2, 128.2) + Location Bias (format: -33.2, 128.2) Location Restriction (format: -33.2, 128.2) + + Origin (lat, lng) + South West (lat, lng)