Skip to content

Commit 6a03383

Browse files
author
Cameron Mace
authored
Several geocoding fixes and additions (#512)
* several geocoding fixes and additions * removed log output * finished making review fixes * removed unused import
1 parent b7b192f commit 6a03383

21 files changed

Lines changed: 939 additions & 652 deletions

File tree

mapbox/app/src/main/java/com/mapbox/services/android/testapp/geocoding/GeocodingWidgetActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import com.mapbox.mapboxsdk.maps.MapView;
1414
import com.mapbox.mapboxsdk.maps.MapboxMap;
1515
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
16+
import com.mapbox.services.android.location.LostLocationEngine;
1617
import com.mapbox.services.android.telemetry.location.LocationEngine;
1718
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
1819
import com.mapbox.services.android.testapp.R;
1920
import com.mapbox.services.android.testapp.Utils;
20-
import com.mapbox.services.android.location.LostLocationEngine;
2121
import com.mapbox.services.android.ui.geocoder.GeocoderAutoCompleteView;
2222
import com.mapbox.services.api.geocoding.v5.GeocodingCriteria;
2323
import com.mapbox.services.api.geocoding.v5.models.CarmenFeature;
@@ -148,5 +148,4 @@ public void onLowMemory() {
148148
super.onLowMemory();
149149
mapView.onLowMemory();
150150
}
151-
152151
}

mapbox/libandroid-ui/src/main/java/com/mapbox/services/android/ui/geocoder/GeocoderAdapter.java

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @since 1.0.0
2929
*/
30-
public class GeocoderAdapter extends BaseAdapter implements Filterable {
30+
class GeocoderAdapter extends BaseAdapter implements Filterable {
3131

3232
private final Context context;
3333
private String baseUrl;
@@ -39,14 +39,14 @@ public class GeocoderAdapter extends BaseAdapter implements Filterable {
3939
private double[] bbox;
4040
private Position position;
4141
private int limit;
42-
private String language;
43-
private Call call;
42+
private String[] languages;
43+
private Call<GeocodingResponse> call;
4444

4545
private GeocoderFilter geocoderFilter;
4646

4747
private List<CarmenFeature> features;
4848

49-
public GeocoderAdapter(Context context) {
49+
GeocoderAdapter(Context context) {
5050
this.context = context;
5151
}
5252

@@ -60,7 +60,7 @@ public GeocoderAdapter(Context context) {
6060
* @return the base url used as endpoint.
6161
* @since 2.0.0
6262
*/
63-
public String getBaseUrl() {
63+
private String getBaseUrl() {
6464
return baseUrl;
6565
}
6666

@@ -70,7 +70,7 @@ public String getBaseUrl() {
7070
* @param baseUrl base url used as end point
7171
* @since 2.0.0
7272
*/
73-
public void setBaseUrl(String baseUrl) {
73+
void setBaseUrl(String baseUrl) {
7474
this.baseUrl = baseUrl;
7575
}
7676

@@ -81,7 +81,7 @@ public void setBaseUrl(String baseUrl) {
8181
* @see <a href="https://www.mapbox.com/help/define-access-token/">Mapbox access token</a>
8282
* @since 1.0.0
8383
*/
84-
public String getAccessToken() {
84+
private String getAccessToken() {
8585
return accessToken;
8686
}
8787

@@ -104,7 +104,7 @@ public void setAccessToken(String accessToken) {
104104
* country code
105105
* @since 1.3.0
106106
*/
107-
public String getCountry() {
107+
private String getCountry() {
108108
return country;
109109
}
110110

@@ -115,7 +115,7 @@ public String getCountry() {
115115
* @param country String matching country code.
116116
* @since 1.3.0
117117
*/
118-
public void setCountry(String country) {
118+
void setCountry(String country) {
119119
this.country = country;
120120
}
121121

@@ -126,7 +126,7 @@ public void setCountry(String country) {
126126
* country code inside a String array.
127127
* @since 2.0.0
128128
*/
129-
public String[] getCountries() {
129+
private String[] getCountries() {
130130
return countries;
131131
}
132132

@@ -138,7 +138,7 @@ public String[] getCountries() {
138138
* @param countries String array containing the country codes you want to limit results to.
139139
* @since 2.0.0
140140
*/
141-
public void setCountries(String[] countries) {
141+
void setCountries(String[] countries) {
142142
this.countries = countries;
143143
}
144144

@@ -160,7 +160,7 @@ public String getType() {
160160
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
161161
* @since 2.0.0
162162
*/
163-
public String[] getTypes() {
163+
private String[] getTypes() {
164164
return types;
165165
}
166166

@@ -184,7 +184,7 @@ public void setType(String type) {
184184
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
185185
* @since 2.0.0
186186
*/
187-
public void setTypes(String[] types) {
187+
void setTypes(String[] types) {
188188
this.types = types;
189189
}
190190

@@ -194,22 +194,10 @@ public void setTypes(String[] types) {
194194
* @return double array containing minX, minY, maxX, maxY
195195
* @since 1.3.0
196196
*/
197-
public double[] getBbox() {
197+
private double[] getBbox() {
198198
return bbox;
199199
}
200200

201-
/**
202-
* Bounding box within which to limit results.
203-
*
204-
* @param northeast The top right hand corner of your bounding box when the map is pointed north.
205-
* @param southwest The bottom left hand corner of your bounding box when the map is pointed north.
206-
* @since 1.3.0
207-
*/
208-
public void setBbox(Position northeast, Position southwest) {
209-
setBbox(southwest.getLongitude(), southwest.getLatitude(),
210-
northeast.getLongitude(), northeast.getLatitude());
211-
}
212-
213201
/**
214202
* Bounding box within which to limit results.
215203
*
@@ -219,7 +207,7 @@ public void setBbox(Position northeast, Position southwest) {
219207
* @param maxY Right of bounding box when map is pointed north.
220208
* @since 1.3.0
221209
*/
222-
public void setBbox(double minX, double minY, double maxX, double maxY) {
210+
void setBbox(double minX, double minY, double maxX, double maxY) {
223211
if (bbox == null) {
224212
bbox = new double[4];
225213
}
@@ -236,7 +224,7 @@ public void setBbox(double minX, double minY, double maxX, double maxY) {
236224
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
237225
* @since 1.0.0
238226
*/
239-
public Position getProximity() {
227+
private Position getProximity() {
240228
return position;
241229
}
242230

@@ -247,7 +235,7 @@ public Position getProximity() {
247235
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
248236
* @since 1.0.0
249237
*/
250-
public void setProximity(Position position) {
238+
void setProximity(Position position) {
251239
this.position = position;
252240
}
253241

@@ -257,7 +245,7 @@ public void setProximity(Position position) {
257245
* @return integer value
258246
* @since 2.0.0
259247
*/
260-
public int getLimit() {
248+
private int getLimit() {
261249
return limit;
262250
}
263251

@@ -267,16 +255,16 @@ public int getLimit() {
267255
* @param limit the integer value representing the amount of results desired.
268256
* @since 2.0.0
269257
*/
270-
public void setLimit(int limit) {
258+
void setLimit(int limit) {
271259
this.limit = limit;
272260
}
273261

274262
/**
275263
* @return The locale in which results should be returned.
276264
* @since 2.0.0
277265
*/
278-
public String getLanguage() {
279-
return language;
266+
private String[] getLanguage() {
267+
return languages;
280268
}
281269

282270
/**
@@ -293,11 +281,11 @@ public String getLanguage() {
293281
* <p>
294282
* This option is experimental.
295283
*
296-
* @param language The locale in which results should be returned.
284+
* @param languages The locale in which results should be returned.
297285
* @since 2.0.0
298286
*/
299-
public void setLanguage(String language) {
300-
this.language = language;
287+
void setLanguage(String... languages) {
288+
this.languages = languages;
301289
}
302290

303291
/**
@@ -306,7 +294,7 @@ public void setLanguage(String language) {
306294
*
307295
* @since 2.0.0
308296
*/
309-
public void cancelApiCall() {
297+
void cancelApiCall() {
310298
if (call != null) {
311299
call.cancel();
312300
}
@@ -408,11 +396,11 @@ public Filter getFilter() {
408396

409397
private class GeocoderFilter extends Filter {
410398

411-
private final MapboxGeocoding.Builder builder;
399+
private final MapboxGeocoding.Builder<MapboxGeocoding.Builder> builder;
412400

413-
public GeocoderFilter() {
401+
GeocoderFilter() {
414402
super();
415-
builder = new MapboxGeocoding.Builder();
403+
builder = new MapboxGeocoding.Builder<>();
416404
}
417405

418406
@Override
@@ -459,7 +447,7 @@ protected FilterResults performFiltering(CharSequence constraint) {
459447
builder.setLimit(limit);
460448
}
461449
if (getLanguage() != null) {
462-
builder.setLanguage(language);
450+
builder.setLanguages(languages);
463451
}
464452

465453
call = builder.build().getCall();

mapbox/libandroid-ui/src/main/java/com/mapbox/services/android/ui/geocoder/GeocoderAutoCompleteView.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.view.MotionEvent;
99
import android.view.View;
1010
import android.widget.AdapterView;
11-
import android.widget.AutoCompleteTextView;
1211

1312
import com.mapbox.services.android.ui.R;
1413
import com.mapbox.services.api.geocoding.v5.models.CarmenFeature;
@@ -25,7 +24,7 @@
2524
* @see <a href="https://www.mapbox.com/android-sdk/examples/geocoding/">Mapbox example</a>
2625
* @since 1.0.0
2726
*/
28-
public class GeocoderAutoCompleteView extends AutoCompleteTextView {
27+
public class GeocoderAutoCompleteView extends android.support.v7.widget.AppCompatAutoCompleteTextView {
2928

3029
private static final int DEFAULT_NUMBER_OF_LINES = 1;
3130

@@ -44,6 +43,7 @@ public GeocoderAutoCompleteView(Context context, AttributeSet attrs) {
4443
// Get attributes from attrs.xml
4544
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.mas_geocoderWidget);
4645
imgClearButton = attributes.getDrawable(R.styleable.mas_geocoderWidget_mas_clearButtonDrawable);
46+
attributes.recycle();
4747

4848
// Set custom adapter
4949
adapter = new GeocoderAdapter(context);
@@ -233,11 +233,34 @@ public void setLimit(int limit) {
233233
*
234234
* @param language The locale in which results should be returned.
235235
* @since 2.0.0
236+
* @deprecated use {@link GeocoderAutoCompleteView#setLanguages(String...)} instead
236237
*/
238+
@Deprecated
237239
public void setLanguage(String language) {
238240
adapter.setLanguage(language);
239241
}
240242

243+
/**
244+
* The locale in which results should be returned.
245+
* <p>
246+
* This property affects the language of returned results; generally speaking,
247+
* it does not determine which results are found. If the Geocoding API does not
248+
* recognize the language code, it may fall back to another language or the default
249+
* language. Components other than the language code, such as the country and
250+
* script codes, are ignored.
251+
* <p>
252+
* By default, this property is set to `null`, causing results to be in the default
253+
* language.
254+
* <p>
255+
* This option is experimental.
256+
*
257+
* @param languages The locale in which results should be returned.
258+
* @since 2.0.0
259+
*/
260+
public void setLanguages(String... languages) {
261+
adapter.setLanguage(languages);
262+
}
263+
241264
/**
242265
* Sets the listener that will be notified when the user clicks an item in the drop down list.
243266
*

mapbox/libjava-services-rx/src/main/java/com/mapbox/services/api/rx/geocoding/v5/MapboxGeocodingRx.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Observable<GeocodingResponse> getObservable() {
6868
builder.getAutocomplete(),
6969
builder.getBbox(),
7070
builder.getLimit(),
71-
builder.getLanguage());
71+
builder.getLanguages());
7272

7373
// Done
7474
return observable;
@@ -95,7 +95,7 @@ public Observable<List<GeocodingResponse>> getBatchObservable() {
9595
builder.getAutocomplete(),
9696
builder.getBbox(),
9797
builder.getLimit(),
98-
builder.getLanguage());
98+
builder.getLanguages());
9999

100100
// Done
101101
return batchObservable;

mapbox/libjava-services-rx/src/test/java/com/mapbox/services/api/rx/geocoding/v5/MapboxGeocodingRxTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mapbox.services.api.ServicesException;
44
import com.mapbox.services.api.geocoding.v5.models.GeocodingResponse;
5+
import com.mapbox.services.api.rx.BaseTest;
56

67
import org.junit.After;
78
import org.junit.Before;
@@ -10,9 +11,6 @@
1011
import org.junit.rules.ExpectedException;
1112

1213
import java.io.IOException;
13-
import java.nio.charset.Charset;
14-
import java.nio.file.Files;
15-
import java.nio.file.Paths;
1614
import java.util.List;
1715

1816
import io.reactivex.observers.TestObserver;
@@ -29,11 +27,9 @@
2927
* Test Rx support on the Mapbox Geocoding API
3028
*/
3129

32-
public class MapboxGeocodingRxTest {
30+
public class MapboxGeocodingRxTest extends BaseTest {
3331

34-
private static final double DELTA = 1E-10;
35-
36-
private static final String GEOCODING_FIXTURE = "../libjava-services/src/test/fixtures/geocoding.json";
32+
private static final String GEOCODING_FIXTURE = "../libjava-services/src/test/fixtures/geocoding/geocoding.json";
3733
private static final String ACCESS_TOKEN = "pk.XXX";
3834

3935
private MockWebServer server;
@@ -48,7 +44,7 @@ public void setUp() throws IOException {
4844
@Override
4945
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
5046
try {
51-
String body = new String(Files.readAllBytes(Paths.get(GEOCODING_FIXTURE)), Charset.forName("utf-8"));
47+
String body = loadJsonFixture(GEOCODING_FIXTURE);
5248
return new MockResponse().setBody(body);
5349
} catch (IOException ioException) {
5450
throw new RuntimeException(ioException);

0 commit comments

Comments
 (0)