Update poi types

This commit is contained in:
Victor Shcherb 2015-04-03 13:33:55 +02:00
parent cfaac85523
commit 7e51abfe95
3 changed files with 68 additions and 68 deletions

View file

@ -25,6 +25,7 @@ public class MapPoiTypes {
static final String OSM_WIKI_CATEGORY = "osmwiki"; static final String OSM_WIKI_CATEGORY = "osmwiki";
private PoiTranslator poiTranslator = null; private PoiTranslator poiTranslator = null;
private boolean init;
public MapPoiTypes(String fileName){ public MapPoiTypes(String fileName){
this.resourceName = fileName; this.resourceName = fileName;
@ -51,6 +52,9 @@ public class MapPoiTypes {
return DEFAULT_INSTANCE; return DEFAULT_INSTANCE;
} }
public boolean isInit() {
return init;
}
public PoiCategory getOtherPoiCategory() { public PoiCategory getOtherPoiCategory() {
return otherCategory; return otherCategory;
@ -185,6 +189,7 @@ public class MapPoiTypes {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
findDefaultOtherCategory(); findDefaultOtherCategory();
init = true;
} }
private void findDefaultOtherCategory() { private void findDefaultOtherCategory() {

View file

@ -3,7 +3,7 @@
android:id="@+id/loading" android:id="@+id/loading"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top|end" android:layout_gravity="top|start"
android:gravity="end" android:gravity="end"
android:paddingTop="5dp" android:paddingTop="5dp"
android:orientation="horizontal"> android:orientation="horizontal">

View file

@ -33,7 +33,6 @@ public class PoiFiltersHelper {
private static final String UDF_SIGHTSEEING = "sightseeing"; private static final String UDF_SIGHTSEEING = "sightseeing";
private static final String UDF_EMERGENCY = "emergency"; private static final String UDF_EMERGENCY = "emergency";
private static final String UDF_PUBLIC_TRANSPORT = "public_transport"; private static final String UDF_PUBLIC_TRANSPORT = "public_transport";
private static final String UDF_ENTERTAINMENT = "entertainment";
private static final String UDF_ACCOMMODATION = "accomodation"; private static final String UDF_ACCOMMODATION = "accomodation";
private static final String UDF_RESTAURANTS = "restaurants"; private static final String UDF_RESTAURANTS = "restaurants";
private static final String UDF_PARKING = "parking"; private static final String UDF_PARKING = "parking";
@ -74,74 +73,68 @@ public class PoiFiltersHelper {
} }
public MapPoiTypes getPoiTypes() { private void putAll(MapPoiTypes poiTypes, Map<PoiCategory, LinkedHashSet<String>> types, String tp) {
return application.getPoiTypes(); types.put(poiTypes.getPoiCategoryByName(tp), null);
} }
private void putAll(Map<PoiCategory, LinkedHashSet<String>> types, String tp) { private void putValues(MapPoiTypes poiTypes, Map<PoiCategory, LinkedHashSet<String>> types, String p, String... vls) {
types.put(getPoiTypes().getPoiCategoryByName(tp), null);
}
private void putValues(Map<PoiCategory, LinkedHashSet<String>> types, String p, String... vls) {
LinkedHashSet<String> list = new LinkedHashSet<String>(); LinkedHashSet<String> list = new LinkedHashSet<String>();
Collections.addAll(list, vls); Collections.addAll(list, vls);
types.put(getPoiTypes().getPoiCategoryByName(p), list); PoiCategory pc = poiTypes.getPoiCategoryByName(p);
if(pc == null) {
throw new NullPointerException("Category " + p + " was not found");
}
types.put(poiTypes.getPoiCategoryByName(p), list);
} }
private List<PoiLegacyFilter> getUserDefinedDefaultFilters() { private List<PoiLegacyFilter> getUserDefinedDefaultFilters(MapPoiTypes poiTypes) {
List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>(); List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>();
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_accomodation), PoiLegacyFilter.USER_PREFIX + UDF_ACCOMMODATION, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_accomodation), PoiLegacyFilter.USER_PREFIX + UDF_ACCOMMODATION,
configureDefaultUserDefinedFilter(null, UDF_ACCOMMODATION), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_ACCOMMODATION), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_car_aid), PoiLegacyFilter.USER_PREFIX + UDF_CAR_AID, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_car_aid), PoiLegacyFilter.USER_PREFIX + UDF_CAR_AID,
configureDefaultUserDefinedFilter(null, UDF_CAR_AID), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_CAR_AID), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_food_shop), PoiLegacyFilter.USER_PREFIX + UDF_FOOD_SHOP, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_food_shop), PoiLegacyFilter.USER_PREFIX + UDF_FOOD_SHOP,
configureDefaultUserDefinedFilter(null, UDF_FOOD_SHOP), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_FOOD_SHOP), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_for_tourists), PoiLegacyFilter.USER_PREFIX + UDF_FOR_TOURISTS, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_for_tourists), PoiLegacyFilter.USER_PREFIX + UDF_FOR_TOURISTS,
configureDefaultUserDefinedFilter(null, UDF_FOR_TOURISTS), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_FOR_TOURISTS), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_fuel), PoiLegacyFilter.USER_PREFIX + UDF_FUEL, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_fuel), PoiLegacyFilter.USER_PREFIX + UDF_FUEL,
configureDefaultUserDefinedFilter(null, UDF_FUEL), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_FUEL), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_parking), PoiLegacyFilter.USER_PREFIX + UDF_PARKING, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_parking), PoiLegacyFilter.USER_PREFIX + UDF_PARKING,
configureDefaultUserDefinedFilter(null, UDF_PARKING), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_PARKING), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_public_transport), filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_public_transport),
PoiLegacyFilter.USER_PREFIX + UDF_PUBLIC_TRANSPORT, configureDefaultUserDefinedFilter(null, UDF_PUBLIC_TRANSPORT), application)); PoiLegacyFilter.USER_PREFIX + UDF_PUBLIC_TRANSPORT, configureDefaultUserDefinedFilter(poiTypes, UDF_PUBLIC_TRANSPORT), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_restaurants), PoiLegacyFilter.USER_PREFIX + UDF_RESTAURANTS, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_restaurants), PoiLegacyFilter.USER_PREFIX + UDF_RESTAURANTS,
configureDefaultUserDefinedFilter(null, UDF_RESTAURANTS), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_RESTAURANTS), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_sightseeing), PoiLegacyFilter.USER_PREFIX + UDF_SIGHTSEEING, filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_sightseeing), PoiLegacyFilter.USER_PREFIX + UDF_SIGHTSEEING,
configureDefaultUserDefinedFilter(null, UDF_SIGHTSEEING), application)); configureDefaultUserDefinedFilter(poiTypes, UDF_SIGHTSEEING), application));
// UDF_EMERGENCY = "emergency"; // UDF_EMERGENCY = "emergency";
// UDF_ENTERTAINMENT = "entertainment"; // UDF_ENTERTAINMENT = "entertainment";
return filters; return filters;
} }
private Map<PoiCategory, LinkedHashSet<String>> configureDefaultUserDefinedFilter(Map<PoiCategory, LinkedHashSet<String>> types, String key) { private Map<PoiCategory, LinkedHashSet<String>> configureDefaultUserDefinedFilter(MapPoiTypes poiTypes, String key) {
if(types == null) { Map<PoiCategory, LinkedHashSet<String>> types = new LinkedHashMap<PoiCategory, LinkedHashSet<String>>();
types = new LinkedHashMap<PoiCategory, LinkedHashSet<String>>();
}
if(UDF_ACCOMMODATION.equals(key)){ if(UDF_ACCOMMODATION.equals(key)){
putValues(types, "tourism", "camp_site", putValues(poiTypes, types, "tourism", "camp_site",
"caravan_site","picnic_site","alpine_hut", "chalet","guest_house", "caravan_site","picnic_site","alpine_hut", "chalet","guest_house",
"hostel", "hotel","motel"); "hostel", "hotel","motel");
} else if (UDF_CAR_AID.equals(key)) { } else if (UDF_CAR_AID.equals(key)) {
putValues(types, "transportation", "fuel", "car_wash", "car_repair","car", "car_sharing"); putValues(poiTypes, types, "transportation", "fuel", "car_wash", "car_repair","car", "car_sharing");
putValues(types, "shop", "fuel", "car_wash", "car_repair","car", "car_parts"); putValues(poiTypes, types, "shop", "fuel", "car_wash", "car_repair","car", "car_parts");
} else if (UDF_FOOD_SHOP.equals(key)) { } else if (UDF_FOOD_SHOP.equals(key)) {
putValues(types, "shop", "alcohol", "bakery", "beverages", "butcher", "convenience", "department_store", putValues(poiTypes, types, "shop", "alcohol", "bakery", "beverages", "butcher", "convenience", "department_store",
"convenience", "farm", "general", "ice_cream", "kiosk", "seafood", "supermarket", "variety_store"); "convenience", "farm", "general", "ice_cream", "kiosk", "seafood", "supermarket", "variety_store");
} else if(UDF_FOR_TOURISTS.equals(key)){ } else if(UDF_FOR_TOURISTS.equals(key)){
putAll(types, "historic"); putAll(poiTypes, types, "tourism");
putAll(types, "tourism"); putAll(poiTypes, types, "finance");
putAll(types, "finance"); putAll(poiTypes, types, "osmwiki");
putAll(types, "osmwiki");
putValues(types, "other", "place_of_worship", "internet_access_wlan", "internet_access_wired",
"internet_access_terminal", "internet_access_public", "internet_access_service",
"embassy", "marketplace", "post_office", "telephone", "toilets", "emergency_phone");
} else if(UDF_FUEL.equals(key)){ } else if(UDF_FUEL.equals(key)){
putValues(types, "transportation", "fuel"); putValues(poiTypes, types, "transportation", "fuel");
} else if (UDF_PARKING.equals(key)) { } else if (UDF_PARKING.equals(key)) {
putValues(types, "transportation", "parking", putValues(poiTypes, types, "transportation", "parking",
"bicycle_parking"); "bicycle_parking");
} else if (UDF_PUBLIC_TRANSPORT.equals(key)) { } else if (UDF_PUBLIC_TRANSPORT.equals(key)) {
putValues(types, "transportation", "public_transport_stop_position", "public_transport_platform", putValues(poiTypes, types, "transportation", "public_transport_stop_position", "public_transport_platform",
"public_transport_station", "public_transport_station",
// railway // railway
"railway_platform", "railway_station", "halt", "tram_stop", "subway_entrance", "railway_buffer_stop", "railway_platform", "railway_station", "halt", "tram_stop", "subway_entrance", "railway_buffer_stop",
@ -156,19 +149,16 @@ public class PoiFiltersHelper {
// "rail", "tram", "light_rail", "subway", "railway_narrow_gauge", "railway_monorail", "railway_funicular" // "rail", "tram", "light_rail", "subway", "railway_narrow_gauge", "railway_monorail", "railway_funicular"
); );
} else if (UDF_RESTAURANTS.equals(key)) { } else if (UDF_RESTAURANTS.equals(key)) {
putValues(types, "sustenance", "restaurant", putValues(poiTypes, types, "sustenance", "restaurant",
"cafe", "food_court", "fast_food", "pub", "bar", "biergarten"); "cafe", "food_court", "pub", "bar", "biergarten");
} else if (UDF_SIGHTSEEING.equals(key)) { } else if (UDF_SIGHTSEEING.equals(key)) {
putAll(types, "historic"); // TODO filter only sightseeing from tourimsm
putValues(types, "tourism", "attraction", // putValues(types, "tourism", "...","...");
"artwork","zoo","theme_park", "museum","viewpoint"); putAll(poiTypes, types, "tourism");
putAll(types, "osmwiki"); putAll(poiTypes, types, "osmwiki");
putValues(types, "other", "place_of_worship");
} else if (UDF_EMERGENCY.equals(key)) { } else if (UDF_EMERGENCY.equals(key)) {
putAll(types, "healthcare"); putAll(poiTypes, types, "healthcare");
putAll(types, "emergency"); putAll(poiTypes, types, "emergency");
} else if (UDF_ENTERTAINMENT.equals(key)) {
putAll(types, "entertainment");
} }
return types; return types;
} }
@ -188,11 +178,13 @@ public class PoiFiltersHelper {
if(cacheUserDefinedFilters == null){ if(cacheUserDefinedFilters == null){
cacheUserDefinedFilters = new ArrayList<PoiLegacyFilter>(); cacheUserDefinedFilters = new ArrayList<PoiLegacyFilter>();
PoiFilterDbHelper helper = openDbHelper(); PoiFilterDbHelper helper = openDbHelper();
if (helper != null) {
List<PoiLegacyFilter> userDefined = helper.getFilters(helper.getReadableDatabase()); List<PoiLegacyFilter> userDefined = helper.getFilters(helper.getReadableDatabase());
sortListOfFiltersByName(userDefined); sortListOfFiltersByName(userDefined);
cacheUserDefinedFilters.addAll(userDefined); cacheUserDefinedFilters.addAll(userDefined);
helper.close(); helper.close();
} }
}
return Collections.unmodifiableList(cacheUserDefinedFilters); return Collections.unmodifiableList(cacheUserDefinedFilters);
} }
private void sortListOfFiltersByName(List<PoiLegacyFilter> userDefined) { private void sortListOfFiltersByName(List<PoiLegacyFilter> userDefined) {
@ -229,15 +221,18 @@ public class PoiFiltersHelper {
public void updateFilters(boolean onlyAddFilters){ public void updateFilters(boolean onlyAddFilters){
PoiFilterDbHelper helper = openDbHelper(); PoiFilterDbHelper helper = openDbHelper();
if(helper != null ) {
helper.upgradeFilters(helper.getWritableDatabase(), onlyAddFilters); helper.upgradeFilters(helper.getWritableDatabase(), onlyAddFilters);
helper.close(); helper.close();
} }
}
public List<PoiLegacyFilter> getOsmDefinedPoiFilters(){ public List<PoiLegacyFilter> getOsmDefinedPoiFilters(){
if(cacheOsmDefinedFilters == null){ if(cacheOsmDefinedFilters == null){
cacheOsmDefinedFilters = new ArrayList<PoiLegacyFilter>(); cacheOsmDefinedFilters = new ArrayList<PoiLegacyFilter>();
for(PoiCategory t : getPoiTypes().getCategories()){ MapPoiTypes poiTypes = application.getPoiTypes();
for(PoiCategory t : poiTypes.getCategories()){
cacheOsmDefinedFilters.add(new PoiLegacyFilter(t, application)); cacheOsmDefinedFilters.add(new PoiLegacyFilter(t, application));
} }
final Collator instance = Collator.getInstance(); final Collator instance = Collator.getInstance();
@ -252,7 +247,10 @@ public class PoiFiltersHelper {
} }
private PoiFilterDbHelper openDbHelper(){ private PoiFilterDbHelper openDbHelper(){
return new PoiFilterDbHelper(application); if(!application.getPoiTypes().isInit()) {
return null;
}
return new PoiFilterDbHelper(application.getPoiTypes(), application);
} }
public boolean removePoiFilter(PoiLegacyFilter filter){ public boolean removePoiFilter(PoiLegacyFilter filter){
@ -324,8 +322,10 @@ public class PoiFiltersHelper {
CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + ", " + CATEGORIES_COL_SUBCATEGORY + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + ", " + CATEGORIES_COL_SUBCATEGORY + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private OsmandApplication context; private OsmandApplication context;
private SQLiteConnection conn; private SQLiteConnection conn;
private MapPoiTypes mapPoiTypes;
PoiFilterDbHelper(OsmandApplication context) { PoiFilterDbHelper(MapPoiTypes mapPoiTypes, OsmandApplication context) {
this.mapPoiTypes = mapPoiTypes;
this.context = context; this.context = context;
} }
@ -369,8 +369,8 @@ public class PoiFiltersHelper {
} }
public void upgradeFilters(SQLiteConnection conn, boolean onlyAdd) { public void upgradeFilters(SQLiteConnection conn, boolean onlyAdd) {
List<PoiLegacyFilter> filters = PoiFilterDbHelper.this.getFilters(conn); List<PoiLegacyFilter> filters = PoiFilterDbHelper.this.getFilters( conn);
List<PoiLegacyFilter> def = getUserDefinedDefaultFilters(); List<PoiLegacyFilter> def = getUserDefinedDefaultFilters(mapPoiTypes);
for(PoiLegacyFilter f : filters){ for(PoiLegacyFilter f : filters){
PoiLegacyFilter std = null; PoiLegacyFilter std = null;
for(PoiLegacyFilter d : def){ for(PoiLegacyFilter d : def){
@ -399,12 +399,7 @@ public class PoiFiltersHelper {
} }
public void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) { public void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) {
// if (newVersion == 2 || newVersion == 3) { upgradeFilters(conn, false);
// upgradeFilters(conn, false);
// } else {
// from version 4 (upgrade)
upgradeFilters(conn, true);
// }
conn.setVersion(newVersion); conn.setVersion(newVersion);
} }
@ -449,7 +444,7 @@ public class PoiFiltersHelper {
map.put(filterId, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>()); map.put(filterId, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>());
} }
Map<PoiCategory, LinkedHashSet<String>> m = map.get(filterId); Map<PoiCategory, LinkedHashSet<String>> m = map.get(filterId);
PoiCategory a = getPoiTypes().getPoiCategoryByName(query.getString(1)); PoiCategory a = mapPoiTypes.getPoiCategoryByName(query.getString(1));
String subCategory = query.getString(2); String subCategory = query.getString(2);
if(subCategory == null){ if(subCategory == null){
m.put(a, null); m.put(a, null);