From 515f610cacf6489030edf9ee616cc6b6d4da44ef Mon Sep 17 00:00:00 2001 From: Taranenko Roman Date: Thu, 9 Oct 2014 20:28:29 +0300 Subject: [PATCH] Added more elements in the predefined list of POI types and fixed issue "Please add natural=tree to POI creation list". Fixed app crash in DownloadIndexesThread. --- .../src/net/osmand/osm/MapRenderingTypes.java | 49 ++++++++++++++++--- .../plus/download/DownloadIndexesThread.java | 32 ++++++------ .../plus/osmedit/EditingPOIActivity.java | 4 +- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index db4d7e6654..0a50522fdd 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -45,6 +45,7 @@ public class MapRenderingTypes { private String resourceName = null; private Map> amenityTypeNameToTagVal = null; private Map amenityNameToType = null; + private Map> amenityAllTypeNameToTagVal = null; protected Map types = null; protected List typeList = new ArrayList(); @@ -133,7 +134,31 @@ public class MapRenderingTypes { } return amenityTypeNameToTagVal; } - + + private Map> getAmenityAllTypeNameToTagVal() { + if (amenityAllTypeNameToTagVal == null) { + Map types = getEncodingRuleTypes(); + amenityAllTypeNameToTagVal = new LinkedHashMap>(); + for(MapRulType type : types.values()){ + if(type.category != null && type.targetTagValue == null) { + if(!amenityAllTypeNameToTagVal.containsKey(type.category)) { + amenityAllTypeNameToTagVal.put(type.category, new TreeMap()); + } + String name = type.getValue(); + if (name != null) { + if (type.poiPrefix != null) { + name = type.poiPrefix + name; + amenityAllTypeNameToTagVal.get(type.category).put(name, type.getTag() + " " + type.getValue()); + } else { + amenityAllTypeNameToTagVal.get(type.category).put(name, type.getTag()); + } + } + } + } + } + return amenityAllTypeNameToTagVal; + } + public Collection> splitTagsIntoDifferentObjects(final Map tags) { // check open sea maps tags boolean split = splitIsNeeded(tags); @@ -234,7 +259,15 @@ public class MapRenderingTypes { } return amenityTypeNameToTagVal.get(t).keySet(); } - + + public Collection getAmenityAllSubCategories(AmenityType t){ + Map> amenityAllTypeNameToTagVal = getAmenityAllTypeNameToTagVal(); + if(!amenityAllTypeNameToTagVal.containsKey(t.getCategoryName())){ + return Collections.emptyList(); + } + return amenityAllTypeNameToTagVal.get(t.getCategoryName()).keySet(); + } + public MapRulType getTypeByInternalId(int id) { return typeList.get(id); } @@ -383,6 +416,7 @@ public class MapRenderingTypes { XmlPullParser parser = PlatformUtil.newXMLPullParser(); int tok; parser.setInput(is, "UTF-8"); + String parentCategory = null; String poiParentCategory = null; String poiParentPrefix = null; String order = null; @@ -390,12 +424,13 @@ public class MapRenderingTypes { if (tok == XmlPullParser.START_TAG) { String name = parser.getName(); if (name.equals("category")) { //$NON-NLS-1$ + parentCategory = parser.getAttributeValue("","name"); poiParentCategory = parser.getAttributeValue("","poi_category"); poiParentPrefix = parser.getAttributeValue("","poi_prefix"); order = parser.getAttributeValue("","order"); parseCategoryFromXml(parser, poiParentCategory, poiParentPrefix); } else if (name.equals("type")) { - parseTypeFromXML(parser, poiParentCategory, poiParentPrefix, order); + parseTypeFromXML(parser, parentCategory, poiParentCategory, poiParentPrefix, order); } else if (name.equals("routing_type")) { parseRouteTagFromXML(parser); } @@ -421,11 +456,11 @@ public class MapRenderingTypes { protected void parseRouteTagFromXML(XmlPullParser parser) { } - protected MapRulType parseTypeFromXML(XmlPullParser parser, String poiParentCategory, String poiParentPrefix, String parentOrder) { - return parseBaseRuleType(parser, poiParentCategory, poiParentPrefix, parentOrder, true); + protected MapRulType parseTypeFromXML(XmlPullParser parser, String parentCategory, String poiParentCategory, String poiParentPrefix, String parentOrder) { + return parseBaseRuleType(parser, parentCategory, poiParentCategory, poiParentPrefix, parentOrder, true); } - protected MapRulType parseBaseRuleType(XmlPullParser parser, String poiParentCategory, String poiParentPrefix, String parentOrder, boolean filterOnlyMap) { + protected MapRulType parseBaseRuleType(XmlPullParser parser, String parentCategory, String poiParentCategory, String poiParentPrefix, String parentOrder, boolean filterOnlyMap) { String tag = lc(parser.getAttributeValue("", "tag")); String value = lc(parser.getAttributeValue("", "value")); String additional = parser.getAttributeValue("", "additional"); @@ -473,6 +508,7 @@ public class MapRenderingTypes { } + rtype.category = parentCategory; if (poiParentCategory != null && poiParentCategory.length() > 0) { rtype.poiCategory = AmenityType.getAndRegisterType(poiParentCategory); rtype.poiSpecified = true; @@ -666,6 +702,7 @@ public class MapRenderingTypes { protected int order = 50; protected Set applyToTagValue = null; + protected String category = null; protected String poiPrefix; protected AmenityType poiCategory; // poi_category was specially removed for one tag/value, to skip unnecessary objects diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 05a05cf045..49b4598d49 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -527,22 +527,24 @@ public class DownloadIndexesThread { private void prepareFilesToUpdate() { List filtered = getCachedIndexFiles(); - itemsToUpdate.clear(); - for (IndexItem item : filtered) { - String sfName = item.getTargetFileName(); - java.text.DateFormat format = uiActivity.getMyApplication().getResourceManager().getDateFormat(); - String date = item.getDate(format); - String indexactivateddate = indexActivatedFileNames.get(sfName); - String indexfilesdate = indexFileNames.get(sfName); - if (date != null && - !date.equals(indexactivateddate) && - !date.equals(indexfilesdate) && - indexActivatedFileNames.containsKey(sfName)) { - itemsToUpdate.add(item); + if (filtered != null) { + itemsToUpdate.clear(); + for (IndexItem item : filtered) { + String sfName = item.getTargetFileName(); + java.text.DateFormat format = uiActivity.getMyApplication().getResourceManager().getDateFormat(); + String date = item.getDate(format); + String indexactivateddate = indexActivatedFileNames.get(sfName); + String indexfilesdate = indexFileNames.get(sfName); + if (date != null && + !date.equals(indexactivateddate) && + !date.equals(indexfilesdate) && + indexActivatedFileNames.containsKey(sfName)) { + itemsToUpdate.add(item); + } + } + if (uiActivity != null){ + uiActivity.updateDownloadList(itemsToUpdate); } - } - if (uiActivity != null){ - uiActivity.updateDownloadList(itemsToUpdate); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java index 88a7e79365..7d49fdae14 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java @@ -506,7 +506,7 @@ public class EditingPOIActivity implements DialogProvider { private void updateSubTypesAdapter(AmenityType t){ - Set subCategories = new LinkedHashSet(MapRenderingTypes.getDefault().getAmenitySubCategories(t)); + Set subCategories = new LinkedHashSet(MapRenderingTypes.getDefault().getAmenityAllSubCategories(t)); for(String s : MapRenderingTypes.getDefault().getAmenityNameToType().keySet()){ if(!subCategories.contains(s)){ subCategories.add(s); @@ -606,7 +606,7 @@ public class EditingPOIActivity implements DialogProvider { case DIALOG_SUB_CATEGORIES: { Builder builder = new AlertDialog.Builder(ctx); final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); - final String[] subCats = MapRenderingTypes.getDefault().getAmenitySubCategories(a.getType()). + final String[] subCats = MapRenderingTypes.getDefault().getAmenityAllSubCategories(a.getType()). toArray(new String[0]); builder.setItems(subCats, new DialogInterface.OnClickListener() { @Override