From c9c2d491ba0c108875b54658fe5c1b3159b43600 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 11 Feb 2012 11:43:27 +0100 Subject: [PATCH] Improved search by name filter now displayed on the map --- .../binary/BinaryMapPoiReaderAdapter.java | 12 ++--- .../plus/AmenityIndexRepositoryBinary.java | 2 +- .../src/net/osmand/plus/OsmandSettings.java | 8 +++- OsmAnd/src/net/osmand/plus/PoiFilter.java | 45 ++++++++++--------- .../plus/activities/MapActivityLayers.java | 2 +- .../activities/search/SearchPOIActivity.java | 2 +- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java index fdbe159eb3..fca9d6c14c 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -433,7 +433,7 @@ public class BinaryMapPoiReaderAdapter { codedIS.seek(offsets[j] + indexOffset); int len = readInt(); int oldLim = codedIS.pushLimit(len); - readPoiData(left31, right31, top31, bottom31, req, req.getSearchResults(), region, skipTiles, zoomToSkip); + readPoiData(left31, right31, top31, bottom31, req, region, skipTiles, zoomToSkip); codedIS.popLimit(oldLim); if(req.isCancelled()){ return; @@ -489,7 +489,7 @@ public class BinaryMapPoiReaderAdapter { } private void readPoiData(int left31, int right31, int top31, int bottom31, - SearchRequest req, List result, PoiRegion region, TLongHashSet toSkip, int zSkip) throws IOException { + SearchRequest req, PoiRegion region, TLongHashSet toSkip, int zSkip) throws IOException { int x = 0; int y = 0; int zoom = 0; @@ -522,15 +522,17 @@ public class BinaryMapPoiReaderAdapter { int yp = (int) MapUtils.getTileNumberY(zSkip, am.getLocation().getLatitude()); long val = (((long) xp) << zSkip) | yp; if (!toSkip.contains(val)) { - toSkip.add(val); - result.add(am); + boolean publish = req.publish(am); + if(publish) { + toSkip.add(val); + } } if(zSkip <= zoom){ codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); return; } } else { - result.add(am); + req.publish(am); } } break; diff --git a/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java index e3e05dfd3e..054697552a 100644 --- a/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/AmenityIndexRepositoryBinary.java @@ -83,7 +83,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { } }; SearchRequest req = BinaryMapIndexReader.buildSearchPoiRequest(sleft, sright, stop, sbottom, zoom, - poiTypeFilter, matcher); + poiTypeFilter, filter == null ? matcher : filter.getResultMatcher(matcher)); try { List result = index.searchPoi(req); amenities.addAll(result); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 6336b80c2b..55aeb1f045 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -443,14 +443,18 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name - public final OsmandPreference DAYNIGHT_MODE = - new EnumIntPreference("daynight_mode", DayNightMode.AUTO, false, DayNightMode.values()) { + public final CommonPreference DAYNIGHT_MODE = + new EnumIntPreference("daynight_mode", DayNightMode.DAY, false, DayNightMode.values()) { @Override protected boolean setValue(SharedPreferences prefs, DayNightMode val) { ctx.getDaynightHelper().setDayNightMode(val); return super.setValue(prefs, val); } }; + { + DAYNIGHT_MODE.setModeDefaultValue(ApplicationMode.CAR, DayNightMode.AUTO); + DAYNIGHT_MODE.setModeDefaultValue(ApplicationMode.BICYCLE, DayNightMode.AUTO); + } // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/PoiFilter.java b/OsmAnd/src/net/osmand/plus/PoiFilter.java index 114754f123..66571e7dec 100644 --- a/OsmAnd/src/net/osmand/plus/PoiFilter.java +++ b/OsmAnd/src/net/osmand/plus/PoiFilter.java @@ -73,7 +73,7 @@ public class PoiFilter { if(nameFilter != null) { this.nameFilter = nameFilter.toLowerCase(); } else { - clearFilter(); + clearNameFilter(); } } @@ -145,29 +145,32 @@ public class PoiFilter { return searchAmenities(lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, matcher); } + + public ResultMatcher getResultMatcher(final ResultMatcher matcher){ + if(nameFilter != null) { + final boolean en = OsmandSettings.getOsmandSettings(application).USE_ENGLISH_NAMES.get(); + return new ResultMatcher() { + @Override + public boolean publish(Amenity object) { + if(!OsmAndFormatter.getPoiStringWithoutType(object, en).toLowerCase().contains(nameFilter) || + (matcher != null && !matcher.publish(object))) { + return false; + } + return true; + } + + @Override + public boolean isCancelled() { + return false || (matcher != null && matcher.isCancelled()); + } + }; + } + return matcher; + } protected List searchAmenities(double lat, double lon, double topLatitude, double bottomLatitude, double leftLongitude, double rightLongitude, final ResultMatcher matcher) { - if(nameFilter != null) { - final boolean en = OsmandSettings.getOsmandSettings(application).USE_ENGLISH_NAMES.get(); - application.getResourceManager().searchAmenities(this, - topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, new ResultMatcher() { - - @Override - public boolean publish(Amenity object) { - if(!OsmAndFormatter.getPoiStringWithoutType(object, en).toLowerCase().contains(nameFilter) || - (matcher != null && !matcher.publish(object))) { - return false; - } - return true; - } - - @Override - public boolean isCancelled() { - return false || (matcher != null && matcher.isCancelled()); - } - }); - } + return application.getResourceManager().searchAmenities(this, topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, matcher); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 617384aaea..0ceef59309 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -569,7 +569,7 @@ public class MapActivityLayers { getApplication().getSettings().setPoiFilterForMap(filterId); PoiFilter f = poiFilters.getFilterById(filterId); if(f != null){ - f.clearFilter(); + f.clearNameFilter(); } poiMapLayer.setFilter(f); mapView.refreshMap(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index e970d9429c..50df504d2b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -252,7 +252,7 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen clearSearchQuery(); } if(filter != null) { - filter.clearFilter(); + filter.clearNameFilter(); } if(isNameFinderFilter()){