From 3096a83555a2121b3d110beebca030a04eb17f2d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 12 Jun 2010 12:27:50 +0000 Subject: [PATCH] fixing some issues with filter git-svn-id: https://osmand.googlecode.com/svn/trunk@156 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 10 +- OsmAnd/res/layout/search_address.xml | 2 + OsmAnd/res/layout/searchpoi.xml | 8 +- OsmAnd/res/values/strings.xml | 1 + .../com/osmand/AmenityIndexRepository.java | 16 ++-- OsmAnd/src/com/osmand/PoiFilter.java | 8 +- OsmAnd/src/com/osmand/PoiFiltersHelper.java | 44 ++++++++- OsmAnd/src/com/osmand/ResourceManager.java | 26 +++--- .../osmand/activities/FavouritesActivity.java | 30 +++--- .../activities/NavigatePointActivity.java | 45 +++++---- .../search/SearchAddressActivity.java | 92 +++++++++++-------- .../activities/search/SearchPOIActivity.java | 21 +++-- OsmAnd/src/com/osmand/views/POIMapLayer.java | 4 +- 13 files changed, 197 insertions(+), 110 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 7daf9dc250..2dc3e9baaf 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -27,12 +27,12 @@ public class ToDoConstants { // 31. Translation. // 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others) // ( 1) predefined filters, 2) choose subtype's, 3) filter by name, 4) opening hours (filter)) +// [TODO database support] -// 41. POI layer over map (shows poi by selected filter) +// 41. POI layer over map (shows poi by selected filter) [TODO] // 8. Enable change POI directly on map (requires OSM login) -// 33. Build transport locations. Create transport index (transport-stops) (investigate) -// 39. Support old-versionned resources (1) odb indexes, 2) favourites table, 3) atomic settings (?)) -// 38. Add button in search "navigate to". +// 33. Build transport locations. Create transport index (transport-stops) (investigate) [TODO] +// 39. Support old-versionned resources (1) odb indexes, 2) favourites table, 3) atomic settings (?)) [TODO] // 42. Revise UI (icons/layouts). Support different devices. Add inactive/focus(!) icon versions. // 36. Postcode search @@ -47,7 +47,6 @@ public class ToDoConstants { // 20. Implement save track/route to gpx (?) // 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) @@ -64,6 +63,7 @@ public class ToDoConstants { // DONE ANDROID : +// 38. Add button in search "navigate to" // 16. Support open street bugs api (supports viewing, deleting). // 13. Save point as favorite & introduce favorite points dialog // 29. Show opened/closed amenities (in search poi). diff --git a/OsmAnd/res/layout/search_address.xml b/OsmAnd/res/layout/search_address.xml index f7f6441873..44173f2dcb 100644 --- a/OsmAnd/res/layout/search_address.xml +++ b/OsmAnd/res/layout/search_address.xml @@ -52,6 +52,8 @@ + diff --git a/OsmAnd/res/layout/searchpoi.xml b/OsmAnd/res/layout/searchpoi.xml index 38e86d6bf4..5fdb0be309 100644 --- a/OsmAnd/res/layout/searchpoi.xml +++ b/OsmAnd/res/layout/searchpoi.xml @@ -3,9 +3,11 @@ - + + + + + - - \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index ef1736f5f0..ca00d1ad02 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,6 @@ + Navigate to Update map Reload tile Input user name to communicate osm diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index 5fc524133c..80e6713acd 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -34,6 +34,7 @@ public class AmenityIndexRepository { private double cBottomLatitude; private double cLeftLongitude; private double cRightLongitude; + private int cZoom; private String cFilterId; @@ -86,15 +87,16 @@ public class AmenityIndexRepository { cRightLongitude = 0; cLeftLongitude = 0; cFilterId = null; + cZoom = 0; } - public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int limit, PoiFilter filter, List toFill){ - cachedAmenities.clear(); + public void evaluateCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, int limit, PoiFilter filter, List toFill){ cTopLatitude = topLatitude + (topLatitude -bottomLatitude); cBottomLatitude = bottomLatitude - (topLatitude -bottomLatitude); cLeftLongitude = leftLongitude - (rightLongitude - leftLongitude); cRightLongitude = rightLongitude + (rightLongitude - leftLongitude); cFilterId = filter == null? null :filter.getFilterId(); + cZoom = zoom; // 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, limit, filter, tempList); @@ -103,15 +105,15 @@ public class AmenityIndexRepository { cachedAmenities.addAll(tempList); } - checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), toFill); + checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, cZoom, filter.getFilterId(), toFill); } - public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, String filterId, List toFill, boolean fillFound){ + public synchronized boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, String filterId, List toFill, boolean fillFound){ if (db == null) { return true; } boolean inside = cTopLatitude >= topLatitude && cLeftLongitude <= leftLongitude && cRightLongitude >= rightLongitude - && cBottomLatitude <= bottomLatitude; + && cBottomLatitude <= bottomLatitude && zoom == cZoom; if((inside || fillFound) && toFill != null && Algoritms.objectEquals(filterId, cFilterId)){ for(Amenity a : cachedAmenities){ LatLon location = a.getLocation(); @@ -123,8 +125,8 @@ public class AmenityIndexRepository { } return inside; } - 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 boolean checkCachedAmenities(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, String filterId, List toFill){ + return checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, 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 69494e723f..4e85ee85f0 100644 --- a/OsmAnd/src/com/osmand/PoiFilter.java +++ b/OsmAnd/src/com/osmand/PoiFilter.java @@ -22,7 +22,7 @@ public class PoiFilter { private String name; private final boolean isStandardFilter; - private final static int finalZoom = 8; + private final static int finalZoom = 6; private final static int initialZoom = 13; private final static int maxCount = 200; private int zoom = initialZoom; @@ -67,8 +67,8 @@ public class PoiFilter { } public String getSearchArea(){ - if(zoom <= 15){ - int d = (int) (1.5 * (1 << (zoom - 15))); + if(zoom <= 14){ + int d = (int) (1 * (1 << (14 - zoom))); return " < " + d + " km"; } else { return " < 500 m"; @@ -78,7 +78,7 @@ public class PoiFilter { public List initializeNewSearch(double lat, double lon, int firstTimeLimit){ zoom = initialZoom; if(areAllTypesAccepted()){ - zoom += 2; + zoom += 1; } List amenityList = ResourceManager.getResourceManager().searchAmenities(this, lat, lon, zoom, maxCount); MapUtils.sortListOfMapObject(amenityList, lat, lon); diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 5b580146eb..932abe4d04 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -42,15 +42,55 @@ public class PoiFiltersHelper { list.add("car_wash"); list.add("car_repair"); types.put(AmenityType.TRANSPORTATION, list); - list = new ArrayList(); list.add("car"); + list.add("car_repair"); types.put(AmenityType.SHOP, list); - filters.add(new PoiFilter("Car aid", null, types)); types.clear(); + types.put(AmenityType.HISTORIC, null); + types.put(AmenityType.TOURISM, null); + list = new ArrayList(); + list.add("internet_access"); + list.add("bench"); + list.add("embassy"); + list.add("emergency_phone"); + list.add("marketplace"); + list.add("post_office"); + list.add("recycling"); + list.add("telephone"); + list.add("toilets"); + list.add("waste_basket"); + list.add("waste_disposal"); + types.put(AmenityType.OTHER, list); + filters.add(new PoiFilter("For tourists", null, types)); + types.clear(); + + list = new ArrayList(); + list.add("fuel"); + types.put(AmenityType.TRANSPORTATION, list); + filters.add(new PoiFilter("Fuel", null, types)); + types.clear(); + + list = new ArrayList(); + list.add("alcohol"); + list.add("bakery"); + list.add("beverages"); + list.add("butcher"); + list.add("convenience"); + list.add("department_store"); + list.add("convenience"); + list.add("farm"); + list.add("general"); + list.add("ice_cream"); + list.add("kiosk"); + list.add("supermarket"); + list.add("variety_store"); + types.put(AmenityType.SHOP, list); + filters.add(new PoiFilter("Food shop", null, types)); + types.clear(); return filters; } diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 2b5e43cabc..85b662e0fd 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -207,16 +207,16 @@ public class ResourceManager { // //////////////////////////////////////////// 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); - double bottomLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY + 1); - double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX); - double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 1); + double tileNumberX = MapUtils.getTileNumberX(zoom, longitude); + double tileNumberY = MapUtils.getTileNumberY(zoom, latitude); + double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY - 0.5); + double bottomLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY + 0.5); + double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX - 0.5); + double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 0.5); List amenities = new ArrayList(); for (AmenityIndexRepository index : amenityRepositories) { if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { - if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter.getFilterId(), amenities)) { + if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filter.getFilterId(), amenities)) { index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, filter, amenities); } } @@ -225,13 +225,13 @@ public class ResourceManager { return amenities; } - public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, PoiFilter filter, List toFill){ + public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, 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, filterId, toFill, true)){ + if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filterId, toFill, true)){ asyncLoadingTiles.requestToLoadAmenities( - new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter)); + new AmenityLoadRequest(index, topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filter)); } } } @@ -318,15 +318,17 @@ public class ResourceManager { public final double leftLongitude; public final double rightLongitude; public final PoiFilter filter; + public final int zoom; public AmenityLoadRequest(AmenityIndexRepository repository, double topLatitude, double leftLongitude, - double bottomLatitude, double rightLongitude, PoiFilter filter) { + double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter) { super(); this.bottomLatitude = bottomLatitude; this.leftLongitude = leftLongitude; this.repository = repository; this.rightLongitude = rightLongitude; this.topLatitude = topLatitude; + this.zoom = zoom; this.filter = filter; } @@ -359,7 +361,7 @@ public class ResourceManager { if(!amenityLoaded){ AmenityLoadRequest r = (AmenityLoadRequest) req; r.repository.evaluateCachedAmenities(r.topLatitude, r.leftLongitude, - r.bottomLatitude, r.rightLongitude, POIMapLayer.LIMIT_POI, r.filter, null); + r.bottomLatitude, r.rightLongitude, r.zoom, POIMapLayer.LIMIT_POI, r.filter, null); amenityLoaded = true; } } diff --git a/OsmAnd/src/com/osmand/activities/FavouritesActivity.java b/OsmAnd/src/com/osmand/activities/FavouritesActivity.java index b632d43655..09da16859b 100644 --- a/OsmAnd/src/com/osmand/activities/FavouritesActivity.java +++ b/OsmAnd/src/com/osmand/activities/FavouritesActivity.java @@ -12,7 +12,6 @@ import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -42,8 +41,10 @@ import com.osmand.osm.MapUtils; */ public class FavouritesActivity extends ListActivity { - public static final int DELETE_ITEM = 0; - public static final int EDIT_ITEM = 1; + public static final int NAVIGATE_TO = 0; + public static final int DELETE_ITEM = 1; + public static final int EDIT_ITEM = 2; + private List favouritesList; private FavouritesDbHelper helper; @@ -67,28 +68,31 @@ public class FavouritesActivity extends ListActivity { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.setHeaderTitle("Context menu"); - menu.add(0, EDIT_ITEM, 0, "Edit favourite"); - menu.add(0, DELETE_ITEM, 1, "Delete favourite"); + menu.add(0, NAVIGATE_TO, 0, "Navigate to"); + menu.add(0, EDIT_ITEM, 1, "Edit favourite"); + menu.add(0, DELETE_ITEM, 2, "Delete favourite"); } }); } public void onListItemClick(ListView parent, View v, int position, long id) { - SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); - if (prefs != null) { - FavouritePoint point = favouritesList.get(position); - OsmandSettings.setMapLocationToShow(this, point.getLatitude(), point.getLongitude()); - Intent newIntent = new Intent(FavouritesActivity.this, MapActivity.class); - startActivity(newIntent); - } + FavouritePoint point = favouritesList.get(position); + OsmandSettings.setMapLocationToShow(this, point.getLatitude(), point.getLongitude()); + Intent newIntent = new Intent(FavouritesActivity.this, MapActivity.class); + startActivity(newIntent); } @Override public boolean onContextItemSelected(MenuItem aItem) { AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) aItem.getMenuInfo(); final FavouritePoint point = (FavouritePoint) favouritesList.get(menuInfo.position); - if(aItem.getItemId() == EDIT_ITEM){ + if(aItem.getItemId() == NAVIGATE_TO){ + OsmandSettings.setMapLocationToShow(this, point.getLatitude(), point.getLongitude()); + OsmandSettings.setPointToNavigate(this, point.getLatitude(), point.getLongitude()); + Intent newIntent = new Intent(FavouritesActivity.this, MapActivity.class); + startActivity(newIntent); + } else if(aItem.getItemId() == EDIT_ITEM){ Builder builder = new AlertDialog.Builder(this); builder.setTitle("Input new name of favourite point"); final EditText editText = new EditText(this); diff --git a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java index e8a65d9708..99a037c040 100644 --- a/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java +++ b/OsmAnd/src/com/osmand/activities/NavigatePointActivity.java @@ -50,7 +50,7 @@ public class NavigatePointActivity extends Activity { setContentView(R.layout.navigate_point); setTitle("Navigate to point"); initUI(loc.getLatitude(), loc.getLongitude()); - ((Button) findViewById(R.id.Cancel)).setVisibility(View.INVISIBLE); + ((Button) findViewById(R.id.Cancel)).setText(getString(R.string.navigate_to)); } @Override @@ -101,31 +101,42 @@ public class NavigatePointActivity extends Activity { ((Button) findViewById(R.id.Cancel)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - close(); + if(dlg == null){ + showOnMap(true); + } else { + close(); + } } }); ((Button) findViewById(R.id.ShowOnMap)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - try { - // TODO there is a bug in that convert if min = 59.23 or sec = 59.32 or deg=179.3 - double lat = Location.convert(((TextView) findViewById(R.id.LatitudeEdit)).getText().toString()); - double lon = Location.convert(((TextView) findViewById(R.id.LongitudeEdit)).getText().toString()); - // in case when it is dialog - if(activity != null) { - activity.setMapLocation(lat, lon); - } else { - OsmandSettings.setMapLocationToShow(NavigatePointActivity.this, lat, lon); - } - close(); - } catch (RuntimeException e) { - ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); - Log.w(LogUtil.TAG, "Convertion failed", e); - } + showOnMap(false); } }); } + public void showOnMap(boolean navigate){ + try { + // TODO there is a bug in android implementation : doesn't convert if min = 59.23 or sec = 59.32 or deg=179.3 + double lat = Location.convert(((TextView) findViewById(R.id.LatitudeEdit)).getText().toString()); + double lon = Location.convert(((TextView) findViewById(R.id.LongitudeEdit)).getText().toString()); + // in case when it is dialog + if(activity != null) { + activity.setMapLocation(lat, lon); + } else { + OsmandSettings.setMapLocationToShow(this, lat, lon); + } + if(navigate){ + OsmandSettings.setPointToNavigate(this, lat, lon); + } + close(); + } catch (RuntimeException e) { + ((TextView) findViewById(R.id.ValidateTextView)).setText("Locations are invalid"); + Log.w(LogUtil.TAG, "Convertion failed", e); + } + } + // THIS code is copied from Location.convert() in order to change locale public static final int FORMAT_DEGREES = 0; diff --git a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java index bdc535eea8..8cb0f5efa3 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java @@ -31,6 +31,7 @@ public class SearchAddressActivity extends Activity { private Button cityButton; private Button countryButton; private Button buildingButton; + private Button navigateTo; private RegionAddressRepository region = null; private City city = null; @@ -38,6 +39,7 @@ public class SearchAddressActivity extends Activity { private Building building = null; private Street street2 = null; private boolean radioBuilding = true; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -46,6 +48,7 @@ public class SearchAddressActivity extends Activity { setContentView(R.layout.search_address); showOnMap = (Button) findViewById(R.id.ShowOnMap); + navigateTo = (Button) findViewById(R.id.NavigateTo); streetButton = (Button) findViewById(R.id.StreetButton); cityButton = (Button) findViewById(R.id.CityButton); countryButton = (Button) findViewById(R.id.CountryButton); @@ -84,47 +87,16 @@ public class SearchAddressActivity extends Activity { } } }); + navigateTo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showOnMap(true); + } + }); showOnMap.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - LatLon l = null; - int zoom = 12; - if (street2 != null && street != null) { - region.preloadWayNodes(street2); - region.preloadWayNodes(street); - Node inters = null; - for(Way w : street2.getWayNodes()){ - for(Way w2 : street.getWayNodes()){ - for(Node n : w.getNodes()){ - for(Node n2 : w2.getNodes()){ - if(n.getId() == n2.getId()){ - inters = n; - break; - } - } - } - } - } - if(inters != null){ - l = inters.getLatLon(); - zoom = 16; - } - } else if (building != null) { - l = building.getLocation(); - zoom = 16; - } else if (street != null) { - l = street.getLocation(); - zoom = 14; - } else if (city != null) { - l = city.getLocation(); - zoom = 12; - } - if (l != null) { - OsmandSettings.setMapLocationToShow(SearchAddressActivity.this, l.getLatitude(), l.getLongitude()); - OsmandSettings.setLastKnownMapZoom(SearchAddressActivity.this, zoom); - startActivity(new Intent(SearchAddressActivity.this, MapActivity.class)); - } - + showOnMap(false); } }); findViewById(R.id.ResetBuilding).setOnClickListener(new View.OnClickListener(){ @@ -180,6 +152,50 @@ public class SearchAddressActivity extends Activity { }); } + public void showOnMap(boolean navigateTo){ + LatLon l = null; + int zoom = 12; + if (street2 != null && street != null) { + region.preloadWayNodes(street2); + region.preloadWayNodes(street); + Node inters = null; + for(Way w : street2.getWayNodes()){ + for(Way w2 : street.getWayNodes()){ + for(Node n : w.getNodes()){ + for(Node n2 : w2.getNodes()){ + if(n.getId() == n2.getId()){ + inters = n; + break; + } + } + } + } + } + if(inters != null){ + l = inters.getLatLon(); + zoom = 16; + } + } else if (building != null) { + l = building.getLocation(); + zoom = 16; + } else if (street != null) { + l = street.getLocation(); + zoom = 14; + } else if (city != null) { + l = city.getLocation(); + zoom = 12; + } + if (l != null) { + if(navigateTo){ + OsmandSettings.setPointToNavigate(SearchAddressActivity.this, l.getLatitude(), l.getLongitude()); + } + OsmandSettings.setMapLocationToShow(SearchAddressActivity.this, l.getLatitude(), l.getLongitude()); + OsmandSettings.setLastKnownMapZoom(SearchAddressActivity.this, zoom); + + startActivity(new Intent(SearchAddressActivity.this, MapActivity.class)); + } + } + protected void updateBuildingSection(){ if(radioBuilding){ ((TextView)findViewById(R.id.BuildingText)).setText("Building"); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index 19cd055404..e7066bcc15 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -36,23 +36,26 @@ import com.osmand.osm.MapUtils; */ public class SearchPOIActivity extends ListActivity { - public static final String AMENITY_FILTER = "amenity_filter"; + public static final String AMENITY_FILTER = "com.osmand.amenity_filter"; private Button searchPOILevel; private PoiFilter filter; private AmenityAdapter amenityAdapter; private LatLon lastKnownMapLocation; + private TextView searchArea; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.searchpoi); searchPOILevel = (Button) findViewById(R.id.SearchPOILevelButton); + searchArea = (TextView) findViewById(R.id.SearchAreaText); searchPOILevel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { amenityAdapter.setNewModel(filter.searchFurther(lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); + searchArea.setText(filter.getSearchArea()); searchPOILevel.setEnabled(filter.isSearchFurtherAvailable()); } @@ -60,13 +63,15 @@ public class SearchPOIActivity extends ListActivity { Bundle bundle = this.getIntent().getExtras(); String filterId = bundle.getString(AMENITY_FILTER); - if (filterId != null) { - lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); - filter = PoiFiltersHelper.getFilterById(this, filterId); - amenityAdapter = new AmenityAdapter(filter.initializeNewSearch(lastKnownMapLocation.getLatitude(), - lastKnownMapLocation.getLongitude(), 40)); + lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); + filter = PoiFiltersHelper.getFilterById(this, filterId); + if (filter != null) { + amenityAdapter = new AmenityAdapter(filter.initializeNewSearch(lastKnownMapLocation.getLatitude(), lastKnownMapLocation + .getLongitude(), 40)); setListAdapter(amenityAdapter); + searchArea.setText(filter.getSearchArea()); } + // ListActivity has a ListView, which you can get with: ListView lv = getListView(); @@ -74,7 +79,7 @@ public class SearchPOIActivity extends ListActivity { lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView av, View v, int pos, long id) { - Amenity amenity = ((AmenityAdapter)getListAdapter()).getItem(pos); + Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(pos); String format = amenity.getSimpleFormat(OsmandSettings.usingEnglishNames(v.getContext())); if (amenity.getOpeningHours() != null) { format += "\nOpening hours : " + amenity.getOpeningHours(); @@ -85,6 +90,8 @@ public class SearchPOIActivity extends ListActivity { }); } + + public void onListItemClick(ListView parent, View v, int position, long id) { SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); if (prefs != null) { diff --git a/OsmAnd/src/com/osmand/views/POIMapLayer.java b/OsmAnd/src/com/osmand/views/POIMapLayer.java index f0ed1cd4b9..5d3d83af6f 100644 --- a/OsmAnd/src/com/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/com/osmand/views/POIMapLayer.java @@ -20,7 +20,7 @@ import com.osmand.osm.MapUtils; public class POIMapLayer implements OsmandMapLayer { // it is very slow to use with 15 level private static final int startZoom = 10; - public static final int LIMIT_POI = 100; + public static final int LIMIT_POI = 200; private Paint pointAltUI; @@ -117,7 +117,7 @@ public class POIMapLayer implements OsmandMapLayer { double rightLongitude = MapUtils.getLongitudeFromTile(view.getZoom(), tileRect.right); objects.clear(); - resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, filter, objects); + resourceManager.searchAmenitiesAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude, view.getZoom(), filter, objects); for (Amenity o : objects) { int x = view.getMapXForPoint(o.getLocation().getLongitude()); int y = view.getMapYForPoint(o.getLocation().getLatitude());