fix small issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@168 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-17 08:07:39 +00:00
parent 9b6212b5ed
commit 8b8c7928b2
8 changed files with 57 additions and 32 deletions

View file

@ -46,19 +46,23 @@ public class ToDoConstants {
// FUTURE RELEASES // FUTURE RELEASES
// 43. Enable poi filter by name (?) // 43. Enable poi filter by name (?)
// 40. Support simple vector road rendering (require new index file) (?) // 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. (?) // 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 // BUGS Android
// 5. Improvement : Implement caching files existing on FS, implement specific method in RM // 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)
// 6. Improvement postal_code search : replace search city <-> postal_code (show streets for postal_code)
// TODO swing // 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) // Current result : for big file (1 - task 60-80% time, 90% memory)
// 1. Download tiles without using dir tiles (?) // 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 // BUGS Swing

View file

@ -119,10 +119,8 @@ public class DataIndexWriter {
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath()); Connection conn = DriverManager.getConnection("jdbc:sqlite:"+file.getAbsolutePath());
try { try {
Statement stat = conn.createStatement(); 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.generateCreateSQL(IndexCityTable.values()));
stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexCityTable.values())); stat.executeUpdate(IndexConstants.generateCreateIndexSQL(IndexCityTable.values()));
@ -136,13 +134,13 @@ public class DataIndexWriter {
stat.close(); stat.close();
PreparedStatement prepCity = conn.prepareStatement( PreparedStatement prepCity = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexCityTable.getTable(), 6)); IndexConstants.generatePrepareStatementToInsert(IndexCityTable.getTable(), IndexCityTable.values().length));
PreparedStatement prepStreet = conn.prepareStatement( PreparedStatement prepStreet = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexStreetTable.getTable(), 6)); IndexConstants.generatePrepareStatementToInsert(IndexStreetTable.getTable(), IndexStreetTable.values().length));
PreparedStatement prepBuilding = conn.prepareStatement( PreparedStatement prepBuilding = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexBuildingTable.getTable(), 7)); IndexConstants.generatePrepareStatementToInsert(IndexBuildingTable.getTable(), IndexBuildingTable.values().length));
PreparedStatement prepStreetNode = conn.prepareStatement( PreparedStatement prepStreetNode = conn.prepareStatement(
IndexConstants.generatePrepareStatementToInsert(IndexStreetNodeTable.getTable(), 5)); IndexConstants.generatePrepareStatementToInsert(IndexStreetNodeTable.getTable(), IndexStreetNodeTable.values().length));
Map<PreparedStatement, Integer> count = new HashMap<PreparedStatement, Integer>(); Map<PreparedStatement, Integer> count = new HashMap<PreparedStatement, Integer>();
count.put(prepStreet, 0); count.put(prepStreet, 0);
count.put(prepCity, 0); count.put(prepCity, 0);
@ -155,6 +153,7 @@ public class DataIndexWriter {
if(city.getId() == null || city.getLocation() == null){ if(city.getId() == null || city.getLocation() == null){
continue; continue;
} }
assert IndexCityTable.values().length == 6;
prepCity.setLong(IndexCityTable.ID.ordinal() + 1, city.getId()); prepCity.setLong(IndexCityTable.ID.ordinal() + 1, city.getId());
prepCity.setDouble(IndexCityTable.LATITUDE.ordinal() + 1, city.getLocation().getLatitude()); prepCity.setDouble(IndexCityTable.LATITUDE.ordinal() + 1, city.getLocation().getLatitude());
prepCity.setDouble(IndexCityTable.LONGITUDE.ordinal() + 1, city.getLocation().getLongitude()); 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())); prepCity.setString(IndexCityTable.CITY_TYPE.ordinal() + 1, CityType.valueToString(city.getType()));
addBatch(count, prepCity); addBatch(count, prepCity);
for(Street street : city.getStreets()){ for(Street street : city.getStreets()){
if(street.getId() == null || street.getLocation() == null){ if(street.getId() == null || street.getLocation() == null){
continue; continue;
} }
assert IndexStreetTable.values().length == 6;
prepStreet.setLong(IndexStreetTable.ID.ordinal() + 1, street.getId()); prepStreet.setLong(IndexStreetTable.ID.ordinal() + 1, street.getId());
prepStreet.setString(IndexStreetTable.NAME_EN.ordinal() + 1, street.getEnName()); prepStreet.setString(IndexStreetTable.NAME_EN.ordinal() + 1, street.getEnName());
prepStreet.setDouble(IndexStreetTable.LATITUDE.ordinal() + 1, street.getLocation().getLatitude()); prepStreet.setDouble(IndexStreetTable.LATITUDE.ordinal() + 1, street.getLocation().getLatitude());
@ -179,6 +180,7 @@ public class DataIndexWriter {
if(n == null){ if(n == null){
continue; continue;
} }
assert IndexStreetNodeTable.values().length == 5;
prepStreetNode.setLong(IndexStreetNodeTable.ID.ordinal() + 1, n.getId()); prepStreetNode.setLong(IndexStreetNodeTable.ID.ordinal() + 1, n.getId());
prepStreetNode.setDouble(IndexStreetNodeTable.LATITUDE.ordinal() + 1, n.getLatitude()); prepStreetNode.setDouble(IndexStreetNodeTable.LATITUDE.ordinal() + 1, n.getLatitude());
prepStreetNode.setDouble(IndexStreetNodeTable.LONGITUDE.ordinal() + 1, n.getLongitude()); prepStreetNode.setDouble(IndexStreetNodeTable.LONGITUDE.ordinal() + 1, n.getLongitude());
@ -193,6 +195,7 @@ public class DataIndexWriter {
if(building.getId() == null || building.getLocation() == null){ if(building.getId() == null || building.getLocation() == null){
continue; continue;
} }
assert IndexBuildingTable.values().length == 7;
prepBuilding.setLong(IndexBuildingTable.ID.ordinal() + 1, building.getId()); prepBuilding.setLong(IndexBuildingTable.ID.ordinal() + 1, building.getId());
prepBuilding.setDouble(IndexBuildingTable.LATITUDE.ordinal() + 1, building.getLocation().getLatitude()); prepBuilding.setDouble(IndexBuildingTable.LATITUDE.ordinal() + 1, building.getLocation().getLatitude());
prepBuilding.setDouble(IndexBuildingTable.LONGITUDE.ordinal() + 1, building.getLocation().getLongitude()); prepBuilding.setDouble(IndexBuildingTable.LONGITUDE.ordinal() + 1, building.getLocation().getLongitude());

View file

@ -248,7 +248,7 @@ public class IndexConstants {
} }
public enum IndexBuildingTable implements IndexColumn { 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; boolean index = false;
String type = null; String type = null;

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/list.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">

View file

@ -12,8 +12,9 @@ import com.osmand.osm.MapUtils;
public class PoiFilter { public class PoiFilter {
public static String STD_PREFIX = "std_"; public final static String STD_PREFIX = "std_";
public static String USER_PREFIX = "user_"; public final static String USER_PREFIX = "user_";
public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id";
private Map<AmenityType, List<String>> acceptedTypes = new LinkedHashMap<AmenityType, List<String>>(); private Map<AmenityType, List<String>> acceptedTypes = new LinkedHashMap<AmenityType, List<String>>();
private String filterByName = null; private String filterByName = null;
@ -34,9 +35,7 @@ public class PoiFilter {
filterId = STD_PREFIX + type; filterId = STD_PREFIX + type;
name = type == null ? "Closest poi" : Algoritms.capitalizeFirstLetterAndLowercase(type.name()).replace('_', ' '); name = type == null ? "Closest poi" : Algoritms.capitalizeFirstLetterAndLowercase(type.name()).replace('_', ' ');
if(type == null){ if(type == null){
for(AmenityType t : AmenityType.values()){ initSearchAll();
acceptedTypes.put(t, null);
}
} else { } else {
acceptedTypes.put(type, null); acceptedTypes.put(type, null);
} }
@ -50,8 +49,18 @@ public class PoiFilter {
} }
this.filterId = filterId; this.filterId = filterId;
this.name = name; this.name = name;
if(acceptedTypes == null){
initSearchAll();
} else {
this.acceptedTypes.putAll(acceptedTypes); this.acceptedTypes.putAll(acceptedTypes);
} }
}
private void initSearchAll(){
for(AmenityType t : AmenityType.values()){
acceptedTypes.put(t, null);
}
}
public boolean isSearchFurtherAvailable(){ public boolean isSearchFurtherAvailable(){
@ -185,6 +194,7 @@ public class PoiFilter {
return filterId; return filterId;
} }
public String getFilterByName() { public String getFilterByName() {
return filterByName; return filterByName;
} }

View file

@ -1,6 +1,7 @@
package com.osmand; package com.osmand;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -105,25 +106,25 @@ public class PoiFiltersHelper {
////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME); ////ctx.deleteDatabase(PoiFilterDbHelper.DATABASE_NAME);
cacheUserDefinedFilters = new ArrayList<PoiFilter>(); cacheUserDefinedFilters = new ArrayList<PoiFilter>();
PoiFilter filter = new PoiFilter("Custom filter", PoiFilter.CUSTOM_FILTER_ID, null);
cacheUserDefinedFilters.add(filter);
PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx); PoiFilterDbHelper helper = new PoiFilterDbHelper(ctx);
cacheUserDefinedFilters.addAll(helper.getFilters()); cacheUserDefinedFilters.addAll(helper.getFilters());
helper.close(); helper.close();
} }
return cacheUserDefinedFilters; return Collections.unmodifiableList(cacheUserDefinedFilters);
} }
private static List<PoiFilter> cacheOsmDefinedFilters; private static List<PoiFilter> cacheOsmDefinedFilters;
public static List<PoiFilter> getOsmDefinedPoiFilters(Context ctx){ public static List<PoiFilter> getOsmDefinedPoiFilters(Context ctx){
if(cacheOsmDefinedFilters == null){ if(cacheOsmDefinedFilters == null){
cacheOsmDefinedFilters = new ArrayList<PoiFilter>(); cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
// TODO for test purposes
cacheOsmDefinedFilters.addAll(getUserDefinedPoiFilters(ctx));
cacheOsmDefinedFilters.add(new PoiFilter(null)); cacheOsmDefinedFilters.add(new PoiFilter(null));
for(AmenityType t : AmenityType.values()){ for(AmenityType t : AmenityType.values()){
cacheOsmDefinedFilters.add(new PoiFilter(t)); cacheOsmDefinedFilters.add(new PoiFilter(t));
} }
} }
return cacheOsmDefinedFilters; return Collections.unmodifiableList(cacheOsmDefinedFilters);
} }
public static boolean removePoiFilter(Context ctx, PoiFilter filter){ public static boolean removePoiFilter(Context ctx, PoiFilter filter){

View file

@ -37,6 +37,7 @@ public class RegionAddressRepository {
private SQLiteDatabase db; private SQLiteDatabase db;
private String name; private String name;
private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>(); private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>();
private Map<CityType, List<City>> cityTypes = new HashMap<CityType, List<City>>(); private Map<CityType, List<City>> cityTypes = new HashMap<CityType, List<City>>();
private boolean useEnglishNames = false; private boolean useEnglishNames = false;
@ -199,7 +200,7 @@ public class RegionAddressRepository {
Character.isDigit(name.charAt(0)) && Character.isDigit(name.charAt(0)) &&
Character.isDigit(name.charAt(1))) { Character.isDigit(name.charAt(1))) {
// also try to identify postcodes // also try to identify postcodes
for (String code:c.getPostcodes()) { for (String code : c.getPostcodes()) {
code = code.toLowerCase(); code = code.toLowerCase();
if (code.startsWith(name)) { if (code.startsWith(name)) {
streetsToFill.add(ind++,new PostcodeBasedStreet(c, code)); streetsToFill.add(ind++,new PostcodeBasedStreet(c, code));
@ -335,11 +336,7 @@ public class RegionAddressRepository {
query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = postcode", query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = postcode",
new String[] { street.getName().toUpperCase()}, null, null, null); new String[] { street.getName().toUpperCase()}, null, null, null);
} else { } else {
IndexBuildingTable[] columns = IndexBuildingTable.values(); query = db.query(IndexBuildingTable.getTable(), IndexConstants.generateColumnNames(IndexBuildingTable.values()), "? = street",
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",
new String[] { street.getId() + "" }, null, null, null); new String[] { street.getId() + "" }, null, null, null);
} }
log.debug("Start loading buildings for " + street.getName()); log.debug("Start loading buildings for " + street.getName());

View file

@ -3,10 +3,12 @@
*/ */
package com.osmand.activities.search; package com.osmand.activities.search;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import android.app.ListActivity; import android.app.ListActivity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -28,12 +30,18 @@ import com.osmand.R;
public class SearchPoiFilterActivity extends ListActivity { public class SearchPoiFilterActivity extends ListActivity {
private Typeface typeFace;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
setContentView(R.layout.searchpoilist); setContentView(R.layout.searchpoilist);
List<PoiFilter> filters = PoiFiltersHelper.getOsmDefinedPoiFilters(this);
List<PoiFilter> filters = new ArrayList<PoiFilter>(PoiFiltersHelper.getUserDefinedPoiFilters(this)) ;
filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this));
setListAdapter(new AmenityAdapter(filters)); 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); ImageView icon = (ImageView) row.findViewById(R.id.folder_icon);
PoiFilter model = getItem(position); PoiFilter model = getItem(position);
label.setText(model.getName()); 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); return (row);
} }