Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d40195c507
7 changed files with 182 additions and 81 deletions
|
@ -9,6 +9,8 @@ public enum ObjectType {
|
||||||
LOCATION(true), PARTIAL_LOCATION(false),
|
LOCATION(true), PARTIAL_LOCATION(false),
|
||||||
// UI OBJECTS
|
// UI OBJECTS
|
||||||
FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true),
|
FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true),
|
||||||
|
// ONLINE
|
||||||
|
ONLINE_SEARCH(true), ONLINE_ADDRESS(true),
|
||||||
|
|
||||||
REGION(true),
|
REGION(true),
|
||||||
|
|
||||||
|
|
|
@ -685,7 +685,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
if (searchLocation != null) {
|
if (searchLocation != null) {
|
||||||
if (requestType == NEW_SEARCH_INIT) {
|
if (requestType == NEW_SEARCH_INIT) {
|
||||||
return filter.initializeNewSearch(searchLocation.getLatitude(), searchLocation.getLongitude(),
|
return filter.initializeNewSearch(searchLocation.getLatitude(), searchLocation.getLongitude(),
|
||||||
-1, this);
|
-1, this, -1);
|
||||||
} else if (requestType == SEARCH_FURTHER) {
|
} else if (requestType == SEARCH_FURTHER) {
|
||||||
return filter.searchFurther(searchLocation.getLatitude(), searchLocation.getLongitude(), this);
|
return filter.searchFurther(searchLocation.getLatitude(), searchLocation.getLongitude(), this);
|
||||||
} else if (requestType == SEARCH_AGAIN) {
|
} else if (requestType == SEARCH_AGAIN) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
|
|
||||||
protected int distanceInd = 0;
|
protected int distanceInd = 0;
|
||||||
// in kilometers
|
// in kilometers
|
||||||
protected double[] distanceToSearchValues = new double[] { 1, 2, 5, 10, 20, 50, 100, 200, 500 };
|
protected double[] distanceToSearchValues = new double[]{1, 2, 5, 10, 20, 50, 100, 200, 500};
|
||||||
|
|
||||||
private final MapPoiTypes poiTypes;
|
private final MapPoiTypes poiTypes;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
|
|
||||||
// constructor for user defined filters
|
// constructor for user defined filters
|
||||||
public PoiUIFilter(String name, String filterId,
|
public PoiUIFilter(String name, String filterId,
|
||||||
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app) {
|
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
isStandardFilter = false;
|
isStandardFilter = false;
|
||||||
poiTypes = app.getPoiTypes();
|
poiTypes = app.getPoiTypes();
|
||||||
|
@ -209,8 +209,14 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher) {
|
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher, int radius) {
|
||||||
clearPreviousZoom();
|
if (radius < 0) {
|
||||||
|
clearPreviousZoom();
|
||||||
|
} else if (radius < distanceToSearchValues.length) {
|
||||||
|
distanceInd = radius;
|
||||||
|
} else {
|
||||||
|
distanceInd = distanceToSearchValues.length - 1;
|
||||||
|
}
|
||||||
List<Amenity> amenityList = searchAmenities(lat, lon, matcher);
|
List<Amenity> amenityList = searchAmenities(lat, lon, matcher);
|
||||||
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
||||||
if (firstTimeLimit > 0) {
|
if (firstTimeLimit > 0) {
|
||||||
|
@ -246,7 +252,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom,
|
public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom,
|
||||||
ResultMatcher<Amenity> matcher) {
|
ResultMatcher<Amenity> matcher) {
|
||||||
List<Amenity> results = new ArrayList<Amenity>();
|
List<Amenity> results = new ArrayList<Amenity>();
|
||||||
List<Amenity> tempResults = currentSearchResult;
|
List<Amenity> tempResults = currentSearchResult;
|
||||||
if (tempResults != null) {
|
if (tempResults != null) {
|
||||||
|
@ -271,7 +277,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Amenity> searchAmenitiesInternal(double lat, double lon, double topLatitude,
|
protected List<Amenity> searchAmenitiesInternal(double lat, double lon, double topLatitude,
|
||||||
double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||||
return app.getResourceManager().searchAmenities(this,
|
return app.getResourceManager().searchAmenities(this,
|
||||||
topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, wrapResultMatcher(matcher));
|
topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, wrapResultMatcher(matcher));
|
||||||
}
|
}
|
||||||
|
@ -315,10 +321,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
|
|
||||||
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
||||||
final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
|
final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
|
||||||
final CollatorStringMatcher sm =
|
final CollatorStringMatcher sm =
|
||||||
nmFilter.length() > 0 ?
|
nmFilter.length() > 0 ?
|
||||||
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
||||||
return new AmenityNameFilter() {
|
return new AmenityNameFilter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -333,8 +339,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
if (poiAdditionals != null) {
|
if (poiAdditionals != null) {
|
||||||
Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
|
Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
|
||||||
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
|
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
|
||||||
for (PoiType pt : poiAdditionals) {
|
for (PoiType pt : poiAdditionals) {
|
||||||
String category = pt.getPoiAdditionalCategory();
|
String category = pt.getPoiAdditionalCategory();
|
||||||
List<PoiType> types = poiAdditionalCategoriesMap.get(category);
|
List<PoiType> types = poiAdditionalCategoriesMap.get(category);
|
||||||
if (types == null) {
|
if (types == null) {
|
||||||
types = new ArrayList<>();
|
types = new ArrayList<>();
|
||||||
|
|
|
@ -1079,6 +1079,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
for (SearchResult sr : res.getCurrentSearchResults()) {
|
for (SearchResult sr : res.getCurrentSearchResults()) {
|
||||||
rows.add(new QuickSearchListItem(app, sr));
|
rows.add(new QuickSearchListItem(app, sr));
|
||||||
}
|
}
|
||||||
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark,
|
||||||
|
app.getString(R.string.search_online_address), new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
startOnlinePoiSearch();
|
||||||
|
mainSearchFragment.getAdapter().clear();
|
||||||
|
updateTabbarVisibility(false);
|
||||||
|
openKeyboard();
|
||||||
|
}
|
||||||
|
}));
|
||||||
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark,
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark,
|
||||||
app.getString(R.string.custom_search), new OnClickListener() {
|
app.getString(R.string.custom_search), new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1320,6 +1330,17 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startOnlinePoiSearch() {
|
||||||
|
SearchSettings settings = searchUICore.getSearchSettings()
|
||||||
|
.setSearchTypes(ObjectType.ONLINE_SEARCH)
|
||||||
|
.setEmptyQueryAllowed(false)
|
||||||
|
.setAddressSearch(false)
|
||||||
|
.setSortByName(true)
|
||||||
|
.setRadiusLevel(1);
|
||||||
|
|
||||||
|
searchUICore.updateSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
private void startAddressSearch() {
|
private void startAddressSearch() {
|
||||||
SearchSettings settings = searchUICore.getSearchSettings()
|
SearchSettings settings = searchUICore.getSearchSettings()
|
||||||
.setEmptyQueryAllowed(true)
|
.setEmptyQueryAllowed(true)
|
||||||
|
|
|
@ -1,26 +1,38 @@
|
||||||
package net.osmand.plus.search;
|
package net.osmand.plus.search;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
|
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||||
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.QuadRect;
|
||||||
|
import net.osmand.osm.AbstractPoiType;
|
||||||
|
import net.osmand.osm.MapPoiTypes;
|
||||||
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
|
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.resources.ResourceManager.ResourceListener;
|
import net.osmand.plus.resources.ResourceManager.ResourceListener;
|
||||||
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.SearchUICore.SearchResultMatcher;
|
||||||
import net.osmand.search.core.CustomSearchPoiFilter;
|
import net.osmand.search.core.CustomSearchPoiFilter;
|
||||||
import net.osmand.search.core.ObjectType;
|
import net.osmand.search.core.ObjectType;
|
||||||
import net.osmand.search.core.SearchCoreFactory.SearchBaseAPI;
|
import net.osmand.search.core.SearchCoreFactory.SearchBaseAPI;
|
||||||
import net.osmand.search.core.SearchPhrase;
|
import net.osmand.search.core.SearchPhrase;
|
||||||
import net.osmand.search.core.SearchResult;
|
import net.osmand.search.core.SearchResult;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -36,6 +48,8 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
public static final int SEARCH_WPT_OBJECT_PRIORITY = 52;
|
public static final int SEARCH_WPT_OBJECT_PRIORITY = 52;
|
||||||
public static final int SEARCH_HISTORY_API_PRIORITY = 50;
|
public static final int SEARCH_HISTORY_API_PRIORITY = 50;
|
||||||
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 53;
|
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 53;
|
||||||
|
public static final int SEARCH_ONLINE_AMENITY_PRIORITY = 700;
|
||||||
|
public static final int SEARCH_ONLINE_ADDRESS_PRIORITY = 500;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private SearchUICore core;
|
private SearchUICore core;
|
||||||
private SearchResultCollection resultCollection;
|
private SearchResultCollection resultCollection;
|
||||||
|
@ -78,13 +92,15 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
core.registerAPI(new SearchWptAPI(app));
|
core.registerAPI(new SearchWptAPI(app));
|
||||||
core.registerAPI(new SearchHistoryAPI(app));
|
core.registerAPI(new SearchHistoryAPI(app));
|
||||||
|
|
||||||
|
core.registerAPI(new SearchOnlineApi(app));
|
||||||
|
|
||||||
refreshCustomPoiFilters();
|
refreshCustomPoiFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshCustomPoiFilters() {
|
public void refreshCustomPoiFilters() {
|
||||||
core.clearCustomSearchPoiFilters();
|
core.clearCustomSearchPoiFilters();
|
||||||
PoiFiltersHelper poiFilters = app.getPoiFilters();
|
PoiFiltersHelper poiFilters = app.getPoiFilters();
|
||||||
for(CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
|
for (CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
|
||||||
core.addCustomSearchPoiFilter(udf, 0);
|
core.addCustomSearchPoiFilter(udf, 0);
|
||||||
}
|
}
|
||||||
PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
|
PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
|
||||||
|
@ -99,6 +115,45 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
core.getSearchSettings().setOfflineIndexes(Arrays.asList(binaryMapIndexReaderArray));
|
core.getSearchSettings().setOfflineIndexes(Arrays.asList(binaryMapIndexReaderArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
|
||||||
|
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
|
||||||
|
List<Amenity> amenities = app.getResourceManager().searchAmenities(
|
||||||
|
new SearchPoiTypeFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(PoiCategory type, String subcategory) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
|
||||||
|
|
||||||
|
MapPoiTypes types = app.getPoiTypes();
|
||||||
|
for (Amenity amenity : amenities) {
|
||||||
|
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
|
||||||
|
if (poiSimpleFormat.equals(name)) {
|
||||||
|
return amenity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Amenity amenity : amenities) {
|
||||||
|
String amenityName = amenity.getName(lang, transliterate);
|
||||||
|
if (Algorithms.isEmpty(amenityName)) {
|
||||||
|
AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
|
||||||
|
if (st != null) {
|
||||||
|
amenityName = st.getTranslation();
|
||||||
|
} else {
|
||||||
|
amenityName = amenity.getSubType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name.contains(amenityName)) {
|
||||||
|
return amenity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static class SearchWptAPI extends SearchBaseAPI {
|
public static class SearchWptAPI extends SearchBaseAPI {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -114,7 +169,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
|
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||||
if (phrase.isEmpty()) {
|
if (phrase.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +200,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSearchPriority(SearchPhrase p) {
|
public int getSearchPriority(SearchPhrase p) {
|
||||||
if(!p.isNoSelectedType()) {
|
if (!p.isNoSelectedType()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return SEARCH_WPT_API_PRIORITY;
|
return SEARCH_WPT_API_PRIORITY;
|
||||||
|
@ -169,7 +224,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
|
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||||
String baseGroupName = app.getString(R.string.shared_string_favorites);
|
String baseGroupName = app.getString(R.string.shared_string_favorites);
|
||||||
List<FavoriteGroup> groups = app.getFavorites().getFavoriteGroups();
|
List<FavoriteGroup> groups = app.getFavorites().getFavoriteGroups();
|
||||||
for (FavoriteGroup group : groups) {
|
for (FavoriteGroup group : groups) {
|
||||||
|
@ -225,7 +280,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
|
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||||
List<FavouritePoint> favList = app.getFavorites().getFavouritePoints();
|
List<FavouritePoint> favList = app.getFavorites().getFavouritePoints();
|
||||||
for (FavouritePoint point : favList) {
|
for (FavouritePoint point : favList) {
|
||||||
if (!point.isVisible()) {
|
if (!point.isVisible()) {
|
||||||
|
@ -259,13 +314,68 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
if (p.isLastWord(ObjectType.FAVORITE_GROUP)) {
|
if (p.isLastWord(ObjectType.FAVORITE_GROUP)) {
|
||||||
return SEARCH_FAVORITE_API_PRIORITY;
|
return SEARCH_FAVORITE_API_PRIORITY;
|
||||||
}
|
}
|
||||||
if(!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
if (!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return SEARCH_FAVORITE_API_PRIORITY;
|
return SEARCH_FAVORITE_API_PRIORITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SearchOnlineApi extends SearchBaseAPI {
|
||||||
|
|
||||||
|
OsmandApplication app;
|
||||||
|
private NominatimPoiFilter poiFilter;
|
||||||
|
private NominatimPoiFilter addressFilter;
|
||||||
|
|
||||||
|
public SearchOnlineApi(OsmandApplication app) {
|
||||||
|
super(ObjectType.ONLINE_SEARCH);
|
||||||
|
this.app = app;
|
||||||
|
this.poiFilter = app.getPoiFilters().getNominatimPOIFilter();
|
||||||
|
this.addressFilter = app.getPoiFilters().getNominatimAddressFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean search(SearchPhrase phrase, SearchResultMatcher matcher) throws IOException {
|
||||||
|
double lat = phrase.getSettings().getOriginalLocation().getLatitude();
|
||||||
|
double lon = phrase.getSettings().getOriginalLocation().getLongitude();
|
||||||
|
String text = phrase.getUnknownSearchPhrase();
|
||||||
|
poiFilter.setFilterByName(text);
|
||||||
|
addressFilter.setFilterByName(text);
|
||||||
|
publishAmenities(phrase, matcher, poiFilter.initializeNewSearch(lat, lon, -1, null, phrase.getRadiusLevel()), true);
|
||||||
|
publishAmenities(phrase, matcher, addressFilter.initializeNewSearch(lat, lon, -1, null, -1), false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publishAmenities(SearchPhrase phrase, SearchResultMatcher matcher, List<Amenity> amenities, boolean poi) {
|
||||||
|
for (Amenity amenity : amenities) {
|
||||||
|
SearchResult sr = getSearchResult(phrase, poi, amenity);
|
||||||
|
if (poi) {
|
||||||
|
LatLon latLon = amenity.getLocation();
|
||||||
|
String lang = sr.requiredSearchPhrase.getSettings().getLang();
|
||||||
|
boolean transliterate = sr.requiredSearchPhrase.getSettings().isTransliterate();
|
||||||
|
Amenity a = app.getSearchUICore().findAmenity(amenity.getName(), latLon.getLatitude(),
|
||||||
|
latLon.getLongitude(), lang, transliterate);
|
||||||
|
if (a != null) {
|
||||||
|
sr = getSearchResult(phrase, true, a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matcher.publish(sr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private SearchResult getSearchResult(SearchPhrase phrase, boolean poi, Amenity amenity) {
|
||||||
|
SearchResult sr = new SearchResult(phrase);
|
||||||
|
sr.localeName = amenity.getName();
|
||||||
|
sr.object = amenity;
|
||||||
|
sr.priority = poi ? SEARCH_ONLINE_AMENITY_PRIORITY : SEARCH_ONLINE_ADDRESS_PRIORITY;
|
||||||
|
sr.objectType = poi ? ObjectType.POI : ObjectType.ONLINE_ADDRESS;
|
||||||
|
sr.location = amenity.getLocation();
|
||||||
|
sr.preferredZoom = 17;
|
||||||
|
return sr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class SearchHistoryAPI extends SearchBaseAPI {
|
public static class SearchHistoryAPI extends SearchBaseAPI {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -281,7 +391,7 @@ public class QuickSearchHelper implements ResourceListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
|
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||||
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
||||||
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
||||||
int p = 0;
|
int p = 0;
|
||||||
|
|
|
@ -10,17 +10,12 @@ import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.QuadRect;
|
|
||||||
import net.osmand.data.Street;
|
import net.osmand.data.Street;
|
||||||
import net.osmand.osm.AbstractPoiType;
|
|
||||||
import net.osmand.osm.MapPoiTypes;
|
|
||||||
import net.osmand.osm.PoiCategory;
|
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -38,7 +33,6 @@ import net.osmand.plus.search.listitems.QuickSearchTopShadowListItem;
|
||||||
import net.osmand.search.core.ObjectType;
|
import net.osmand.search.core.ObjectType;
|
||||||
import net.osmand.search.core.SearchResult;
|
import net.osmand.search.core.SearchResult;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -177,18 +171,18 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
Amenity a = (Amenity) object;
|
Amenity a = (Amenity) object;
|
||||||
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
|
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
|
||||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
|
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
|
||||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
|
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, a));
|
||||||
break;
|
break;
|
||||||
case RECENT_OBJ:
|
case RECENT_OBJ:
|
||||||
HistoryEntry entry = (HistoryEntry) object;
|
HistoryEntry entry = (HistoryEntry) object;
|
||||||
pointDescription = entry.getName();
|
pointDescription = entry.getName();
|
||||||
if (pointDescription.isPoi()) {
|
if (pointDescription.isPoi()) {
|
||||||
Amenity amenity = findAmenity(entry.getName().getName(), entry.getLat(), entry.getLon(), lang, transliterate);
|
Amenity amenity = app.getSearchUICore().findAmenity(entry.getName().getName(), entry.getLat(), entry.getLon(), lang, transliterate);
|
||||||
if (amenity != null) {
|
if (amenity != null) {
|
||||||
object = amenity;
|
object = amenity;
|
||||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI,
|
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI,
|
||||||
OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
|
OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
|
||||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(amenity));
|
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, amenity));
|
||||||
}
|
}
|
||||||
} else if (pointDescription.isFavorite()) {
|
} else if (pointDescription.isFavorite()) {
|
||||||
LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
|
LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
|
||||||
|
@ -291,46 +285,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
|
|
||||||
OsmandApplication app = getMyApplication();
|
|
||||||
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
|
|
||||||
List<Amenity> amenities = app.getResourceManager().searchAmenities(
|
|
||||||
new SearchPoiTypeFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(PoiCategory type, String subcategory) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
|
|
||||||
|
|
||||||
MapPoiTypes types = app.getPoiTypes();
|
|
||||||
for (Amenity amenity : amenities) {
|
|
||||||
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
|
|
||||||
if (poiSimpleFormat.equals(name)) {
|
|
||||||
return amenity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Amenity amenity : amenities) {
|
|
||||||
String amenityName = amenity.getName(lang, transliterate);
|
|
||||||
if (Algorithms.isEmpty(amenityName)) {
|
|
||||||
AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
|
|
||||||
if (st != null) {
|
|
||||||
amenityName = st.getTranslation();
|
|
||||||
} else {
|
|
||||||
amenityName = amenity.getSubType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name.contains(amenityName)) {
|
|
||||||
return amenity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapActivity getMapActivity() {
|
public MapActivity getMapActivity() {
|
||||||
return (MapActivity) getActivity();
|
return (MapActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,6 +242,8 @@ public class QuickSearchListItem {
|
||||||
sb.append(new File(gpx.path).getName());
|
sb.append(new File(gpx.path).getName());
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
case ONLINE_ADDRESS:
|
||||||
|
return app.getString(R.string.shared_string_address);
|
||||||
case UNKNOWN_NAME_FILTER:
|
case UNKNOWN_NAME_FILTER:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -287,8 +289,11 @@ public class QuickSearchListItem {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAmenityIconName(Amenity amenity) {
|
public static String getAmenityIconName(OsmandApplication app, Amenity amenity) {
|
||||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||||
|
if (st == null) {
|
||||||
|
st = app.getPoiTypes().getPoiTypeByKey(amenity.getSubType());
|
||||||
|
}
|
||||||
if (st != null) {
|
if (st != null) {
|
||||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||||
return st.getIconKeyName();
|
return st.getIconKeyName();
|
||||||
|
@ -344,7 +349,7 @@ public class QuickSearchListItem {
|
||||||
}
|
}
|
||||||
case POI:
|
case POI:
|
||||||
Amenity amenity = (Amenity) searchResult.object;
|
Amenity amenity = (Amenity) searchResult.object;
|
||||||
String id = getAmenityIconName(amenity);
|
String id = getAmenityIconName(app, amenity);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
iconId = RenderingIcons.getBigIconResourceId(id);
|
iconId = RenderingIcons.getBigIconResourceId(id);
|
||||||
if (iconId > 0) {
|
if (iconId > 0) {
|
||||||
|
@ -392,6 +397,9 @@ public class QuickSearchListItem {
|
||||||
case WPT:
|
case WPT:
|
||||||
WptPt wpt = (WptPt) searchResult.object;
|
WptPt wpt = (WptPt) searchResult.object;
|
||||||
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
|
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
|
||||||
|
case ONLINE_ADDRESS:
|
||||||
|
return app.getIconsCache().getIcon(R.drawable.ic_action_search_dark,
|
||||||
|
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||||
case UNKNOWN_NAME_FILTER:
|
case UNKNOWN_NAME_FILTER:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue