diff --git a/OsmAnd/src/com/osmand/PoiFilter.java b/OsmAnd/src/com/osmand/PoiFilter.java index 1d1b98f8c5..69494e723f 100644 --- a/OsmAnd/src/com/osmand/PoiFilter.java +++ b/OsmAnd/src/com/osmand/PoiFilter.java @@ -8,6 +8,7 @@ import java.util.Map; import com.osmand.data.Amenity; import com.osmand.data.AmenityType; import com.osmand.data.index.IndexConstants.IndexPoiTable; +import com.osmand.osm.MapUtils; public class PoiFilter { @@ -21,6 +22,12 @@ public class PoiFilter { private String name; private final boolean isStandardFilter; + private final static int finalZoom = 8; + private final static int initialZoom = 13; + private final static int maxCount = 200; + private int zoom = initialZoom; + + // constructor for standard filters public PoiFilter(AmenityType type){ isStandardFilter = true; @@ -48,23 +55,38 @@ public class PoiFilter { public boolean isSearchFurtherAvailable(){ - return false; + return zoom > finalZoom; } - public List searchFurther(){ - return null; + public List searchFurther(double latitude, double longitude){ + zoom --; + List amenityList = ResourceManager.getResourceManager().searchAmenities(this, latitude, longitude, zoom, -1); + MapUtils.sortListOfMapObject(amenityList, latitude, longitude); + + return amenityList; } public String getSearchArea(){ - return null; + if(zoom <= 15){ + int d = (int) (1.5 * (1 << (zoom - 15))); + return " < " + d + " km"; + } else { + return " < 500 m"; + } } - public List getLastSearchedResults(){ - return null; - } - - public List initializeNewSearch(double lat, double lon){ - return null; + public List initializeNewSearch(double lat, double lon, int firstTimeLimit){ + zoom = initialZoom; + if(areAllTypesAccepted()){ + zoom += 2; + } + List amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, maxCount); + MapUtils.sortListOfMapObject(amenityList, lat, lon); + while (amenityList.size() > firstTimeLimit) { + amenityList.remove(amenityList.size() - 1); + } + + return amenityList; } public String getName(){ @@ -90,6 +112,18 @@ public class PoiFilter { return acceptedTypes.get(type) == null; } + public boolean areAllTypesAccepted(){ + if(AmenityType.values().length == acceptedTypes.size()){ + for(AmenityType a : acceptedTypes.keySet()){ + if(acceptedTypes.get(a) != null){ + return false; + } + } + return true; + } + return false; + } + public void setTypeToAccept(AmenityType type, boolean accept){ if(accept){ @@ -100,17 +134,8 @@ public class PoiFilter { } public String buildSqlWhereFilter(){ - if(AmenityType.values().length == acceptedTypes.size()){ - boolean wildcard = true; - for(AmenityType a : acceptedTypes.keySet()){ - if(acceptedTypes.get(a) != null){ - wildcard = false; - break; - } - } - if(wildcard){ - return null; - } + if(areAllTypesAccepted()){ + return null; } if(acceptedTypes.size() == 0){ return "1 > 1"; diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 5a499f7ac0..96c15fa4ea 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -1,7 +1,9 @@ package com.osmand; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import com.osmand.data.AmenityType; @@ -28,11 +30,35 @@ public class PoiFiltersHelper { return null; } + public static List getUserDefinedDefaultFilters(Context ctx){ + List filters = new ArrayList(); + Map> types = new LinkedHashMap>(); + + List list = new ArrayList(); + list.add("fuel"); + list.add("car_wash"); + list.add("car_repair"); + types.put(AmenityType.TRANSPORTATION, list); + + list = new ArrayList(); + list.add("car"); + types.put(AmenityType.SHOP, list); + + filters.add(new PoiFilter("Car aid", null, types)); + types.clear(); + + + + return filters; + } + private static List cacheUserDefinedFilters; public static List getUserDefinedPoiFilters(Context ctx){ if(cacheUserDefinedFilters == null){ cacheUserDefinedFilters = new ArrayList(); + // TODO + cacheUserDefinedFilters.addAll(getUserDefinedDefaultFilters(ctx)); } return cacheUserDefinedFilters; } @@ -41,6 +67,8 @@ public class PoiFiltersHelper { public static List getOsmDefinedPoiFilters(Context ctx){ if(cacheOsmDefinedFilters == null){ cacheOsmDefinedFilters = new ArrayList(); + // for test purposes + cacheOsmDefinedFilters.addAll(getUserDefinedPoiFilters(ctx)); cacheOsmDefinedFilters.add(new PoiFilter(null)); for(AmenityType t : AmenityType.values()){ cacheOsmDefinedFilters.add(new PoiFilter(t)); diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 42309d6fc3..830b818a8b 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -371,9 +371,9 @@ public class ResourceManager { } sleep(750); } catch (InterruptedException e) { - log.error(e); + log.error(e, e); } catch (RuntimeException e){ - log.error(e); + log.error(e, e); } } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index 9aca50905c..d9c9216e18 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -25,7 +25,6 @@ import com.osmand.OsmandSettings; import com.osmand.PoiFilter; import com.osmand.PoiFiltersHelper; import com.osmand.R; -import com.osmand.ResourceManager; import com.osmand.activities.MapActivity; import com.osmand.data.Amenity; import com.osmand.osm.LatLon; @@ -42,10 +41,6 @@ public class SearchPOIActivity extends ListActivity { private List amenityList; private Button searchPOILevel; - private final static int maxCount = 100; - private final static int finalZoom = 8; - private final static int limitOfClosest = 30; - private int zoom = 13; private PoiFilter filter; @@ -61,17 +56,9 @@ public class SearchPOIActivity extends ListActivity { searchPOILevel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - ResourceManager resourceManager = ResourceManager.getResourceManager(); - if (zoom > finalZoom) { - --zoom; - } - amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation - .getLongitude(), zoom, -1); - if (amenityList != null) { - MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); - amenityAdapter.setNewModel(amenityList); - } - searchPOILevel.setEnabled(zoom > finalZoom); + amenityList = filter.searchFurther(lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); + amenityAdapter.setNewModel(amenityList); + searchPOILevel.setEnabled(filter.isSearchFurtherAvailable()); } }); @@ -79,23 +66,11 @@ public class SearchPOIActivity extends ListActivity { Bundle bundle = this.getIntent().getExtras(); String filterId = bundle.getString(AMENITY_FILTER); if (filterId != null) { - ResourceManager resourceManager = ResourceManager.getResourceManager(); lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); filter = PoiFiltersHelper.getFilterById(this, filterId); - amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation - .getLongitude(), zoom, maxCount); - - if (amenityList != null) { - MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); - // TODO filter closest pois - if(filter.isStandardFilter()){ - while (amenityList.size() > limitOfClosest) { - amenityList.remove(amenityList.size() - 1); - } - } - amenityAdapter = new AmenityAdapter(amenityList); - setListAdapter(amenityAdapter); - } + amenityAdapter = new AmenityAdapter(filter.initializeNewSearch(lastKnownMapLocation.getLatitude(), + lastKnownMapLocation.getLongitude(), 40)); + setListAdapter(amenityAdapter); } // ListActivity has a ListView, which you can get with: ListView lv = getListView(); @@ -161,7 +136,8 @@ public class SearchPOIActivity extends ListActivity { } else { icon.setImageResource(R.drawable.closed_poi); } - distanceLabel.setText(" " + dist + " m "); + + distanceLabel.setText(" " + MapUtils.getFormattedDistance(dist)); return (row); } }