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),
|
||||
// UI OBJECTS
|
||||
FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true),
|
||||
// ONLINE
|
||||
ONLINE_SEARCH(true), ONLINE_ADDRESS(true),
|
||||
|
||||
REGION(true),
|
||||
|
||||
|
|
|
@ -685,7 +685,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
if (searchLocation != null) {
|
||||
if (requestType == NEW_SEARCH_INIT) {
|
||||
return filter.initializeNewSearch(searchLocation.getLatitude(), searchLocation.getLongitude(),
|
||||
-1, this);
|
||||
-1, this, -1);
|
||||
} else if (requestType == SEARCH_FURTHER) {
|
||||
return filter.searchFurther(searchLocation.getLatitude(), searchLocation.getLongitude(), this);
|
||||
} else if (requestType == SEARCH_AGAIN) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
|
||||
protected int distanceInd = 0;
|
||||
// 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;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
|
||||
// constructor for user defined filters
|
||||
public PoiUIFilter(String name, String filterId,
|
||||
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app) {
|
||||
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app) {
|
||||
this.app = app;
|
||||
isStandardFilter = false;
|
||||
poiTypes = app.getPoiTypes();
|
||||
|
@ -202,15 +202,21 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
public void clearPreviousZoom() {
|
||||
distanceInd = 0;
|
||||
}
|
||||
|
||||
|
||||
public void clearCurrentResults() {
|
||||
if (currentSearchResult != null) {
|
||||
currentSearchResult = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher) {
|
||||
clearPreviousZoom();
|
||||
public List<Amenity> initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher<Amenity> matcher, int radius) {
|
||||
if (radius < 0) {
|
||||
clearPreviousZoom();
|
||||
} else if (radius < distanceToSearchValues.length) {
|
||||
distanceInd = radius;
|
||||
} else {
|
||||
distanceInd = distanceToSearchValues.length - 1;
|
||||
}
|
||||
List<Amenity> amenityList = searchAmenities(lat, lon, matcher);
|
||||
MapUtils.sortListOfMapObject(amenityList, lat, lon);
|
||||
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,
|
||||
ResultMatcher<Amenity> matcher) {
|
||||
ResultMatcher<Amenity> matcher) {
|
||||
List<Amenity> results = new ArrayList<Amenity>();
|
||||
List<Amenity> tempResults = currentSearchResult;
|
||||
if (tempResults != null) {
|
||||
|
@ -271,8 +277,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
}
|
||||
|
||||
protected List<Amenity> searchAmenitiesInternal(double lat, double lon, double topLatitude,
|
||||
double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||
return app.getResourceManager().searchAmenities(this,
|
||||
double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
|
||||
return app.getResourceManager().searchAmenities(this,
|
||||
topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, wrapResultMatcher(matcher));
|
||||
}
|
||||
|
||||
|
@ -314,17 +320,17 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter);
|
||||
}
|
||||
|
||||
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
||||
final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
|
||||
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
||||
final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
|
||||
final CollatorStringMatcher sm =
|
||||
nmFilter.length() > 0 ?
|
||||
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
||||
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
||||
return new AmenityNameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(Amenity a) {
|
||||
if (sm != null) {
|
||||
String lower = OsmAndFormatter.getPoiStringWithoutType(a,
|
||||
String lower = OsmAndFormatter.getPoiStringWithoutType(a,
|
||||
app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
|
||||
if (!sm.matches(lower)) {
|
||||
return false;
|
||||
|
@ -333,8 +339,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
if (poiAdditionals != null) {
|
||||
Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
|
||||
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
|
||||
for (PoiType pt : poiAdditionals) {
|
||||
String category = pt.getPoiAdditionalCategory();
|
||||
for (PoiType pt : poiAdditionals) {
|
||||
String category = pt.getPoiAdditionalCategory();
|
||||
List<PoiType> types = poiAdditionalCategoriesMap.get(category);
|
||||
if (types == null) {
|
||||
types = new ArrayList<>();
|
||||
|
@ -417,7 +423,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
public Object getIconResource() {
|
||||
return getIconId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResultMatcher<Amenity> wrapResultMatcher(final ResultMatcher<Amenity> matcher) {
|
||||
final AmenityNameFilter nm = getNameFilter(filterByName);
|
||||
|
@ -699,7 +705,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
}
|
||||
return set.contains(subtype);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return acceptedTypes.isEmpty() &&
|
||||
|
|
|
@ -1079,6 +1079,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
for (SearchResult sr : res.getCurrentSearchResults()) {
|
||||
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,
|
||||
app.getString(R.string.custom_search), new OnClickListener() {
|
||||
@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() {
|
||||
SearchSettings settings = searchUICore.getSearchSettings()
|
||||
.setEmptyQueryAllowed(true)
|
||||
|
|
|
@ -1,26 +1,38 @@
|
|||
package net.osmand.plus.search;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
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.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.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.resources.ResourceManager.ResourceListener;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.search.SearchUICore.SearchResultCollection;
|
||||
import net.osmand.search.SearchUICore.SearchResultMatcher;
|
||||
import net.osmand.search.core.CustomSearchPoiFilter;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.search.core.SearchCoreFactory.SearchBaseAPI;
|
||||
import net.osmand.search.core.SearchPhrase;
|
||||
import net.osmand.search.core.SearchResult;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
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_HISTORY_API_PRIORITY = 50;
|
||||
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 SearchUICore core;
|
||||
private SearchResultCollection resultCollection;
|
||||
|
@ -43,11 +57,11 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
|
||||
public QuickSearchHelper(OsmandApplication app) {
|
||||
this.app = app;
|
||||
core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(),
|
||||
core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get(),
|
||||
app.getSettings().MAP_TRANSLITERATE_NAMES.get());
|
||||
app.getResourceManager().addResourceListener(this);
|
||||
}
|
||||
|
||||
|
||||
public SearchUICore getCore() {
|
||||
if (mapsIndexed) {
|
||||
mapsIndexed = false;
|
||||
|
@ -78,13 +92,15 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
core.registerAPI(new SearchWptAPI(app));
|
||||
core.registerAPI(new SearchHistoryAPI(app));
|
||||
|
||||
core.registerAPI(new SearchOnlineApi(app));
|
||||
|
||||
refreshCustomPoiFilters();
|
||||
}
|
||||
|
||||
public void refreshCustomPoiFilters() {
|
||||
core.clearCustomSearchPoiFilters();
|
||||
PoiFiltersHelper poiFilters = app.getPoiFilters();
|
||||
for(CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
|
||||
for (CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
|
||||
core.addCustomSearchPoiFilter(udf, 0);
|
||||
}
|
||||
PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
|
||||
|
@ -99,6 +115,45 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
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 {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -107,14 +162,14 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
super(ObjectType.WPT);
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSearchMoreAvailable(SearchPhrase phrase) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||
if (phrase.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -145,7 +200,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType()) {
|
||||
if (!p.isNoSelectedType()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_WPT_API_PRIORITY;
|
||||
|
@ -169,7 +224,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
}
|
||||
|
||||
@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);
|
||||
List<FavoriteGroup> groups = app.getFavorites().getFavoriteGroups();
|
||||
for (FavoriteGroup group : groups) {
|
||||
|
@ -225,7 +280,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
}
|
||||
|
||||
@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();
|
||||
for (FavouritePoint point : favList) {
|
||||
if (!point.isVisible()) {
|
||||
|
@ -259,13 +314,68 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
if (p.isLastWord(ObjectType.FAVORITE_GROUP)) {
|
||||
return SEARCH_FAVORITE_API_PRIORITY;
|
||||
}
|
||||
if(!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
||||
if (!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
||||
return -1;
|
||||
}
|
||||
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 {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -274,14 +384,14 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
super(ObjectType.RECENT_OBJ);
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSearchMoreAvailable(SearchPhrase phrase) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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);
|
||||
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
||||
int p = 0;
|
||||
|
@ -289,7 +399,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
|
@ -306,7 +416,7 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
public int getSearchPriority(SearchPhrase p) {
|
||||
if (!p.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return SEARCH_HISTORY_API_PRIORITY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,12 @@ import android.widget.AdapterView;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
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.OsmAndFormatter;
|
||||
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.SearchResult;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -177,18 +171,18 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
Amenity a = (Amenity) object;
|
||||
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, a));
|
||||
break;
|
||||
case RECENT_OBJ:
|
||||
HistoryEntry entry = (HistoryEntry) object;
|
||||
pointDescription = entry.getName();
|
||||
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) {
|
||||
object = amenity;
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI,
|
||||
OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(amenity));
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, amenity));
|
||||
}
|
||||
} else if (pointDescription.isFavorite()) {
|
||||
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() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
|
|
@ -242,6 +242,8 @@ public class QuickSearchListItem {
|
|||
sb.append(new File(gpx.path).getName());
|
||||
}
|
||||
return sb.toString();
|
||||
case ONLINE_ADDRESS:
|
||||
return app.getString(R.string.shared_string_address);
|
||||
case UNKNOWN_NAME_FILTER:
|
||||
break;
|
||||
}
|
||||
|
@ -287,8 +289,11 @@ public class QuickSearchListItem {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static String getAmenityIconName(Amenity amenity) {
|
||||
public static String getAmenityIconName(OsmandApplication app, Amenity amenity) {
|
||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (st == null) {
|
||||
st = app.getPoiTypes().getPoiTypeByKey(amenity.getSubType());
|
||||
}
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||
return st.getIconKeyName();
|
||||
|
@ -344,7 +349,7 @@ public class QuickSearchListItem {
|
|||
}
|
||||
case POI:
|
||||
Amenity amenity = (Amenity) searchResult.object;
|
||||
String id = getAmenityIconName(amenity);
|
||||
String id = getAmenityIconName(app, amenity);
|
||||
if (id != null) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(id);
|
||||
if (iconId > 0) {
|
||||
|
@ -392,6 +397,9 @@ public class QuickSearchListItem {
|
|||
case WPT:
|
||||
WptPt wpt = (WptPt) searchResult.object;
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue