Skip to content
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 @@ -36,6 +36,7 @@ public class GeocoderAdapter extends BaseAdapter implements Filterable {
private String country;
private String[] countries;
private String type;
private String[] types;
private double[] bbox;
private Position position;
private int limit;
Expand Down Expand Up @@ -133,6 +134,17 @@ public String getType() {
return type;
}

/**
* Get the geocder filter types in a String array.
*
* @return String containing "place", "poi", "neighborhood", etc.
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
* @since 2.0.0
*/
public String[] getTypes() {
return types;
}

/**
* Configure the geocoder type, pass in one of the constants found within
* {@link com.mapbox.services.geocoding.v5.GeocodingCriteria}.
Expand All @@ -145,6 +157,18 @@ public void setType(String type) {
this.type = type;
}

/**
* Configure the geocoder type, pass in one or more of the constants found within
* {@link com.mapbox.services.geocoding.v5.GeocodingCriteria}.
*
* @param types String array containing "place", "poi", "neighborhood", etc.
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
* @since 2.0.0
*/
public void setTypes(String[] types) {
this.types = types;
}

/**
* Bounding box within which to limit results
*
Expand Down Expand Up @@ -374,6 +398,9 @@ protected FilterResults performFiltering(CharSequence constraint) {
if (getType() != null) {
builder.setGeocodingType(getType());
}
if (getTypes() != null) {
builder.setGeocodingTypes(getTypes());
}
if (getBbox() != null) {
builder.setBbox(bbox[0], bbox[1], bbox[2], bbox[3]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.services.android.geocoder.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class GeocoderAutoCompleteView extends AutoCompleteTextView {
private static final int DEFAULT_NUMBER_OF_LINES = 1;

private GeocoderAdapter adapter;
private Drawable imgClearButton;

public interface OnFeatureListener {
void OnFeatureClick(CarmenFeature feature);
Expand All @@ -38,6 +40,10 @@ public interface OnFeatureListener {
public GeocoderAutoCompleteView(Context context, AttributeSet attrs) {
super(context, attrs);

// Get attributes from attrs.xml
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.mas_geocoderWidget);
imgClearButton = attributes.getDrawable(R.styleable.mas_geocoderWidget_mas_clearButtonDrawable);

// Set custom adapter
adapter = new GeocoderAdapter(context);
setAdapter(adapter);
Expand All @@ -60,7 +66,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
});

// Add clear button to autocomplete
final Drawable imgClearButton = ContextCompat.getDrawable(context, R.drawable.ic_clear_black_24dp);
if (imgClearButton == null) {
imgClearButton = ContextCompat.getDrawable(context, R.drawable.ic_clear_black_24dp);
}
setCompoundDrawablesWithIntrinsicBounds(null, null, imgClearButton, null);
setOnTouchListener(new View.OnTouchListener() {
@Override
Expand Down Expand Up @@ -117,6 +125,18 @@ public void setType(String type) {
adapter.setType(type);
}

/**
* Configure the geocoder type, pass in one or more of the constants found within
* {@link com.mapbox.services.geocoding.v5.GeocodingCriteria}.
*
* @param types String array containing "place", "poi", "neighborhood", etc.
* @see <a href="https://www.mapbox.com/api-documentation/#request-format">Geocoding API documentation</a>
* @since 2.0.0
*/
public void setTypes(String[] types) {
adapter.setTypes(types);
}

/**
* Parameter limits results to a country. Use one of the
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes. The country code is
Expand Down
6 changes: 6 additions & 0 deletions libandroid/lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="mas_geocoderWidget">
<attr name="mas_clearButtonDrawable" format="integer" />
</declare-styleable>
</resources>