From 72bb0e9fd482a95335a82d0fcd3c55aff3e7f7ff Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 29 May 2010 10:08:37 +0000 Subject: [PATCH] implement search amenities by type git-svn-id: https://osmand.googlecode.com/svn/trunk@96 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- DataExtractionOSM/src/com/osmand/ToDoConstants.java | 2 -- OsmAnd/src/com/osmand/AmenityIndexRepository.java | 10 +++++++--- OsmAnd/src/com/osmand/ResourceManager.java | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index fcad152ca7..813f71d50a 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -37,8 +37,6 @@ public class ToDoConstants { // 5. Call ResourceManager.close when it is needed // 6. Understand concept of application where to save/restore global setting. // (for example reset navigate to point, reset link map with location). It should be reset after user call exit. - // 7. Implement search amenities by type (!). - // Rewrite search activity in order to limit amenities not to all types. // 8. Introduce activity search by location (unify with existing dialog) // 9. When all features will be ready we can remove show location from context menu diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index 33ee51a9a1..5f00a7f8c5 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -38,9 +38,13 @@ public class AmenityIndexRepository { private final String[] columns = IndexConstants.generateColumnNames(IndexPoiTable.values()); - public List searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, List amenities){ + public List searchAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, AmenityType type, List amenities){ long now = System.currentTimeMillis(); - Cursor query = db.query(IndexPoiTable.getTable(), columns, "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?", + String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"; + if(type != null){ + squery += " AND type = " + AmenityType.valueToString(type); + } + Cursor query = db.query(IndexPoiTable.getTable(), columns, squery, new String[]{Double.toString(bottomLatitude), Double.toString(topLatitude), Double.toString(leftLongitude), Double.toString(rightLongitude)}, null, null, null); if(query.moveToFirst()){ @@ -82,7 +86,7 @@ public class AmenityIndexRepository { cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude); cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); - searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, cachedAmenities); + searchAmenities(cTopLatitude, cLeftLongitude, cBottomLatitude, cRightLongitude, -1, null, cachedAmenities); checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, toFill); } diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 761264af1f..2aff905174 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -187,7 +187,7 @@ public class ResourceManager { 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, amenities); + index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, null, amenities); } } }