diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 057d2164d5..7daf9dc250 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -49,7 +49,10 @@ public class ToDoConstants { // BUGS Android // 5. Improvement : Implement caching files existing on FS, implement specific method in RM - // Introducing cache of file names that are on disk (creating new File() consumes a lot of memory) + // Introducing cache of file names that are on disk (creating new File() consumes a lot of memory) + + // BUGS Swing + // 1. Bug renaming region // TODO swing diff --git a/DataExtractionOSM/src/com/osmand/data/Amenity.java b/DataExtractionOSM/src/com/osmand/data/Amenity.java index b3b1031457..0281e5df91 100644 --- a/DataExtractionOSM/src/com/osmand/data/Amenity.java +++ b/DataExtractionOSM/src/com/osmand/data/Amenity.java @@ -1,6 +1,5 @@ package com.osmand.data; -import com.osmand.Algoritms; import com.osmand.osm.Entity; import com.osmand.osm.OSMSettings.OSMTagKey; @@ -98,8 +97,7 @@ public class Amenity extends MapObject { public String getSimpleFormat(boolean en){ - return Algoritms.capitalizeFirstLetterAndLowercase(getType().toString()) + - " : " + getStringWithoutType(en); + return AmenityType.toPublicString(type) + " : " + getStringWithoutType(en); } public String getStringWithoutType(boolean en){ diff --git a/DataExtractionOSM/src/com/osmand/data/AmenityType.java b/DataExtractionOSM/src/com/osmand/data/AmenityType.java index 8b34eba2ff..e0fd10fd41 100644 --- a/DataExtractionOSM/src/com/osmand/data/AmenityType.java +++ b/DataExtractionOSM/src/com/osmand/data/AmenityType.java @@ -5,6 +5,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import com.osmand.Algoritms; + // http://wiki.openstreetmap.org/wiki/Amenity // POI tags : amenity, leisure, shop, sport, tourism, historic; accessories (internet-access), natural ? public enum AmenityType { @@ -23,7 +25,11 @@ public enum AmenityType { ; public static AmenityType fromString(String s){ - return AmenityType.valueOf(s.toUpperCase()); + try { + return AmenityType.valueOf(s.toUpperCase()); + } catch (IllegalArgumentException e) { + return AmenityType.OTHER; + } } public static String valueToString(AmenityType t){ @@ -44,6 +50,10 @@ public enum AmenityType { return list; } + public static String toPublicString(AmenityType t){ + return Algoritms.capitalizeFirstLetterAndLowercase(t.toString().replace('_', ' ')); + } + protected static Map amenityMap = new LinkedHashMap(); static { diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 463414223c..c69a29be66 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -17,7 +17,7 @@ - + diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index f86e20dd9a..bc36ca4b57 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -34,15 +34,20 @@ public class AmenityIndexRepository { private double cBottomLatitude; private double cLeftLongitude; private double cRightLongitude; + private String cFilterId; private final String[] columns = IndexConstants.generateColumnNames(IndexPoiTable.values()); - public List searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, AmenityType type, List amenities){ + public List searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List amenities){ long now = System.currentTimeMillis(); String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"; - if(type != null){ - squery += " AND type = " + "'" +AmenityType.valueToString(type)+ "'"; + + if(filter != null){ + String sql = filter.buildSqlWhereFilter(); + if(sql != null){ + squery += " AND " + sql; + } } Cursor query = db.query(IndexPoiTable.getTable(), columns, squery, new String[]{Double.toString(bottomLatitude), @@ -80,32 +85,34 @@ public class AmenityIndexRepository { cBottomLatitude = 0; cRightLongitude = 0; cLeftLongitude = 0; + cFilterId = null; } - public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List toFill){ + public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List toFill){ cachedAmenities.clear(); cTopLatitude = topLatitude + (topLatitude -bottomLatitude); cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude); cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); + cFilterId = filter == null? null :filter.getFilterId(); // first of all put all entities in temp list in order to not freeze other read threads ArrayList tempList = new ArrayList(); - searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, null, tempList); + searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, filter, tempList); synchronized (this) { cachedAmenities.clear(); cachedAmenities.addAll(tempList); } - checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill); + checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), toFill); } - public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List toFill, boolean fillFound){ + public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, String filterId, List toFill, boolean fillFound){ if (db == null) { return true; } boolean inside = cTopLatitude >= topLatitude && cLeftLongitude <= leftLongitude && cRightLongitude >= rightLongitude && cBottomLatitude <= bottomLatitude; - if((inside || fillFound) && toFill != null){ + if((inside || fillFound) && toFill != null && Algoritms.objectEquals(filterId, cFilterId)){ for(Amenity a : cachedAmenities){ LatLon location = a.getLocation(); if (location.getLatitude() <= topLatitude && location.getLongitude() >= leftLongitude && location.getLongitude() <= rightLongitude @@ -116,8 +123,8 @@ public class AmenityIndexRepository { } return inside; } - public boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List toFill){ - return checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill, false); + public boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, String filterId, List toFill){ + return checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filterId, toFill, false); } public void initialize(final IProgress progress, File file) { diff --git a/OsmAnd/src/com/osmand/PoiFilter.java b/OsmAnd/src/com/osmand/PoiFilter.java index 6dd85aa59f..1d1b98f8c5 100644 --- a/OsmAnd/src/com/osmand/PoiFilter.java +++ b/OsmAnd/src/com/osmand/PoiFilter.java @@ -7,6 +7,7 @@ import java.util.Map; import com.osmand.data.Amenity; import com.osmand.data.AmenityType; +import com.osmand.data.index.IndexConstants.IndexPoiTable; public class PoiFilter { @@ -14,6 +15,8 @@ public class PoiFilter { public static String USER_PREFIX = "user_"; private Map> acceptedTypes = new LinkedHashMap>(); + private String filterByName = null; + private String filterId; private String name; private final boolean isStandardFilter; @@ -96,6 +99,56 @@ 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(acceptedTypes.size() == 0){ + return "1 > 1"; + } + StringBuilder b = new StringBuilder(); + b.append("("); + boolean first = true; + for(AmenityType a : acceptedTypes.keySet()){ + if(first){ + first = false; + } else { + b.append(" OR "); + } + b.append("("); + b.append(IndexPoiTable.TYPE.name().toLowerCase()).append(" = '").append(AmenityType.valueToString(a)).append("'"); + if(acceptedTypes.get(a) != null){ + List list = acceptedTypes.get(a); + b.append(" AND "); + b.append(IndexPoiTable.SUBTYPE.name().toLowerCase()).append(" IN ("); + boolean bfirst = true; + for(String s : list){ + if(bfirst){ + bfirst = false; + } else { + b.append(", "); + } + b.append("'").append(s).append("'"); + } + b.append(")"); + } + b.append(")"); + } + + b.append(")"); + return b.toString(); + + } + public void selectSubTypesToAccept(AmenityType t, List accept){ acceptedTypes.put(t, accept); } @@ -104,6 +157,14 @@ public class PoiFilter { return filterId; } + public String getFilterByName() { + return filterByName; + } + + public void setFilterByName(String filterByName) { + this.filterByName = filterByName; + } + public boolean isStandardFilter(){ return isStandardFilter; } diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 6fdeee630b..5a499f7ac0 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -28,7 +28,7 @@ public class PoiFiltersHelper { return null; } - private static List cacheUserDefinedFilters = new ArrayList(); + private static List cacheUserDefinedFilters; public static List getUserDefinedPoiFilters(Context ctx){ if(cacheUserDefinedFilters == null){ cacheUserDefinedFilters = new ArrayList(); @@ -37,7 +37,7 @@ public class PoiFiltersHelper { return cacheUserDefinedFilters; } - private static List cacheOsmDefinedFilters = new ArrayList(); + private static List cacheOsmDefinedFilters; public static List getOsmDefinedPoiFilters(Context ctx){ if(cacheOsmDefinedFilters == null){ cacheOsmDefinedFilters = new ArrayList(); diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 3b34995d53..42309d6fc3 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -17,7 +17,6 @@ import android.graphics.BitmapFactory; import android.os.Environment; import com.osmand.data.Amenity; -import com.osmand.data.AmenityType; import com.osmand.data.index.IndexConstants; import com.osmand.data.preparation.MapTileDownloader; import com.osmand.data.preparation.MapTileDownloader.DownloadRequest; @@ -205,9 +204,8 @@ public class ResourceManager { } } - // //////////////////////////////////////////// Working with amenities - // //////////////////////////////////////////////// - public List searchAmenities(AmenityType type, double latitude, double longitude, int zoom, int limit) { + // //////////////////////////////////////////// Working with amenities //////////////////////////////////////////////// + public List searchAmenities(PoiFilter filter, double latitude, double longitude, int zoom, int limit) { double tileNumberX = Math.floor(MapUtils.getTileNumberX(zoom, longitude)); double tileNumberY = Math.floor(MapUtils.getTileNumberY(zoom, latitude)); double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY); @@ -217,8 +215,8 @@ public class ResourceManager { List amenities = new ArrayList(); for (AmenityIndexRepository index : amenityRepositories) { if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { - if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)) { - index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, type, amenities); + if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), amenities)) { + index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, filter, amenities); } } } @@ -226,12 +224,13 @@ public class ResourceManager { return amenities; } - public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, List toFill){ + public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List toFill){ + String filterId = filter == null ? null : filter.getFilterId(); for(AmenityIndexRepository index : amenityRepositories){ if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){ - if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill, true)){ + if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filterId, toFill, true)){ asyncLoadingTiles.requestToLoadAmenities( - new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude)); + new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter)); } } } @@ -317,15 +316,17 @@ public class ResourceManager { public final double bottomLatitude; public final double leftLongitude; public final double rightLongitude; + public final PoiFilter filter; public AmenityLoadRequest(AmenityIndexRepository repository, double topLatitude, double leftLongitude, - double bottomLatitude, double rightLongitude) { + double bottomLatitude, double rightLongitude, PoiFilter filter) { super(); this.bottomLatitude = bottomLatitude; this.leftLongitude = leftLongitude; this.repository = repository; this.rightLongitude = rightLongitude; this.topLatitude = topLatitude; + this.filter = filter; } @@ -348,21 +349,21 @@ public class ResourceManager { boolean amenityLoaded = false; while(!requests.isEmpty()){ Object req = requests.pop(); - if(req instanceof TileLoadDownloadRequest){ + if (req instanceof TileLoadDownloadRequest) { TileLoadDownloadRequest r = (TileLoadDownloadRequest) req; - if(cacheOfImages.get(r.fileToLoad) == null) { - update |= getRequestedImageTile(r) != null; - } + if (cacheOfImages.get(r.fileToLoad) == null) { + update |= getRequestedImageTile(r) != null; + } } else if(req instanceof AmenityLoadRequest){ if(!amenityLoaded){ AmenityLoadRequest r = (AmenityLoadRequest) req; r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude, - r.bottomLatitude, r.rightLongitude, null); + r.bottomLatitude, r.rightLongitude, r.filter, null); amenityLoaded = true; } } } - if(update){ + if(update || amenityLoaded){ // use downloader callback for(IMapDownloaderCallback c : downloader.getDownloaderCallbacks()){ c.tileDownloaded(null); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index b139b120c4..2ced074e7d 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -23,7 +23,7 @@ public class SearchActivity extends TabActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TabHost host = getTabHost(); - host.addTab(host.newTabSpec("Search_POI").setIndicator("POI").setContent(new Intent(this, SearchPOIListActivity.class))); + host.addTab(host.newTabSpec("Search_POI").setIndicator("POI").setContent(new Intent(this, SearchPoiFilterActivity.class))); host.addTab(host.newTabSpec("Search_Address").setIndicator("Address").setContent(new Intent(this, SearchAddressActivity.class))); host.addTab(host.newTabSpec("Search_Location").setIndicator("Location").setContent(new Intent(this, NavigatePointActivity.class))); } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index 921d03e636..9aca50905c 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -21,13 +21,13 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -import com.osmand.Algoritms; 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.data.AmenityType; import com.osmand.osm.LatLon; import com.osmand.osm.MapUtils; @@ -37,7 +37,7 @@ import com.osmand.osm.MapUtils; */ public class SearchPOIActivity extends ListActivity { - public static final String AMENITY_TYPE = "amenity_type"; + public static final String AMENITY_FILTER = "amenity_filter"; private List amenityList; @@ -47,7 +47,7 @@ public class SearchPOIActivity extends ListActivity { private final static int limitOfClosest = 30; private int zoom = 13; - private AmenityType amenityType; + private PoiFilter filter; private AmenityAdapter amenityAdapter; @@ -65,7 +65,7 @@ public class SearchPOIActivity extends ListActivity { if (zoom > finalZoom) { --zoom; } - amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation + amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation .getLongitude(), zoom, -1); if (amenityList != null) { MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); @@ -77,22 +77,18 @@ public class SearchPOIActivity extends ListActivity { }); Bundle bundle = this.getIntent().getExtras(); - String anemity = bundle.getString(AMENITY_TYPE); - if (anemity != null) { + String filterId = bundle.getString(AMENITY_FILTER); + if (filterId != null) { ResourceManager resourceManager = ResourceManager.getResourceManager(); lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); - amenityType = findAmenityType(anemity); - if (amenityType != null) { - amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation + filter = PoiFiltersHelper.getFilterById(this, filterId); + amenityList = resourceManager.searchAmenities(filter, lastKnownMapLocation.getLatitude(), lastKnownMapLocation .getLongitude(), zoom, maxCount); - } else { - amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation - .getLongitude(), zoom + 2, maxCount); - } if (amenityList != null) { MapUtils.sortListOfMapObject(amenityList, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); - if(amenityType == null){ + // TODO filter closest pois + if(filter.isStandardFilter()){ while (amenityList.size() > limitOfClosest) { amenityList.remove(amenityList.size() - 1); } @@ -129,27 +125,16 @@ public class SearchPOIActivity extends ListActivity { } } - private AmenityType findAmenityType(String string) { - for (AmenityType type : AmenityType.values()) { - if (string.equals(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()))) { - return type; - } - } - return null; - - } - - @SuppressWarnings("unchecked") - class AmenityAdapter extends ArrayAdapter { - AmenityAdapter(Object list) { - super(SearchPOIActivity.this, R.layout.searchpoi_list, (List) list); + class AmenityAdapter extends ArrayAdapter { + AmenityAdapter(List list) { + super(SearchPOIActivity.this, R.layout.searchpoi_list, list); this.setNotifyOnChange(false); } - public void setNewModel(List amenityList) { + public void setNewModel(List amenityList) { setNotifyOnChange(false); ((AmenityAdapter) getListAdapter()).clear(); - for (Object obj : amenityList) { + for (Amenity obj : amenityList) { this.add(obj); } this.notifyDataSetChanged(); @@ -165,29 +150,20 @@ public class SearchPOIActivity extends ListActivity { TextView label = (TextView) row.findViewById(R.id.poi_label); TextView distanceLabel = (TextView) row.findViewById(R.id.poidistance_label); ImageView icon = (ImageView) row.findViewById(R.id.poi_icon); - Object model = getModel(position); - if (model instanceof Amenity) { - Amenity anemity = (Amenity) model; - if (anemity != null) { - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this); - int dist = (int) (MapUtils.getDistance(anemity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation - .getLongitude())); - String str = anemity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this)); - label.setText(str); - if(anemity.getOpeningHours() != null) { - icon.setImageResource(R.drawable.poi); - } else{ - icon.setImageResource(R.drawable.closed_poi); - } - distanceLabel.setText(" " + dist + " m "); - } + Amenity amenity = getItem(position); + LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this); + int dist = (int) (MapUtils.getDistance(amenity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation + .getLongitude())); + String str = amenity.getStringWithoutType(OsmandSettings.usingEnglishNames(SearchPOIActivity.this)); + label.setText(str); + if (amenity.getOpeningHours() != null) { + icon.setImageResource(R.drawable.poi); + } else { + icon.setImageResource(R.drawable.closed_poi); } + distanceLabel.setText(" " + dist + " m "); return (row); } - - private Object getModel(int position) { - return (((AmenityAdapter) getListAdapter()).getItem(position)); - } } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java deleted file mode 100644 index 188725b42c..0000000000 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - */ -package com.osmand.activities.search; - -import java.util.ArrayList; -import java.util.List; - -import android.app.ListActivity; -import android.content.Intent; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; - -import com.osmand.Algoritms; -import com.osmand.R; -import com.osmand.data.AmenityType; - -/** - * @author Maxim Frolov - * - */ -public class SearchPOIListActivity extends ListActivity { - - List amenityList = new ArrayList(); - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - setContentView(R.layout.searchpoilist); - createAmenityTypeList(); - setListAdapter(new AmenityAdapter(amenityList)); - - } - - private void createAmenityTypeList() { - amenityList.add(getResources().getString(R.string.Closest_Amenities)); - for (AmenityType type : AmenityType.values()) { - amenityList.add(Algoritms.capitalizeFirstLetterAndLowercase(type.toString())); - } - - } - - public void onListItemClick(ListView parent, View v, int position, long id) { - AmenityType amenityType = findAmenityType(amenityList.get(position)); - Bundle bundle = new Bundle(); - Intent newIntent = new Intent(SearchPOIListActivity.this, SearchPOIActivity.class); - // folder selected - if (amenityType != null) { - bundle.putString(SearchPOIActivity.AMENITY_TYPE, amenityList.get(position)); - } else { - bundle.putString(SearchPOIActivity.AMENITY_TYPE, "Closest_Amenities"); - } - newIntent.putExtras(bundle); - startActivityForResult(newIntent, 0); - } - - private AmenityType findAmenityType(String string) { - for (AmenityType type : AmenityType.values()) { - if (string.equals(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()))) { - return type; - } - } - return null; - - } - - @SuppressWarnings("unchecked") - class AmenityAdapter extends ArrayAdapter { - AmenityAdapter(Object list) { - super(SearchPOIListActivity.this, R.layout.searchpoi_list, (List) list); - } - - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflater = getLayoutInflater(); - View row = inflater.inflate(R.layout.searchpoifolder_list, parent, false); - TextView label = (TextView) row.findViewById(R.id.folder_label); - ImageView icon = (ImageView) row.findViewById(R.id.folder_icon); - Object model = getModel(position); - label.setText((String) model); - icon.setImageResource(R.drawable.folder); - return (row); - } - - private Object getModel(int position) { - return (((AmenityAdapter) getListAdapter()).getItem(position)); - } - } -} diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java new file mode 100644 index 0000000000..ee0ccdb38e --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java @@ -0,0 +1,67 @@ +/** + * + */ +package com.osmand.activities.search; + +import java.util.List; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.osmand.PoiFilter; +import com.osmand.PoiFiltersHelper; +import com.osmand.R; + +/** + * @author Maxim Frolov + * + */ +public class SearchPoiFilterActivity extends ListActivity { + + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.searchpoilist); + List filters = PoiFiltersHelper.getOsmDefinedPoiFilters(this); + setListAdapter(new AmenityAdapter(filters)); + } + + + public void onListItemClick(ListView parent, View v, int position, long id) { + PoiFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position); + Bundle bundle = new Bundle(); + Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class); + // folder selected + bundle.putString(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId()); + newIntent.putExtras(bundle); + startActivityForResult(newIntent, 0); + } + + + class AmenityAdapter extends ArrayAdapter { + AmenityAdapter(List list) { + super(SearchPoiFilterActivity.this, R.layout.searchpoi_list, list); + } + + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = getLayoutInflater(); + View row = inflater.inflate(R.layout.searchpoifolder_list, parent, false); + TextView label = (TextView) row.findViewById(R.id.folder_label); + ImageView icon = (ImageView) row.findViewById(R.id.folder_icon); + PoiFilter model = getItem(position); + label.setText(model.getName()); + icon.setImageResource(R.drawable.folder); + return (row); + } + + } +} diff --git a/OsmAnd/src/com/osmand/views/POIMapLayer.java b/OsmAnd/src/com/osmand/views/POIMapLayer.java index d844fad82b..ac49b2e010 100644 --- a/OsmAnd/src/com/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/com/osmand/views/POIMapLayer.java @@ -105,7 +105,7 @@ public class POIMapLayer implements OsmandMapLayer { double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right); objects.clear(); - resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, objects); + resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, null, objects); for (Amenity o : objects) { int x = view.getMapXForPoint(o.getLocation().getLongitude()); int y = view.getMapYForPoint(o.getLocation().getLatitude());