From c5edcae2065e06f4f6edad7c7a6f379dcd59afae Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 9 Nov 2016 21:29:18 +0300 Subject: [PATCH] Added search of poi additionals --- .../src/net/osmand/search/SearchUICore.java | 3 + .../osmand/search/core/SearchCoreFactory.java | 67 ++++++++++--------- .../search/QuickSearchDialogFragment.java | 40 ++++++----- .../plus/search/QuickSearchListAdapter.java | 5 +- .../plus/search/QuickSearchListItem.java | 3 + 5 files changed, 69 insertions(+), 49 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/net/osmand/search/SearchUICore.java index cd332dc9fa..f966069372 100644 --- a/OsmAnd-java/src/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/net/osmand/search/SearchUICore.java @@ -7,6 +7,7 @@ import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.LatLon; +import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.search.core.CustomSearchPoiFilter; import net.osmand.search.core.ObjectType; @@ -220,6 +221,8 @@ public class SearchUICore { } return MapUtils.getDistance(r1.location, r2.location) < similarityRadius; } + } else if (r1.object != null && r2.object != null) { + return r1.object == r2.object; } return false; } diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java index fef9f511fc..e5e7926673 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchCoreFactory.java @@ -1,20 +1,7 @@ package net.osmand.search.core; -import gnu.trove.list.array.TIntArrayList; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.TreeSet; +import com.jwetherell.openmap.common.LatLonPoint; +import com.jwetherell.openmap.common.UTMPoint; import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.ResultMatcher; @@ -44,8 +31,20 @@ import net.osmand.util.GeoPointParserUtil; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; import net.osmand.util.MapUtils; -import com.jwetherell.openmap.common.LatLonPoint; -import com.jwetherell.openmap.common.UTMPoint; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import gnu.trove.list.array.TIntArrayList; public class SearchCoreFactory { @@ -533,35 +532,43 @@ public class SearchCoreFactory { categories = types.getCategories(false); } // results.clear(); - TreeMap results = new TreeMap() ; + List results = new ArrayList() ; NameStringMatcher nm = phrase.getNameStringMatcher(); for (PoiFilter pf : topVisibleFilters) { if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation())) { - results.put(pf.getTranslation(), pf); + results.add(pf); } } if (phrase.isUnknownSearchWordPresent()) { for (PoiCategory c : categories) { - if (!phrase.isUnknownSearchWordPresent() || nm.matches(c.getTranslation())) { - results.put(c.getTranslation(), c); + if (!results.contains(c) && nm.matches(c.getTranslation())) { + results.add(c); } } Iterator> it = translatedNames.entrySet().iterator(); while (it.hasNext()) { Entry e = it.next(); - if (e.getValue().getCategory() != types.getOtherMapCategory() - && (nm.matches(e.getKey()) || nm.matches(e.getValue().getTranslation()))) { - results.put(e.getValue().getTranslation(), e.getValue()); + PoiType pt = e.getValue(); + if (pt.getCategory() != types.getOtherMapCategory()) { + if (!results.contains(pt) && (nm.matches(e.getKey()) || nm.matches(pt.getTranslation()))) { + results.add(pt); + } + List additionals = pt.getPoiAdditionals(); + if (additionals != null) { + for (PoiType a : additionals) { + if (!a.isReference() && !results.contains(a) && (nm.matches(a.getKeyName()) || nm.matches(a.getTranslation()))) { + results.add(a); + } + } + } } } } - Iterator> it = results.entrySet().iterator(); - while(it.hasNext()) { - Entry p = it.next(); + for (AbstractPoiType pt : results) { SearchResult res = new SearchResult(phrase); - res.localeName = p.getKey(); - res.object = p.getValue(); - res.priority = SEARCH_AMENITY_TYPE_PRIORITY; + res.localeName = pt.getTranslation(); + res.object = pt; + res.priority = SEARCH_AMENITY_TYPE_PRIORITY + (pt instanceof PoiCategory ? 0.0 : 0.1); res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; resultMatcher.publish(res); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 38cdae5d12..295ce39454 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -36,6 +36,7 @@ import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; + import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ResultMatcher; @@ -43,6 +44,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.GPXUtilities; @@ -611,16 +613,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } public void show() { - paused = false; if (useMapCenter) { LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon(); SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation( new LatLon(mapCenter.getLatitude(), mapCenter.getLongitude())); searchUICore.updateSettings(ss); updateUseMapCenterUI(); - forceUpdateLocationUI(mapCenter, null); + updateLocationUI(mapCenter, null); } getDialog().show(); + paused = false; hidden = false; if (interruptedSearch) { interruptedSearch = false; @@ -1142,6 +1144,26 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } public void completeQueryWithObject(SearchResult sr) { + if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) { + PoiType additional = (PoiType) sr.object; + AbstractPoiType parent = additional.getParentType(); + if (parent != null) { + PoiUIFilter custom = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + parent.getKeyName()); + if (custom != null) { + custom.clearFilter(); + custom.updateTypesToAccept(parent); + custom.setFilterByName(additional.getKeyName().replace('_', ':').toLowerCase()); + + SearchPhrase phrase = searchUICore.getPhrase(); + sr = new SearchResult(phrase); + sr.localeName = custom.getName(); + sr.object = custom; + sr.priority = SEARCH_AMENITY_TYPE_PRIORITY; + sr.priorityDistance = 0; + sr.objectType = ObjectType.POI_TYPE; + } + } + } searchUICore.selectSearchResult(sr); String txt = searchUICore.getPhrase().getText(true); searchQuery = txt; @@ -1326,20 +1348,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } - private void forceUpdateLocationUI(LatLon latLon, Float heading) { - if (latLon != null) { - if (mainSearchFragment != null) { - mainSearchFragment.updateLocation(latLon, heading); - } - if (historySearchFragment != null) { - historySearchFragment.updateLocation(latLon, heading); - } - if (categoriesSearchFragment != null) { - categoriesSearchFragment.updateLocation(latLon, heading); - } - } - } - private void updateUseMapCenterUI() { if (!paused && !cancelPrev) { if (mainSearchFragment != null) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 1480ce9c6c..f745a6f76e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -11,6 +11,7 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; + import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.Amenity; @@ -405,7 +406,6 @@ public class QuickSearchListAdapter extends ArrayAdapter { private void updateDistanceDirection(View view, QuickSearchListItem listItem) { TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); - /* SearchPhrase phrase = listItem.getSearchResult().requiredSearchPhrase; LatLon loc = location; if(phrase != null && useMapCenter) { @@ -414,8 +414,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { loc = ol; } } - */ - DashLocationFragment.updateLocationView(useMapCenter, location, + DashLocationFragment.updateLocationView(useMapCenter, loc, heading, direction, distanceText, listItem.getSearchResult().location.getLatitude(), listItem.getSearchResult().location.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java index 77f3b925b5..1c76f05b9f 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java @@ -266,6 +266,9 @@ public class QuickSearchListItem { ((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue())) { return ((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue(); } + if (abstractPoiType instanceof PoiType && ((PoiType) abstractPoiType).getParentType() != null) { + return getPoiTypeIconName(((PoiType) abstractPoiType).getParentType()); + } return null; }