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

Several geocoding fixes and additions #512

Merged
merged 4 commits into from
Aug 1, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.location.LostLocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.android.testapp.R;
import com.mapbox.services.android.testapp.Utils;
import com.mapbox.services.android.location.LostLocationEngine;
import com.mapbox.services.android.ui.geocoder.GeocoderAutoCompleteView;
import com.mapbox.services.api.geocoding.v5.GeocodingCriteria;
import com.mapbox.services.api.geocoding.v5.models.CarmenFeature;
Expand Down Expand Up @@ -148,5 +148,4 @@ public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @since 1.0.0
*/
public class GeocoderAdapter extends BaseAdapter implements Filterable {
class GeocoderAdapter extends BaseAdapter implements Filterable {

private final Context context;
private String baseUrl;
Expand All @@ -39,14 +39,14 @@ public class GeocoderAdapter extends BaseAdapter implements Filterable {
private double[] bbox;
private Position position;
private int limit;
private String language;
private Call call;
private String[] languages;
private Call<GeocodingResponse> call;

private GeocoderFilter geocoderFilter;

private List<CarmenFeature> features;

public GeocoderAdapter(Context context) {
GeocoderAdapter(Context context) {
this.context = context;
}

Expand All @@ -60,7 +60,7 @@ public GeocoderAdapter(Context context) {
* @return the base url used as endpoint.
* @since 2.0.0
*/
public String getBaseUrl() {
private String getBaseUrl() {
return baseUrl;
}

Expand All @@ -70,7 +70,7 @@ public String getBaseUrl() {
* @param baseUrl base url used as end point
* @since 2.0.0
*/
public void setBaseUrl(String baseUrl) {
void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

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

Expand All @@ -104,7 +104,7 @@ public void setAccessToken(String accessToken) {
* country code
* @since 1.3.0
*/
public String getCountry() {
private String getCountry() {
return country;
}

Expand All @@ -115,7 +115,7 @@ public String getCountry() {
* @param country String matching country code.
* @since 1.3.0
*/
public void setCountry(String country) {
void setCountry(String country) {
this.country = country;
}

Expand All @@ -126,7 +126,7 @@ public void setCountry(String country) {
* country code inside a String array.
* @since 2.0.0
*/
public String[] getCountries() {
private String[] getCountries() {
return countries;
}

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

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

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

Expand All @@ -194,22 +194,10 @@ public void setTypes(String[] types) {
* @return double array containing minX, minY, maxX, maxY
* @since 1.3.0
*/
public double[] getBbox() {
private double[] getBbox() {
return bbox;
}

/**
* Bounding box within which to limit results.
*
* @param northeast The top right hand corner of your bounding box when the map is pointed north.
* @param southwest The bottom left hand corner of your bounding box when the map is pointed north.
* @since 1.3.0
*/
public void setBbox(Position northeast, Position southwest) {
setBbox(southwest.getLongitude(), southwest.getLatitude(),
northeast.getLongitude(), northeast.getLatitude());
}

/**
* Bounding box within which to limit results.
*
Expand All @@ -219,7 +207,7 @@ public void setBbox(Position northeast, Position southwest) {
* @param maxY Right of bounding box when map is pointed north.
* @since 1.3.0
*/
public void setBbox(double minX, double minY, double maxX, double maxY) {
void setBbox(double minX, double minY, double maxX, double maxY) {
if (bbox == null) {
bbox = new double[4];
}
Expand All @@ -236,7 +224,7 @@ public void setBbox(double minX, double minY, double maxX, double maxY) {
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
* @since 1.0.0
*/
public Position getProximity() {
private Position getProximity() {
return position;
}

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

Expand All @@ -257,7 +245,7 @@ public void setProximity(Position position) {
* @return integer value
* @since 2.0.0
*/
public int getLimit() {
private int getLimit() {
return limit;
}

Expand All @@ -267,16 +255,16 @@ public int getLimit() {
* @param limit the integer value representing the amount of results desired.
* @since 2.0.0
*/
public void setLimit(int limit) {
void setLimit(int limit) {
this.limit = limit;
}

/**
* @return The locale in which results should be returned.
* @since 2.0.0
*/
public String getLanguage() {
return language;
private String[] getLanguage() {
return languages;
}

/**
Expand All @@ -293,11 +281,11 @@ public String getLanguage() {
* <p>
* This option is experimental.
*
* @param language The locale in which results should be returned.
* @param languages The locale in which results should be returned.
* @since 2.0.0
*/
public void setLanguage(String language) {
this.language = language;
void setLanguage(String... languages) {
this.languages = languages;
}

/**
Expand All @@ -306,7 +294,7 @@ public void setLanguage(String language) {
*
* @since 2.0.0
*/
public void cancelApiCall() {
void cancelApiCall() {
if (call != null) {
call.cancel();
}
Expand Down Expand Up @@ -408,11 +396,11 @@ public Filter getFilter() {

private class GeocoderFilter extends Filter {

private final MapboxGeocoding.Builder builder;
private final MapboxGeocoding.Builder<MapboxGeocoding.Builder> builder;

public GeocoderFilter() {
GeocoderFilter() {
super();
builder = new MapboxGeocoding.Builder();
builder = new MapboxGeocoding.Builder<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary? It looks like a change on our standard builder approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was receiving a lint warning unchecked assignment so I added the <> which seemed to make it happy. Can switch back if there's an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's alright, I just wanted to make sure new MapboxGeocoding.Builder(); still was an option.

}

@Override
Expand Down Expand Up @@ -459,7 +447,7 @@ protected FilterResults performFiltering(CharSequence constraint) {
builder.setLimit(limit);
}
if (getLanguage() != null) {
builder.setLanguage(language);
builder.setLanguages(languages);
}

call = builder.build().getCall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;

import com.mapbox.services.android.ui.R;
import com.mapbox.services.api.geocoding.v5.models.CarmenFeature;
Expand All @@ -25,7 +24,7 @@
* @see <a href="https://www.mapbox.com/android-sdk/examples/geocoding/">Mapbox example</a>
* @since 1.0.0
*/
public class GeocoderAutoCompleteView extends AutoCompleteTextView {
public class GeocoderAutoCompleteView extends android.support.v7.widget.AppCompatAutoCompleteTextView {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, good find.


private static final int DEFAULT_NUMBER_OF_LINES = 1;

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

// Set custom adapter
adapter = new GeocoderAdapter(context);
Expand Down Expand Up @@ -233,11 +233,34 @@ public void setLimit(int limit) {
*
* @param language The locale in which results should be returned.
* @since 2.0.0
* @deprecated use {@link GeocoderAutoCompleteView#setLanguages(String...)} instead
*/
@Deprecated
public void setLanguage(String language) {
adapter.setLanguage(language);
}

/**
* The locale in which results should be returned.
* <p>
* This property affects the language of returned results; generally speaking,
* it does not determine which results are found. If the Geocoding API does not
* recognize the language code, it may fall back to another language or the default
* language. Components other than the language code, such as the country and
* script codes, are ignored.
* <p>
* By default, this property is set to `null`, causing results to be in the default
* language.
* <p>
* This option is experimental.
*
* @param languages The locale in which results should be returned.
* @since 2.0.0
*/
public void setLanguages(String... languages) {
adapter.setLanguage(languages);
}

/**
* Sets the listener that will be notified when the user clicks an item in the drop down list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Observable<GeocodingResponse> getObservable() {
builder.getAutocomplete(),
builder.getBbox(),
builder.getLimit(),
builder.getLanguage());
builder.getLanguages());

// Done
return observable;
Expand All @@ -95,7 +95,7 @@ public Observable<List<GeocodingResponse>> getBatchObservable() {
builder.getAutocomplete(),
builder.getBbox(),
builder.getLimit(),
builder.getLanguage());
builder.getLanguages());

// Done
return batchObservable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mapbox.services.api.ServicesException;
import com.mapbox.services.api.geocoding.v5.models.GeocodingResponse;
import com.mapbox.services.api.rx.BaseTest;

import org.junit.After;
import org.junit.Before;
Expand All @@ -10,9 +11,6 @@
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

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

public class MapboxGeocodingRxTest {
public class MapboxGeocodingRxTest extends BaseTest {

private static final double DELTA = 1E-10;

private static final String GEOCODING_FIXTURE = "../libjava-services/src/test/fixtures/geocoding.json";
private static final String GEOCODING_FIXTURE = "../libjava-services/src/test/fixtures/geocoding/geocoding.json";
private static final String ACCESS_TOKEN = "pk.XXX";

private MockWebServer server;
Expand All @@ -48,7 +44,7 @@ public void setUp() throws IOException {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
try {
String body = new String(Files.readAllBytes(Paths.get(GEOCODING_FIXTURE)), Charset.forName("utf-8"));
String body = loadJsonFixture(GEOCODING_FIXTURE);
return new MockResponse().setBody(body);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
Expand Down
Loading