Added searchType parameter to AIDL Search API

This commit is contained in:
crimean 2018-08-28 12:55:55 +03:00
parent 2f6d331c42
commit e23e835e75
4 changed files with 77 additions and 28 deletions

View file

@ -29,6 +29,7 @@ import net.osmand.aidl.maplayer.AMapLayer;
import net.osmand.aidl.maplayer.point.AMapPoint; import net.osmand.aidl.maplayer.point.AMapPoint;
import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AMapMarker;
import net.osmand.aidl.mapwidget.AMapWidget; import net.osmand.aidl.mapwidget.AMapWidget;
import net.osmand.aidl.search.SearchParams;
import net.osmand.aidl.search.SearchResult; import net.osmand.aidl.search.SearchResult;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; 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.helpers.ColorDialogs;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.views.AidlMapLayer; import net.osmand.plus.views.AidlMapLayer;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer; 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.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchSettings; import net.osmand.search.core.SearchSettings;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -1327,7 +1330,7 @@ public class OsmandAidlApi {
return true; 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) { final int radiusLevel, final int totalLimit, final SearchCompleteCallback callback) {
if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) { if (Algorithms.isEmpty(searchQuery) || latitude == 0 || longitude == 0 || callback == null) {
return false; return false;
@ -1340,30 +1343,17 @@ public class OsmandAidlApi {
@Override @Override
public void onFinish(AppInitializer init) { public void onFinish(AppInitializer init) {
runSearch(searchQuery, latitude, longitude, radiusLevel, totalLimit, callback); runSearch(searchQuery, searchType, latitude, longitude, radiusLevel, totalLimit, callback);
} }
}); });
} else { } else {
runSearch(searchQuery, latitude, longitude, radiusLevel, totalLimit, callback); runSearch(searchQuery, searchType, latitude, longitude, radiusLevel, totalLimit, callback);
} }
return true; return true;
} }
private void runSearch(String searchQuery, double latitude, double longitude, int radiusLevel, int totalLimit, final SearchCompleteCallback callback) { private void runSearch(String searchQuery, int searchType, double latitude, double longitude, int radiusLevel,
final SearchUICore core = app.getSearchUICore().getCore(); int totalLimit, final SearchCompleteCallback callback) {
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);
}
});
if (radiusLevel < 1) { if (radiusLevel < 1) {
radiusLevel = 1; radiusLevel = 1;
} else if (radiusLevel > MAX_DEFAULT_SEARCH_RADIUS) { } else if (radiusLevel > MAX_DEFAULT_SEARCH_RADIUS) {
@ -1372,15 +1362,51 @@ public class OsmandAidlApi {
if (totalLimit <= 0) { if (totalLimit <= 0) {
totalLimit = -1; 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()) SearchSettings searchSettings = new SearchSettings(core.getSearchSettings())
.setSearchTypes(CITY, VILLAGE, POSTCODE, STREET, HOUSE, STREET_INTERSECTION, POI)
.setRadiusLevel(radiusLevel) .setRadiusLevel(radiusLevel)
.setEmptyQueryAllowed(false) .setEmptyQueryAllowed(false)
.setSortByName(false) .setSortByName(false)
.setOriginalLocation(new LatLon(latitude, longitude)) .setOriginalLocation(new LatLon(latitude, longitude))
.setTotalLimit(totalLimit); .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); core.search(searchQuery, false, null, searchSettings);
} }

View file

@ -555,7 +555,7 @@ public class OsmandAidlService extends Service {
@Override @Override
public boolean search(SearchParams params, final IOsmAndAidlCallback callback) throws RemoteException { public boolean search(SearchParams params, final IOsmAndAidlCallback callback) throws RemoteException {
try { 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() { params.getLatutude(), params.getLongitude(), params.getRadiusLevel(), params.getTotalLimit(), new SearchCompleteCallback() {
@Override @Override
public void onSearchComplete(List<SearchResult> resultSet) { public void onSearchComplete(List<SearchResult> resultSet) {

View file

@ -5,14 +5,20 @@ import android.os.Parcelable;
public class SearchParams implements 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 String searchQuery;
private int searchType;
private double latutude; private double latutude;
private double longitude; private double longitude;
private int radiusLevel = 1; private int radiusLevel = 1;
private int totalLimit = -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.searchQuery = searchQuery;
this.searchType = searchType;
this.latutude = latutude; this.latutude = latutude;
this.longitude = longitude; this.longitude = longitude;
this.radiusLevel = radiusLevel; this.radiusLevel = radiusLevel;
@ -39,6 +45,10 @@ public class SearchParams implements Parcelable {
return searchQuery; return searchQuery;
} }
public int getSearchType() {
return searchType;
}
public double getLatutude() { public double getLatutude() {
return latutude; return latutude;
} }
@ -58,6 +68,7 @@ public class SearchParams implements Parcelable {
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeString(searchQuery); out.writeString(searchQuery);
out.writeInt(searchType);
out.writeDouble(latutude); out.writeDouble(latutude);
out.writeDouble(longitude); out.writeDouble(longitude);
out.writeInt(radiusLevel); out.writeInt(radiusLevel);
@ -66,6 +77,7 @@ public class SearchParams implements Parcelable {
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
searchQuery = in.readString(); searchQuery = in.readString();
searchType = in.readInt();
latutude = in.readDouble(); latutude = in.readDouble();
longitude = in.readDouble(); longitude = in.readDouble();
radiusLevel = in.readInt(); radiusLevel = in.readInt();

View file

@ -11,14 +11,19 @@ public class SearchResult implements Parcelable {
private double latitude; private double latitude;
private double longitude; private double longitude;
private String localeName; private String localName;
private String localTypeName;
private String alternateName; private String alternateName;
private List<String> otherNames = new ArrayList<>(); 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.latitude = latitude;
this.longitude = longitude; this.longitude = longitude;
this.localeName = localeName; this.localName = localName;
this.localTypeName = localTypeName;
this.alternateName = alternateName; this.alternateName = alternateName;
if (otherNames != null) { if (otherNames != null) {
this.otherNames = otherNames; this.otherNames = otherNames;
@ -49,8 +54,12 @@ public class SearchResult implements Parcelable {
return longitude; return longitude;
} }
public String getLocaleName() { public String getLocalName() {
return localeName; return localName;
}
public String getLocalTypeName() {
return localTypeName;
} }
public String getAlternateName() { public String getAlternateName() {
@ -65,7 +74,8 @@ public class SearchResult implements Parcelable {
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude); out.writeDouble(latitude);
out.writeDouble(longitude); out.writeDouble(longitude);
out.writeString(localeName); out.writeString(localName);
out.writeString(localTypeName);
out.writeString(alternateName); out.writeString(alternateName);
out.writeStringList(otherNames); out.writeStringList(otherNames);
} }
@ -73,7 +83,8 @@ public class SearchResult implements Parcelable {
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
latitude = in.readDouble(); latitude = in.readDouble();
longitude = in.readDouble(); longitude = in.readDouble();
localeName = in.readString(); localName = in.readString();
localTypeName = in.readString();
alternateName = in.readString(); alternateName = in.readString();
in.readStringList(otherNames); in.readStringList(otherNames);
} }