Added searchType parameter to AIDL Search API
This commit is contained in:
parent
2f6d331c42
commit
e23e835e75
4 changed files with 77 additions and 28 deletions
|
@ -29,6 +29,7 @@ import net.osmand.aidl.maplayer.AMapLayer;
|
|||
import net.osmand.aidl.maplayer.point.AMapPoint;
|
||||
import net.osmand.aidl.mapmarker.AMapMarker;
|
||||
import net.osmand.aidl.mapwidget.AMapWidget;
|
||||
import net.osmand.aidl.search.SearchParams;
|
||||
import net.osmand.aidl.search.SearchResult;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -54,6 +55,7 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
|
|||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.search.listitems.QuickSearchListItem;
|
||||
import net.osmand.plus.views.AidlMapLayer;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
|
@ -63,6 +65,7 @@ import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
|
|||
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.search.SearchUICore.SearchResultCollection;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.search.core.SearchSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -1327,7 +1330,7 @@ public class OsmandAidlApi {
|
|||
return true;
|
||||
}
|
||||
|
||||
boolean search(final String searchQuery, final double latitude, final double longitude,
|
||||
boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,
|
||||
final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) {
|
||||
if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) {
|
||||
return false;
|
||||
|
@ -1340,30 +1343,17 @@ public class OsmandAidlApi {
|
|||
|
||||
@Override
|
||||
public void onFinish(AppInitializer init) {
|
||||
runSearch(searchQuery, latitude, longitude, radiusLevel, totalLimit, callback);
|
||||
runSearch(searchQuery, searchType, latitude, longitude, radiusLevel, totalLimit, callback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
runSearch(searchQuery, latitude, longitude, radiusLevel, totalLimit, callback);
|
||||
runSearch(searchQuery, searchType, latitude, longitude, radiusLevel, totalLimit, callback);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void runSearch(String searchQuery, double latitude, double longitude, int radiusLevel, int totalLimit, final SearchCompleteCallback callback) {
|
||||
final SearchUICore core = app.getSearchUICore().getCore();
|
||||
core.setOnResultsComplete(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<SearchResult> resultSet = new ArrayList<>();
|
||||
SearchResultCollection resultCollection = core.getCurrentSearchResult();
|
||||
for (net.osmand.search.core.SearchResult r : resultCollection.getCurrentSearchResults()) {
|
||||
SearchResult result = new SearchResult(r.location.getLatitude(), r.location.getLongitude(), r.localeName, r.alternateName, new ArrayList<>(r.otherNames));
|
||||
resultSet.add(result);
|
||||
}
|
||||
callback.onSearchComplete(resultSet);
|
||||
}
|
||||
});
|
||||
|
||||
private void runSearch(String searchQuery, int searchType, double latitude, double longitude, int radiusLevel,
|
||||
int totalLimit, final SearchCompleteCallback callback) {
|
||||
if (radiusLevel < 1) {
|
||||
radiusLevel = 1;
|
||||
} else if (radiusLevel > MAX_DEFAULT_SEARCH_RADIUS) {
|
||||
|
@ -1372,15 +1362,51 @@ public class OsmandAidlApi {
|
|||
if (totalLimit <= 0) {
|
||||
totalLimit = -1;
|
||||
}
|
||||
final int limit = totalLimit;
|
||||
|
||||
final SearchUICore core = app.getSearchUICore().getCore();
|
||||
core.setOnResultsComplete(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<SearchResult> resultSet = new ArrayList<>();
|
||||
SearchResultCollection resultCollection = core.getCurrentSearchResult();
|
||||
int count = 0;
|
||||
for (net.osmand.search.core.SearchResult r : resultCollection.getCurrentSearchResults()) {
|
||||
String name = QuickSearchListItem.getName(app, r);
|
||||
String typeName = QuickSearchListItem.getTypeName(app, r);
|
||||
SearchResult result = new SearchResult(r.location.getLatitude(), r.location.getLongitude(),
|
||||
name, typeName, r.alternateName, new ArrayList<>(r.otherNames));
|
||||
resultSet.add(result);
|
||||
count++;
|
||||
if (limit != -1 && count >= limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
callback.onSearchComplete(resultSet);
|
||||
}
|
||||
});
|
||||
|
||||
SearchSettings searchSettings = new SearchSettings(core.getSearchSettings())
|
||||
.setSearchTypes(CITY, VILLAGE, POSTCODE, STREET, HOUSE, STREET_INTERSECTION, POI)
|
||||
.setRadiusLevel(radiusLevel)
|
||||
.setEmptyQueryAllowed(false)
|
||||
.setSortByName(false)
|
||||
.setOriginalLocation(new LatLon(latitude, longitude))
|
||||
.setTotalLimit(totalLimit);
|
||||
|
||||
List<ObjectType> searchTypes = new ArrayList<>();
|
||||
if ((searchType & SearchParams.SEARCH_TYPE_POI) != 0) {
|
||||
searchTypes.add(POI);
|
||||
}
|
||||
if ((searchType & SearchParams.SEARCH_TYPE_ADDRESS) != 0) {
|
||||
searchTypes.add(CITY);
|
||||
searchTypes.add(VILLAGE);
|
||||
searchTypes.add(POSTCODE);
|
||||
searchTypes.add(STREET);
|
||||
searchTypes.add(HOUSE);
|
||||
searchTypes.add(STREET_INTERSECTION);
|
||||
}
|
||||
searchSettings = searchSettings.setSearchTypes(searchTypes.toArray(new ObjectType[searchTypes.size()]));
|
||||
|
||||
core.search(searchQuery, false, null, searchSettings);
|
||||
}
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean search(SearchParams params, final IOsmAndAidlCallback callback) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("search").search(params.getSearchQuery(),
|
||||
return params != null && getApi("search").search(params.getSearchQuery(), params.getSearchType(),
|
||||
params.getLatutude(), params.getLongitude(), params.getRadiusLevel(), params.getTotalLimit(), new SearchCompleteCallback() {
|
||||
@Override
|
||||
public void onSearchComplete(List<SearchResult> resultSet) {
|
||||
|
|
|
@ -5,14 +5,20 @@ import android.os.Parcelable;
|
|||
|
||||
public class SearchParams implements Parcelable {
|
||||
|
||||
public static final int SEARCH_TYPE_POI = 1;
|
||||
public static final int SEARCH_TYPE_ADDRESS = 2;
|
||||
public static final int SEARCH_TYPE_ALL = SEARCH_TYPE_POI | SEARCH_TYPE_ADDRESS;
|
||||
|
||||
private String searchQuery;
|
||||
private int searchType;
|
||||
private double latutude;
|
||||
private double longitude;
|
||||
private int radiusLevel = 1;
|
||||
private int totalLimit = -1;
|
||||
|
||||
public SearchParams(String searchQuery, double latutude, double longitude, int radiusLevel, int totalLimit) {
|
||||
public SearchParams(String searchQuery, int searchType, double latutude, double longitude, int radiusLevel, int totalLimit) {
|
||||
this.searchQuery = searchQuery;
|
||||
this.searchType = searchType;
|
||||
this.latutude = latutude;
|
||||
this.longitude = longitude;
|
||||
this.radiusLevel = radiusLevel;
|
||||
|
@ -39,6 +45,10 @@ public class SearchParams implements Parcelable {
|
|||
return searchQuery;
|
||||
}
|
||||
|
||||
public int getSearchType() {
|
||||
return searchType;
|
||||
}
|
||||
|
||||
public double getLatutude() {
|
||||
return latutude;
|
||||
}
|
||||
|
@ -58,6 +68,7 @@ public class SearchParams implements Parcelable {
|
|||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(searchQuery);
|
||||
out.writeInt(searchType);
|
||||
out.writeDouble(latutude);
|
||||
out.writeDouble(longitude);
|
||||
out.writeInt(radiusLevel);
|
||||
|
@ -66,6 +77,7 @@ public class SearchParams implements Parcelable {
|
|||
|
||||
private void readFromParcel(Parcel in) {
|
||||
searchQuery = in.readString();
|
||||
searchType = in.readInt();
|
||||
latutude = in.readDouble();
|
||||
longitude = in.readDouble();
|
||||
radiusLevel = in.readInt();
|
||||
|
|
|
@ -11,14 +11,19 @@ public class SearchResult implements Parcelable {
|
|||
private double latitude;
|
||||
private double longitude;
|
||||
|
||||
private String localeName;
|
||||
private String localName;
|
||||
private String localTypeName;
|
||||
|
||||
private String alternateName;
|
||||
private List<String> otherNames = new ArrayList<>();
|
||||
|
||||
public SearchResult(double latitude, double longitude, String localeName, String alternateName, List<String> otherNames) {
|
||||
|
||||
public SearchResult(double latitude, double longitude, String localName, String localTypeName,
|
||||
String alternateName, List<String> otherNames) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.localeName = localeName;
|
||||
this.localName = localName;
|
||||
this.localTypeName = localTypeName;
|
||||
this.alternateName = alternateName;
|
||||
if (otherNames != null) {
|
||||
this.otherNames = otherNames;
|
||||
|
@ -49,8 +54,12 @@ public class SearchResult implements Parcelable {
|
|||
return longitude;
|
||||
}
|
||||
|
||||
public String getLocaleName() {
|
||||
return localeName;
|
||||
public String getLocalName() {
|
||||
return localName;
|
||||
}
|
||||
|
||||
public String getLocalTypeName() {
|
||||
return localTypeName;
|
||||
}
|
||||
|
||||
public String getAlternateName() {
|
||||
|
@ -65,7 +74,8 @@ public class SearchResult implements Parcelable {
|
|||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeDouble(latitude);
|
||||
out.writeDouble(longitude);
|
||||
out.writeString(localeName);
|
||||
out.writeString(localName);
|
||||
out.writeString(localTypeName);
|
||||
out.writeString(alternateName);
|
||||
out.writeStringList(otherNames);
|
||||
}
|
||||
|
@ -73,7 +83,8 @@ public class SearchResult implements Parcelable {
|
|||
private void readFromParcel(Parcel in) {
|
||||
latitude = in.readDouble();
|
||||
longitude = in.readDouble();
|
||||
localeName = in.readString();
|
||||
localName = in.readString();
|
||||
localTypeName = in.readString();
|
||||
alternateName = in.readString();
|
||||
in.readStringList(otherNames);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue