diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index a117fae75b..a6823d5ace 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -46,19 +46,23 @@ public class ToDoConstants { // FUTURE RELEASES -// 43. Enable poi filter by name (?) -// 40. Support simple vector road rendering (require new index file) (?) -// 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. (?) + // 43. Enable poi filter by name (?) + // 40. Support simple vector road rendering (require new index file) (?) + // 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. (?) // 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) + // 6. Improvement postal_code search : replace search city <-> postal_code (show streets for postal_code) // TODO swing - // 4. Fix issues with big files (such as netherlands) - save memory (!) + // 4. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index ! // Current result : for big file (1 - task 60-80% time, 90% memory) // 1. Download tiles without using dir tiles (?) + // 5. Improve address indexing (use relations). + // Use relation "postal_code" to assign postcodes, use relation "a6" (to accumulate streets!), + // "a3" to read all cities & define boundaries for city (& define that street in city). // BUGS Swing diff --git a/DataExtractionOSM/src/com/osmand/data/index/DataIndexWriter.java b/DataExtractionOSM/src/com/osmand/data/index/DataIndexWriter.java index 44ae1202fb..e31c81a9ef 100644 --- a/DataExtractionOSM/src/com/osmand/data/index/DataIndexWriter.java +++ b/DataExtractionOSM/src/com/osmand/data/index/DataIndexWriter.java @@ -119,10 +119,8 @@ public class DataIndexWriter { Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath()); try { Statement stat = conn.createStatement(); - assert IndexCityTable.values().length == 6; - assert IndexBuildingTable.values().length == 6; - assert IndexStreetNodeTable.values().length == 5; - assert IndexStreetTable.values().length == 6; + + stat.executeUpdate(IndexConstants.generateCreateSQL(IndexCityTable.values())); stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexCityTable.values())); @@ -136,13 +134,13 @@ public class DataIndexWriter { stat.close(); PreparedStatement prepCity = conn.prepareStatement( - IndexConstants.generatePrepareStatementToInsert(IndexCityTable.getTable(), 6)); + IndexConstants.generatePrepareStatementToInsert(IndexCityTable.getTable(), IndexCityTable.values().length)); PreparedStatement prepStreet = conn.prepareStatement( - IndexConstants.generatePrepareStatementToInsert(IndexStreetTable.getTable(), 6)); + IndexConstants.generatePrepareStatementToInsert(IndexStreetTable.getTable(), IndexStreetTable.values().length)); PreparedStatement prepBuilding = conn.prepareStatement( - IndexConstants.generatePrepareStatementToInsert(IndexBuildingTable.getTable(), 7)); + IndexConstants.generatePrepareStatementToInsert(IndexBuildingTable.getTable(), IndexBuildingTable.values().length)); PreparedStatement prepStreetNode = conn.prepareStatement( - IndexConstants.generatePrepareStatementToInsert(IndexStreetNodeTable.getTable(), 5)); + IndexConstants.generatePrepareStatementToInsert(IndexStreetNodeTable.getTable(), IndexStreetNodeTable.values().length)); Map count = new HashMap(); count.put(prepStreet, 0); count.put(prepCity, 0); @@ -155,6 +153,7 @@ public class DataIndexWriter { if(city.getId() == null || city.getLocation() == null){ continue; } + assert IndexCityTable.values().length == 6; prepCity.setLong(IndexCityTable.ID.ordinal() + 1, city.getId()); prepCity.setDouble(IndexCityTable.LATITUDE.ordinal() + 1, city.getLocation().getLatitude()); prepCity.setDouble(IndexCityTable.LONGITUDE.ordinal() + 1, city.getLocation().getLongitude()); @@ -163,10 +162,12 @@ public class DataIndexWriter { prepCity.setString(IndexCityTable.CITY_TYPE.ordinal() + 1, CityType.valueToString(city.getType())); addBatch(count, prepCity); + for(Street street : city.getStreets()){ if(street.getId() == null || street.getLocation() == null){ continue; } + assert IndexStreetTable.values().length == 6; prepStreet.setLong(IndexStreetTable.ID.ordinal() + 1, street.getId()); prepStreet.setString(IndexStreetTable.NAME_EN.ordinal() + 1, street.getEnName()); prepStreet.setDouble(IndexStreetTable.LATITUDE.ordinal() + 1, street.getLocation().getLatitude()); @@ -179,6 +180,7 @@ public class DataIndexWriter { if(n == null){ continue; } + assert IndexStreetNodeTable.values().length == 5; prepStreetNode.setLong(IndexStreetNodeTable.ID.ordinal() + 1, n.getId()); prepStreetNode.setDouble(IndexStreetNodeTable.LATITUDE.ordinal() + 1, n.getLatitude()); prepStreetNode.setDouble(IndexStreetNodeTable.LONGITUDE.ordinal() + 1, n.getLongitude()); @@ -193,6 +195,7 @@ public class DataIndexWriter { if(building.getId() == null || building.getLocation() == null){ continue; } + assert IndexBuildingTable.values().length == 7; prepBuilding.setLong(IndexBuildingTable.ID.ordinal() + 1, building.getId()); prepBuilding.setDouble(IndexBuildingTable.LATITUDE.ordinal() + 1, building.getLocation().getLatitude()); prepBuilding.setDouble(IndexBuildingTable.LONGITUDE.ordinal() + 1, building.getLocation().getLongitude()); diff --git a/DataExtractionOSM/src/com/osmand/data/index/IndexConstants.java b/DataExtractionOSM/src/com/osmand/data/index/IndexConstants.java index 00182612d7..85c7e10e5c 100644 --- a/DataExtractionOSM/src/com/osmand/data/index/IndexConstants.java +++ b/DataExtractionOSM/src/com/osmand/data/index/IndexConstants.java @@ -248,7 +248,7 @@ public class IndexConstants { } public enum IndexBuildingTable implements IndexColumn { - ID("long"), LATITUDE("double"), LONGITUDE("double"), NAME, NAME_EN, STREET("long", true), POSTCODE; + ID("long"), LATITUDE("double"), LONGITUDE("double"), NAME, NAME_EN, STREET("long", true), POSTCODE(null, true); boolean index = false; String type = null; diff --git a/OsmAnd/res/layout/searchpoilist.xml b/OsmAnd/res/layout/searchpoilist.xml index 6e09207594..db14d10ae6 100644 --- a/OsmAnd/res/layout/searchpoilist.xml +++ b/OsmAnd/res/layout/searchpoilist.xml @@ -1,5 +1,4 @@ - diff --git a/OsmAnd/src/com/osmand/PoiFilter.java b/OsmAnd/src/com/osmand/PoiFilter.java index 7858655262..96cb2ab917 100644 --- a/OsmAnd/src/com/osmand/PoiFilter.java +++ b/OsmAnd/src/com/osmand/PoiFilter.java @@ -12,8 +12,9 @@ import com.osmand.osm.MapUtils; public class PoiFilter { - public static String STD_PREFIX = "std_"; - public static String USER_PREFIX = "user_"; + public final static String STD_PREFIX = "std_"; + public final static String USER_PREFIX = "user_"; + public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; private Map> acceptedTypes = new LinkedHashMap>(); private String filterByName = null; @@ -34,9 +35,7 @@ public class PoiFilter { filterId = STD_PREFIX + type; name = type == null ? "Closest poi" : Algoritms.capitalizeFirstLetterAndLowercase(type.name()).replace('_', ' '); if(type == null){ - for(AmenityType t : AmenityType.values()){ - acceptedTypes.put(t, null); - } + initSearchAll(); } else { acceptedTypes.put(type, null); } @@ -50,7 +49,17 @@ public class PoiFilter { } this.filterId = filterId; this.name = name; - this.acceptedTypes.putAll(acceptedTypes); + if(acceptedTypes == null){ + initSearchAll(); + } else { + this.acceptedTypes.putAll(acceptedTypes); + } + } + + private void initSearchAll(){ + for(AmenityType t : AmenityType.values()){ + acceptedTypes.put(t, null); + } } @@ -185,6 +194,7 @@ public class PoiFilter { return filterId; } + public String getFilterByName() { return filterByName; } diff --git a/OsmAnd/src/com/osmand/PoiFiltersHelper.java b/OsmAnd/src/com/osmand/PoiFiltersHelper.java index 724b053d3a..a958580c34 100644 --- a/OsmAnd/src/com/osmand/PoiFiltersHelper.java +++ b/OsmAnd/src/com/osmand/PoiFiltersHelper.java @@ -1,6 +1,7 @@ package com.osmand; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -105,25 +106,25 @@ public class PoiFiltersHelper { ////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME); cacheUserDefinedFilters = new ArrayList(); + PoiFilter filter = new PoiFilter("Custom filter", PoiFilter.CUSTOM_FILTER_ID, null); + cacheUserDefinedFilters.add(filter); PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx); cacheUserDefinedFilters.addAll(helper.getFilters()); helper.close(); } - return cacheUserDefinedFilters; + return Collections.unmodifiableList(cacheUserDefinedFilters); } private static List cacheOsmDefinedFilters; public static List getOsmDefinedPoiFilters(Context ctx){ if(cacheOsmDefinedFilters == null){ cacheOsmDefinedFilters = new ArrayList(); - // TODO for test purposes - cacheOsmDefinedFilters.addAll(getUserDefinedPoiFilters(ctx)); cacheOsmDefinedFilters.add(new PoiFilter(null)); for(AmenityType t : AmenityType.values()){ cacheOsmDefinedFilters.add(new PoiFilter(t)); } } - return cacheOsmDefinedFilters; + return Collections.unmodifiableList(cacheOsmDefinedFilters); } public static boolean removePoiFilter(Context ctx, PoiFilter filter){ diff --git a/OsmAnd/src/com/osmand/RegionAddressRepository.java b/OsmAnd/src/com/osmand/RegionAddressRepository.java index 6b655750d4..93b1c32a07 100644 --- a/OsmAnd/src/com/osmand/RegionAddressRepository.java +++ b/OsmAnd/src/com/osmand/RegionAddressRepository.java @@ -37,6 +37,7 @@ public class RegionAddressRepository { private SQLiteDatabase db; private String name; private LinkedHashMap cities = new LinkedHashMap(); + private Map> cityTypes = new HashMap>(); private boolean useEnglishNames = false; @@ -199,7 +200,7 @@ public class RegionAddressRepository { Character.isDigit(name.charAt(0)) && Character.isDigit(name.charAt(1))) { // also try to identify postcodes - for (String code:c.getPostcodes()) { + for (String code : c.getPostcodes()) { code = code.toLowerCase(); if (code.startsWith(name)) { streetsToFill.add(ind++,new PostcodeBasedStreet(c, code)); @@ -335,11 +336,7 @@ public class RegionAddressRepository { query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = postcode", new String[] { street.getName().toUpperCase()}, null, null, null); } else { - IndexBuildingTable[] columns = IndexBuildingTable.values(); - IndexBuildingTable[] columnsWithoutPostcode = new IndexBuildingTable[columns.length-1]; - // we don't need postcode information here - System.arraycopy(columns, 0, columnsWithoutPostcode, 0, columnsWithoutPostcode.length); - query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(columnsWithoutPostcode), "? = street", + query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = street", new String[] { street.getId() + "" }, null, null, null); } log.debug("Start loading buildings for " + street.getName()); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java index b961f52613..cb3d4da774 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPoiFilterActivity.java @@ -3,10 +3,12 @@ */ package com.osmand.activities.search; +import java.util.ArrayList; import java.util.List; import android.app.ListActivity; import android.content.Intent; +import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -28,12 +30,18 @@ import com.osmand.R; public class SearchPoiFilterActivity extends ListActivity { + private Typeface typeFace; + + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.searchpoilist); - List filters = PoiFiltersHelper.getOsmDefinedPoiFilters(this); + + List filters = new ArrayList(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ; + filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this)); setListAdapter(new AmenityAdapter(filters)); + typeFace = Typeface.create((String)null, Typeface.ITALIC); } @@ -61,7 +69,10 @@ public class SearchPoiFilterActivity extends ListActivity { ImageView icon = (ImageView) row.findViewById(R.id.folder_icon); PoiFilter model = getItem(position); label.setText(model.getName()); - icon.setImageResource(R.drawable.folder); + if(model.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){ + label.setTypeface(typeFace); + } + icon.setImageResource(model.isStandardFilter() ? R.drawable.folder : R.drawable.favorites); return (row); }