From 3717464598054bb2f5109f7d532793b8c9f7c0e1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 18 Feb 2015 23:21:57 +0100 Subject: [PATCH] Implement new poi structure --- .../net/osmand/binary/BinaryInspector.java | 4 +- .../osmand/binary/BinaryMapIndexReader.java | 16 +- .../binary/BinaryMapPoiReaderAdapter.java | 16 +- OsmAnd-java/src/net/osmand/data/Amenity.java | 7 +- .../src/net/osmand/osm/AbstractPoiType.java | 28 +++ .../src/net/osmand/osm/MapPoiTypes.java | 125 ++++++++++++- .../src/net/osmand/osm/MapRenderingTypes.java | 117 +----------- .../src/net/osmand/osm/PoiCategory.java | 38 +++- OsmAnd-java/src/net/osmand/osm/PoiFilter.java | 15 +- OsmAnd-java/src/net/osmand/osm/PoiType.java | 24 +-- .../src/net/osmand/osm/edit/EntityParser.java | 12 +- OsmAnd/res/values/phrases.xml | 24 ++- .../src/net/osmand/plus/OsmAndFormatter.java | 52 +++--- .../net/osmand/plus/OsmandApplication.java | 45 +++-- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 1 - .../src/net/osmand/plus/SpecialPhrases.java | 100 ----------- .../activities/EditPOIFilterActivity.java | 80 +++++---- .../plus/activities/MapActivityLayers.java | 17 +- .../activities/search/GeoIntentActivity.java | 7 +- .../activities/search/SearchPOIActivity.java | 48 +++-- .../plus/helpers/AvoidSpecificRoads.java | 1 - .../osmand/plus/helpers/WaypointHelper.java | 23 +-- .../plus/osmedit/EditingPOIActivity.java | 166 ++++++++++-------- .../plus/osmedit/OpenstreetmapLocalUtil.java | 14 +- .../plus/osmedit/OpenstreetmapPoint.java | 7 +- .../osmand/plus/poi/NameFinderPoiFilter.java | 7 +- .../net/osmand/plus/poi/PoiFiltersHelper.java | 89 +++++----- .../net/osmand/plus/poi/PoiLegacyFilter.java | 90 +++------- .../osmand/plus/poi/SearchByNameFilter.java | 5 +- .../AmenityIndexRepositoryBinary.java | 8 +- .../plus/resources/ResourceManager.java | 6 +- .../net/osmand/plus/views/POIMapLayer.java | 24 +-- 32 files changed, 595 insertions(+), 621 deletions(-) create mode 100644 OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java delete mode 100644 OsmAnd/src/net/osmand/plus/SpecialPhrases.java diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index ccdd05ea2f..05503a4282 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -39,11 +39,11 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; import net.osmand.data.Street; +import net.osmand.osm.PoiCategory; import net.osmand.util.MapUtils; import com.google.protobuf.CodedOutputStream; @@ -841,7 +841,7 @@ public class BinaryInspector { verbose.getZoom(), new SearchPoiTypeFilter() { @Override - public boolean accept(AmenityType type, String subcategory) { + public boolean accept(PoiCategory type, String subcategory) { return true; } diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 4a96ccbe5d..f6e5b11fa7 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -52,7 +52,6 @@ import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapDataBox; import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapEncodingRule; import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapRootLevel; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.LatLon; @@ -60,6 +59,8 @@ import net.osmand.data.MapObject; import net.osmand.data.Street; import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; import net.osmand.osm.edit.Way; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -1240,7 +1241,7 @@ public class BinaryMapIndexReader { return req.getSearchResults(); } - public Map > searchPoiCategoriesByName(String query, Map > map) throws IOException { + public Map > searchPoiCategoriesByName(String query, Map > map) throws IOException { if (query == null || query.length() == 0) { throw new IllegalArgumentException(); } @@ -1249,7 +1250,7 @@ public class BinaryMapIndexReader { poiAdapter.initCategories(poiIndex); for (int i = 0; i < poiIndex.categories.size(); i++) { String cat = poiIndex.categories.get(i); - AmenityType catType = poiIndex.categoriesType.get(i); + PoiCategory catType = poiIndex.categoriesType.get(i); if (CollatorStringMatcher.cmatches(collator, cat, query, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) { map.put(catType, null); } else { @@ -1495,7 +1496,7 @@ public class BinaryMapIndexReader { public static interface SearchPoiTypeFilter { - public boolean accept(AmenityType type, String subcategory); + public boolean accept(PoiCategory type, String subcategory); } @@ -1900,14 +1901,15 @@ public class BinaryMapIndexReader { private static void testSearchOnthePath(BinaryMapIndexReader reader) throws IOException { float radius = 1000; + final MapPoiTypes poiTypes = MapPoiTypes.getDefault(); long now = System.currentTimeMillis(); println("Searching poi on the path..."); final List locations = readGPX(new File( "")); SearchRequest req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() { @Override - public boolean accept(AmenityType type, String subcategory) { - if (type == AmenityType.SHOP && subcategory.contains("super")) { + public boolean accept(PoiCategory type, String subcategory) { + if (type == poiTypes.getPoiCategoryByName("shop") && subcategory.contains("super")) { return true; } return false; @@ -2021,7 +2023,7 @@ public class BinaryMapIndexReader { SearchRequest req = buildSearchPoiRequest(sleft, sright, stop, sbottom, -1, new SearchPoiTypeFilter() { @Override - public boolean accept(AmenityType type, String subcategory) { + public boolean accept(PoiCategory type, String subcategory) { return true; } diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java index fdc8618d02..11c21d8c3d 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -23,6 +23,9 @@ import net.osmand.data.Amenity; import net.osmand.data.Amenity.AmenityRoutePoint; import net.osmand.data.AmenityType; import net.osmand.data.LatLon; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import net.sf.junidecode.Junidecode; @@ -50,7 +53,7 @@ public class BinaryMapPoiReaderAdapter { public static class PoiRegion extends BinaryIndexPart { List categories = new ArrayList(); - List categoriesType = new ArrayList(); + List categoriesType = new ArrayList(); List > subcategories = new ArrayList >(); List subTypes = new ArrayList(); @@ -100,10 +103,13 @@ public class BinaryMapPoiReaderAdapter { private CodedInputStream codedIS; private final BinaryMapIndexReader map; + + private MapPoiTypes poiTypes; protected BinaryMapPoiReaderAdapter(BinaryMapIndexReader map){ this.codedIS = map.codedIS; this.map = map; + this.poiTypes = MapPoiTypes.getDefault(); } private void skipUnknownField(int t) throws IOException { @@ -199,7 +205,7 @@ public class BinaryMapPoiReaderAdapter { case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER : String cat = codedIS.readString().intern(); region.categories.add(cat); - region.categoriesType.add(AmenityType.findOrCreateTypeNoReg(cat)); + region.categoriesType.add(poiTypes.getPoiCategoryByName(cat)); region.subcategories.add(new ArrayList()); break; case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER : @@ -615,7 +621,7 @@ public class BinaryMapPoiReaderAdapter { int x = 0; int y = 0; StringBuilder retValue = new StringBuilder(); - AmenityType amenityType = null; + PoiCategory amenityType = null; LinkedList textTags = null; while(true){ int t = codedIS.readTag(); @@ -688,7 +694,7 @@ public class BinaryMapPoiReaderAdapter { int cat = codedIS.readUInt32(); int subcatId = cat >> SHIFT_BITS_CATEGORY; int catId = cat & CATEGORY_MASK; - AmenityType type = AmenityType.OTHER; + PoiCategory type = poiTypes.getOtherPoiCategory(); String subtype = ""; if (catId < region.categoriesType.size()) { type = region.categoriesType.get(catId); @@ -756,7 +762,7 @@ public class BinaryMapPoiReaderAdapter { // } // break; case OsmandOdb.OsmAndPoiCategories.CATEGORIES_FIELD_NUMBER: - AmenityType type = AmenityType.OTHER; + PoiCategory type = poiTypes.getOtherPoiCategory(); String subcat = ""; int cat = codedIS.readUInt32(); int subcatId = cat >> SHIFT_BITS_CATEGORY; diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index 05496dd475..92be128f99 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; import net.osmand.Location; +import net.osmand.osm.PoiCategory; public class Amenity extends MapObject { @@ -16,7 +17,7 @@ public class Amenity extends MapObject { private static final long serialVersionUID = 132083949926339552L; private String subType; - private AmenityType type; + private PoiCategory type; // duplicate for fast access private String openingHours; private Map additionalInfo; @@ -31,7 +32,7 @@ public class Amenity extends MapObject { public Location pointB; } - public AmenityType getType(){ + public PoiCategory getType(){ return type; } @@ -39,7 +40,7 @@ public class Amenity extends MapObject { return subType; } - public void setType(AmenityType type) { + public void setType(PoiCategory type) { this.type = type; } diff --git a/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java new file mode 100644 index 0000000000..927b4a6060 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java @@ -0,0 +1,28 @@ +package net.osmand.osm; + +public class AbstractPoiType { + + protected final String keyName; + protected final MapPoiTypes registry; + + + + public AbstractPoiType(String keyName, MapPoiTypes registry) { + this.keyName = keyName; + this.registry = registry; + } + + public String getName() { + return keyName; + } + + public String getKeyName() { + return keyName; + } + + public String getTranslation() { + return registry.getTranslation(this); + } + + +} diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 8742ddfe1d..4527b1b248 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -5,23 +5,37 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import net.osmand.PlatformUtil; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; + public class MapPoiTypes { private static MapPoiTypes DEFAULT_INSTANCE = null; private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private String resourceName; - private List categories = new ArrayList(); + private List categories = new ArrayList(); + private PoiCategory otherCategory; + + static final String OSM_WIKI_CATEGORY = "osmwiki"; + private PoiTranslator poiTranslator = null; public MapPoiTypes(String fileName){ this.resourceName = fileName; } + public interface PoiTranslator { + + public String getTranslation(AbstractPoiType type); + } + public static MapPoiTypes getDefault() { if(DEFAULT_INSTANCE == null){ DEFAULT_INSTANCE = new MapPoiTypes(null); @@ -29,6 +43,81 @@ public class MapPoiTypes { } return DEFAULT_INSTANCE; } + + + public static MapPoiTypes initDefault(PoiTranslator pt) { + MapPoiTypes df = getDefault(); + df.setPoiTranslator(pt); + return df; + } + + + public PoiCategory getOtherPoiCategory() { + return otherCategory; + } + + public PoiCategory getUserDefinedCategory() { + return otherCategory; + } + + public PoiCategory getPoiCategoryByName(String name) { + return getPoiCategoryByName(name, false); + } + + + public PoiCategory getPoiCategoryBySubtypeName(String name) { + for(PoiCategory pc : categories) { + PoiType pt = pc.getPoiTypeByKeyName(name); + if(pt != null) { + return pc; + } + } + return otherCategory; + } + + public Map getAllTranslatedNames() { + Map translation = new TreeMap(); + for(PoiCategory pc : categories) { + for(PoiType pt : pc.getPoiTypes()) { + translation.put(pt.getTranslation(), pt); + } + } + return translation; + } + + public Map getAllTranslatedNames(PoiCategory pc) { + Map translation = new TreeMap(); + for (PoiType pt : pc.getPoiTypes()) { + translation.put(pt.getTranslation(), pt); + } + return translation; + } + + public PoiCategory getPoiCategoryByName(String name, boolean create) { + if(name.equals("entertainment") && !create) { + name = "leisure"; + } + for(PoiCategory p : categories ) { + if(p.getName().equals(name)) { + return p; + } + } + if(create) { + PoiCategory lastCategory = new PoiCategory(this, name, categories.size()); + categories.add(lastCategory); + return lastCategory; + } + return otherCategory; + } + + public PoiTranslator getPoiTranslator() { + return poiTranslator; + } + + public void setPoiTranslator(PoiTranslator poiTranslator) { + this.poiTranslator = poiTranslator; + } + protected void init(){ InputStream is; @@ -48,7 +137,7 @@ public class MapPoiTypes { if (tok == XmlPullParser.START_TAG) { String name = parser.getName(); if (name.equals("poi_category")) { - lastCategory = new PoiCategory(this, parser.getAttributeValue("","name")); + lastCategory = new PoiCategory(this, parser.getAttributeValue("","name"), categories.size()); categories.add(lastCategory); } else if (name.equals("poi_filter")) { PoiFilter tp = new PoiFilter(this, lastCategory, @@ -65,9 +154,8 @@ public class MapPoiTypes { if(lastFilter != null) { lastFilter.addPoiType(tp); - } else { - lastCategory.addPoiType(tp); } + lastCategory.addPoiType(tp); } } else if (tok == XmlPullParser.END_TAG) { String name = parser.getName(); @@ -91,12 +179,22 @@ public class MapPoiTypes { e.printStackTrace(); throw new RuntimeException(e); } + findDefaultOtherCategory(); } + private void findDefaultOtherCategory() { + PoiCategory pc = getPoiCategoryByName("user_defined_other"); + if(pc == null) { + throw new IllegalArgumentException("No poi category other"); + } + otherCategory = pc; + } + public List getCategories() { return categories; } + private static void print(MapPoiTypes df) { List pc = df.getCategories(); for(PoiCategory p : pc) { @@ -120,5 +218,24 @@ public class MapPoiTypes { print(getDefault()) ; } + public String getTranslation(AbstractPoiType abstractPoiType) { + String translation = null; + if(poiTranslator != null) { + translation = poiTranslator.getTranslation(abstractPoiType); + } + if(translation != null) { + return translation; + } + return Algorithms.capitalizeFirstLetterAndLowercase(abstractPoiType.getName().replace('_', ' ')); + } + + + public boolean isRegisteredType(PoiCategory t) { + return getPoiCategoryByName(t.getKeyName()) != otherCategory; + } + + + + } diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index 2b4495b9fd..c6dcda3470 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -43,9 +43,6 @@ public class MapRenderingTypes { private static char TAG_DELIMETER = '/'; //$NON-NLS-1$ 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(); @@ -84,81 +81,6 @@ public class MapRenderingTypes { init(); } } - - public void getAmenityTagValue(AmenityType type, String subType, StringBuilder tag, StringBuilder value) { - tag.setLength(0); - tag.append(type.getDefaultTag()); - value.setLength(0); - value.append(subType); - Map> m = getAmenityTypeNameToTagVal(); - if (m.containsKey(type)) { - Map map = m.get(type); - if (map.containsKey(subType)) { - String res = map.get(subType); - if (res != null) { - int i = res.indexOf(' '); - if (i != -1) { - tag.setLength(0); - tag.append(res.substring(0, i)); - value.setLength(0); - value.append(res.substring(i + 1)); - } else { - tag.setLength(0); - tag.append(res); - } - } - } - } - } - - private Map> getAmenityTypeNameToTagVal() { - if (amenityTypeNameToTagVal == null) { - Map types = getEncodingRuleTypes(); - amenityTypeNameToTagVal = new LinkedHashMap>(); - for(MapRulType type : types.values()){ - if(type.poiCategory != null && type.targetTagValue == null) { - if(!amenityTypeNameToTagVal.containsKey(type.poiCategory)) { - amenityTypeNameToTagVal.put(type.poiCategory, new TreeMap()); - } - String name = type.getValue(); - if (name != null) { - if (type.poiPrefix != null) { - name = type.poiPrefix + name; - amenityTypeNameToTagVal.get(type.poiCategory).put(name, type.getTag() + " " + type.getValue()); - } else { - amenityTypeNameToTagVal.get(type.poiCategory).put(name, type.getTag()); - } - } - } - } - } - 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); @@ -229,45 +151,8 @@ public class MapRenderingTypes { } return value; } - - public Map getAmenityNameToType(){ - if(amenityNameToType == null){ - amenityNameToType = new LinkedHashMap(); - Map> map = getAmenityTypeNameToTagVal(); - Iterator>> iter = map.entrySet().iterator(); - while(iter.hasNext()){ - Entry> e = iter.next(); - for(String t : e.getValue().keySet()){ - if (t != null) { - if (amenityNameToType.containsKey(t)) { - System.err.println("Conflict " + t + " " + amenityNameToType.get(t) + " <> " + e.getKey()); - } else { - amenityNameToType.put(t, e.getKey()); - } - - } - } - } - } - return amenityNameToType; - } - public Collection getAmenitySubCategories(AmenityType t){ - Map> amenityTypeNameToTagVal = getAmenityTypeNameToTagVal(); - if(!amenityTypeNameToTagVal.containsKey(t)){ - return Collections.emptyList(); - } - 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); } diff --git a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java index 175fbf02f7..9c8fd1ad36 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiCategory.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiCategory.java @@ -3,20 +3,48 @@ package net.osmand.osm; import java.util.ArrayList; import java.util.List; + public class PoiCategory extends PoiFilter { - + private List poiFilters = new ArrayList(); - - public PoiCategory(MapPoiTypes registry, String keyName){ + private int regId; + private String defaultTag; + + public PoiCategory(MapPoiTypes registry, String keyName, int regId) { super(registry, null, keyName); + this.regId = regId; } - + public void addPoiType(PoiFilter poi) { poiFilters.add(poi); } - + public List getPoiFilters() { return poiFilters; } + public String getDefaultTag() { + if(defaultTag == null) { + return keyName; + } + return defaultTag; + } + + public void setDefaultTag(String defaultTag) { + this.defaultTag = defaultTag; + } + + + public boolean isWiki() { + return keyName.equals(MapPoiTypes.OSM_WIKI_CATEGORY); + } + + public String getKey() { + return keyName; + } + + public int ordinal() { + return regId; + } + } diff --git a/OsmAnd-java/src/net/osmand/osm/PoiFilter.java b/OsmAnd-java/src/net/osmand/osm/PoiFilter.java index 60259ccc29..884e8f6d2d 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiFilter.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiFilter.java @@ -5,27 +5,23 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -public class PoiFilter { +public class PoiFilter extends AbstractPoiType { - private String keyName; - private String translationName; - private MapPoiTypes registry; + private PoiCategory pc; private List poiTypes = new ArrayList(); private Map map = new LinkedHashMap(); - private PoiCategory pc; public PoiFilter(MapPoiTypes registry, PoiCategory pc, String keyName){ - this.registry = registry; + super(keyName, registry); this.pc = pc; - this.keyName = keyName; } public PoiCategory getPoiCategory() { return pc; } - public String getTranslationName() { - return translationName; + public PoiType getPoiTypeByKeyName(String kn) { + return map.get(kn); } public void addPoiType(PoiType type) { @@ -33,7 +29,6 @@ public class PoiFilter { poiTypes.add(type); map.put(type.getName(), type); } - } public List getPoiTypes() { diff --git a/OsmAnd-java/src/net/osmand/osm/PoiType.java b/OsmAnd-java/src/net/osmand/osm/PoiType.java index 4ececbd1c8..34f892b29b 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiType.java @@ -1,10 +1,14 @@ package net.osmand.osm; -public class PoiType { +public class PoiType extends AbstractPoiType { + + + public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name){ + super(name, poiTypes); + this.category = category; + } + - private String name; - private String translationName; - private MapPoiTypes poiTypes; public String getOsmTag() { return osmTag; } @@ -43,22 +47,10 @@ public class PoiType { private String osmValue; private String osmValue2; - public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name){ - this.poiTypes = poiTypes; - this.category = category; - this.name = name; - } public PoiCategory getCategory() { return category; } - public String getTranslationName() { - return translationName; - } - - public String getName() { - return name; - } } diff --git a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java index 6c316f96df..2e72aa280e 100644 --- a/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java +++ b/OsmAnd-java/src/net/osmand/osm/edit/EntityParser.java @@ -12,7 +12,9 @@ import net.osmand.data.City.CityType; import net.osmand.data.LatLon; import net.osmand.data.MapObject; import net.osmand.data.TransportStop; +import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapRenderingTypes; +import net.osmand.osm.PoiCategory; import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.util.Algorithms; @@ -63,7 +65,7 @@ public class EntityParser { mo.setName(op); } - public static Amenity parseAmenity(Entity entity, AmenityType type, String subtype, Map tagValues, + public static Amenity parseAmenity(Entity entity, PoiCategory type, String subtype, Map tagValues, MapRenderingTypes types) { Amenity am = new Amenity(); parseMapObject(am, entity); @@ -72,7 +74,8 @@ public class EntityParser { } am.setType(type); am.setSubType(subtype); - am.setAdditionalInfo(types.getAmenityAdditionalInfo(tagValues, type, subtype)); + AmenityType at = AmenityType.findOrCreateTypeNoReg(type.getKeyName()); + am.setAdditionalInfo(types.getAmenityAdditionalInfo(tagValues, at, subtype)); String wbs = getWebSiteURL(entity); if(wbs != null) { am.setAdditionalInfo("website", wbs); @@ -109,7 +112,7 @@ public class EntityParser { } public static List parseAmenities(MapRenderingTypes renderingTypes, - Entity entity, List amenitiesList){ + MapPoiTypes poiTypes, Entity entity, List amenitiesList){ amenitiesList.clear(); // it could be collection of amenities boolean relation = entity instanceof Relation; @@ -123,7 +126,8 @@ public class EntityParser { : renderingTypes.getAmenityType(e.getKey(), e.getValue(), hasName ); if (type != null) { String subtype = renderingTypes.getAmenitySubtype(e.getKey(), e.getValue()); - Amenity a = parseAmenity(entity, type, subtype, tags, renderingTypes); + PoiCategory pc = poiTypes.getPoiCategoryByName(type.getCategoryName(), true); + Amenity a = parseAmenity(entity, pc, subtype, tags, renderingTypes); if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) { amenitiesList.add(a); } diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index a2c1145671..4ef9e10e24 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -1,6 +1,26 @@ - + + Shop + Emergency + Transportation + Man made + Education + Administrative + Healthcare + Office + Sport + Tourism + Leisure + Food + Service + Finance + Natural + Nautical + Military + Wikipedia + User defined + Palaeontological site Bakery @@ -640,7 +660,7 @@ Rock, seamark Wreck, seamark - Military zone + Military zone Military airfield Military bunker Barracks diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 09536e02e0..292a07e314 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -1,13 +1,13 @@ package net.osmand.plus; -import java.lang.reflect.Field; import java.text.DecimalFormat; import java.text.MessageFormat; import java.util.Map.Entry; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.City.CityType; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.util.Algorithms; import android.content.Context; @@ -157,22 +157,10 @@ public class OsmAndFormatter { return ""; } - public static String toPublicString(AmenityType t, Context ctx) { - Class cl = R.string.class; - try { - Field fld = cl.getField("amenity_type_"+t.getCategoryName()); - if(fld != null) { - return ctx.getString((Integer)fld.get(null)); - } - } catch (Exception e) { - } - return ctx.getString(R.string.amenity_type_user_defined); - } - - + public static String getPoiSimpleFormat(Amenity amenity, Context ctx, boolean en) { return getPoiStringWithoutType(amenity, en, - toPublicString(amenity.getType(), ctx) + ": " + amenity.getSubType()); //$NON-NLS-1$ + amenity.getType().getTranslation() + ": " + amenity.getSubType()); //$NON-NLS-1$ } public static String getPoiStringWithoutType(Amenity amenity, boolean en) { @@ -180,12 +168,14 @@ public class OsmAndFormatter { } public static String getPoiStringWithoutType(Amenity amenity, boolean en, String defName) { - String nm = SpecialPhrases.getSpecialPhrase(amenity.getSubType(), defName); - String type = - SpecialPhrases.getSpecialPhrase(amenity.getType().getCategoryName() + "_" + amenity.getSubType(), - nm); + PoiCategory pc = amenity.getType(); + PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); + String nm = defName; + if (pt != null) { + nm = pt.getTranslation(); + } String n = amenity.getName(en); - if (n.indexOf(type) != -1) { + if (n.indexOf(nm) != -1) { // type is contained in name e.g. // n = "Bakery the Corner" // type = "Bakery" @@ -193,9 +183,9 @@ public class OsmAndFormatter { return n; } if (n.length() == 0) { - return type; + return nm; } - return type + " " + n; //$NON-NLS-1$ + return nm + " " + n; //$NON-NLS-1$ } public static String getAmenityDescriptionContent(Context ctx, Amenity amenity, boolean shortDescription) { @@ -204,7 +194,7 @@ public class OsmAndFormatter { String key = e.getKey(); String vl = e.getValue(); if(Amenity.DESCRIPTION.equals(key)) { - if(amenity.getType() == AmenityType.OSMWIKI && shortDescription) { + if(amenity.getType().isWiki() && shortDescription) { continue; } } else if(Amenity.OPENING_HOURS.equals(key)) { @@ -212,17 +202,19 @@ public class OsmAndFormatter { } else if(Amenity.PHONE.equals(key)) { d.append(ctx.getString(R.string.phone) + ": "); } else if(Amenity.WEBSITE.equals(key)) { - if(amenity.getType() == AmenityType.OSMWIKI) { + if(amenity.getType().isWiki()) { continue; } d.append(ctx.getString(R.string.website) + ": "); } else { - vl = SpecialPhrases.getSpecialPhrase(e.getKey() + "_" + e.getValue(), null); - if(vl == null){ - vl = SpecialPhrases.getSpecialPhrase(e.getKey(), - Algorithms.capitalizeFirstLetterAndLowercase(e.getKey())) + ": "; - vl += SpecialPhrases.getSpecialPhrase(e.getValue(), e.getValue()); + PoiCategory pc = amenity.getType(); + PoiType pt = pc.getPoiTypeByKeyName(e.getKey()); + if (pt != null) { + vl = pt.getTranslation(); + } else { + vl = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey()); } + vl += ": " + e.getValue(); } d.append(vl).append('\n'); } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index cb8b3445cc..48d8d7f195 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -8,26 +8,25 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintStream; import java.lang.Thread.UncaughtExceptionHandler; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; +import net.osmand.osm.AbstractPoiType; +import net.osmand.osm.MapPoiTypes; import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.MainMenuActivity; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; -import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; @@ -60,8 +59,6 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; -import android.graphics.Shader.TileMode; -import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; import android.os.Build; import android.os.Handler; @@ -88,6 +85,7 @@ public class OsmandApplication extends Application { ResourceManager resourceManager = null; PoiFiltersHelper poiFilters = null; + MapPoiTypes poiTypes = null; RoutingHelper routingHelper = null; FavouritesDbHelper favorites = null; CommandPlayer player = null; @@ -158,6 +156,7 @@ public class OsmandApplication extends Application { applyTheme(this); + poiTypes = initPoiTypes(); routingHelper = new RoutingHelper(this, player); taskManager = new OsmAndTaskManager(this); resourceManager = new ResourceManager(this); @@ -175,7 +174,6 @@ public class OsmandApplication extends Application { // if(!osmandSettings.FOLLOW_THE_ROUTE.get()) { // targetPointsHelper.clearPointToNavigate(false); // } - checkPreferredLocale(); startApplication(); if (LOG.isDebugEnabled()) { @@ -190,6 +188,32 @@ public class OsmandApplication extends Application { } + + public MapPoiTypes getPoiTypes() { + if(poiTypes == null) { + throw new IllegalStateException("State exception"); + } + return poiTypes; + } + + private MapPoiTypes initPoiTypes() { + return MapPoiTypes.initDefault(new MapPoiTypes.PoiTranslator() { + + @Override + public String getTranslation(AbstractPoiType type) { + try { + Field f = R.string.class.getField("poi_" + type.getKeyName()); + if (f != null) { + Integer in = (Integer) f.get(null); + return getString(in); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + return null; + } + }); + } private void createInUiThread() { new Toast(this); // activate in UI thread to avoid further exceptions @@ -546,13 +570,6 @@ public class OsmandApplication extends Application { List warnings = new ArrayList(); try { favorites.loadFavorites(); - try { - SpecialPhrases.setLanguage(this, osmandSettings); - } catch (IOException e) { - LOG.error("I/O exception", e); - warnings.add("Error while reading the special phrases. Restart OsmAnd if possible"); - } - if (!"qnx".equals(System.getProperty("os.name"))) { if (osmandSettings.USE_OPENGL_RENDER.get()) { boolean success = false; diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 11585c9977..3661aef45e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -334,7 +334,6 @@ public abstract class OsmandPlugin { for (OsmandPlugin plugin : getEnabledPlugins()) { plugin.optionsMenuFragment(activity, fragment, optionsMenuAdapter); } - } diff --git a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java b/OsmAnd/src/net/osmand/plus/SpecialPhrases.java deleted file mode 100644 index f2544998ba..0000000000 --- a/OsmAnd/src/net/osmand/plus/SpecialPhrases.java +++ /dev/null @@ -1,100 +0,0 @@ -package net.osmand.plus; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import net.osmand.PlatformUtil; -import net.osmand.util.Algorithms; - -import org.apache.commons.logging.Log; - - -public class SpecialPhrases { - - - private static Map m; - private static final Log log = PlatformUtil.getLog(SpecialPhrases.class); - - /** - * Use this method to query a special phrase for a certain subtype - * - * If the language isn't set yet, a nullpointer exception will be thrown - * - * @param value the subtype to query - * @return the special phrase according to the asked key, or "null" if the key isn't found - */ - public static String getSpecialPhrase(String value, String defValue) { - if (m == null) { - // do not throw exception because OsmAndApplication is not always initiliazed before - // this call - log.warn("The language has not been set for special phrases"); - return value; - - } - String specialValue = m.get(value); - if (Algorithms.isEmpty(specialValue)) { - specialValue = defValue; - } - return specialValue == null ? null : specialValue.replace('_', ' '); - } - - /** - * Set the special phrases to a certain language. - * This method needs to be used before the getSpecialPhrase method - * - * @param lang the language to use - * @throws IOException when reading the text file failed - */ - public static void setLanguage(OsmandApplication ctx, OsmandSettings settings) throws IOException { - String lang = getPreferredLanguage(settings).getLanguage(); - m = new HashMap(); - // The InputStream opens the resourceId and sends it to the buffer - InputStream is = null; - BufferedReader br = null; - try { - try { - is = ctx.getAssets().open("specialphrases/specialphrases_" + lang + ".txt"); - } catch (IOException ex) { - // second try: default to English, if this fails, the error is thrown outside - is = ctx.getAssets().open("specialphrases/specialphrases_en.txt"); - } - br = new BufferedReader(new InputStreamReader(is)); - String readLine = null; - - // While the BufferedReader readLine is not null - while ((readLine = br.readLine()) != null) { - String[] arr = readLine.split(","); - if (arr != null && arr.length == 2) { - m.put(arr[0], arr[1]); - } - - } - - } finally { - Algorithms.closeStream(is); - Algorithms.closeStream(br); - } - - } - - /** - * Returns the preferred language - * @param set the OsmandSettings used - * @return ENGLISH if English names are chosen in the settings, Locale.getDefault otherwise - */ - public static Locale getPreferredLanguage(OsmandSettings set){ - if (set.usingEnglishNames()) { - return Locale.ENGLISH; - } - return Locale.getDefault(); - - } - - - -} diff --git a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java index 2f3aeaf49e..2948a65058 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java @@ -6,33 +6,47 @@ package net.osmand.plus.activities; import java.text.Collator; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; -import android.support.v4.view.MenuItemCompat; -import android.view.*; -import android.widget.*; import net.osmand.access.AccessibleToast; -import net.osmand.data.AmenityType; import net.osmand.data.LatLon; -import net.osmand.osm.MapRenderingTypes; -import net.osmand.plus.OsmAndFormatter; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.SpecialPhrases; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchPOIActivity; -import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiLegacyFilter; +import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; +import android.widget.ListView; +import android.widget.ScrollView; +import android.widget.TextView; +import android.widget.Toast; /** * @@ -62,9 +76,9 @@ public class EditPOIFilterActivity extends OsmandListActivity { if (filter != null) { getSupportActionBar().setSubtitle(filter.getName()); - setListAdapter(new AmenityAdapter(AmenityType.getCategories())); + setListAdapter(new AmenityAdapter( ((OsmandApplication) getApplication()).getPoiTypes().getCategories())); } else { - setListAdapter(new AmenityAdapter(new AmenityType[0])); + setListAdapter(new AmenityAdapter(new ArrayList())); } } @@ -189,7 +203,7 @@ public class EditPOIFilterActivity extends OsmandListActivity { builder.create().show(); } - private void showDialog(final AmenityType amenity) { + private void showDialog(final PoiCategory poiCategory) { ListView lv = EditPOIFilterActivity.this.getListView(); final int index = lv.getFirstVisiblePosition(); View v = lv.getChildAt(0); @@ -197,28 +211,26 @@ public class EditPOIFilterActivity extends OsmandListActivity { Builder builder = new AlertDialog.Builder(this); ScrollView scroll = new ScrollView(this); ListView listView = new ListView(this); - - final LinkedHashSet subCategories = new LinkedHashSet(MapRenderingTypes.getDefault().getAmenitySubCategories(amenity)); - Set acceptedCategories = filter.getAcceptedSubtypes(amenity); + final LinkedHashMap subCategories = new LinkedHashMap(); + Set acceptedCategories = filter.getAcceptedSubtypes(poiCategory); if (acceptedCategories != null) { - for (String s : acceptedCategories) { - if (!subCategories.contains(s)) { - subCategories.add(s); - } + for(String s : acceptedCategories) { + subCategories.put(s, Algorithms.capitalizeFirstLetterAndLowercase(s)); } } + for(PoiType pt : poiCategory.getPoiTypes()) { + subCategories.put(pt.getKeyName(), pt.getTranslation()); + } - final String[] array = subCategories.toArray(new String[0]); + final String[] array = subCategories.keySet().toArray(new String[0]); final Collator cl = Collator.getInstance(); cl.setStrength(Collator.SECONDARY); Arrays.sort(array, 0, array.length, new Comparator() { @Override public int compare(String object1, String object2) { - String v1 = SpecialPhrases.getSpecialPhrase(object1, object1); - String v2 = SpecialPhrases.getSpecialPhrase(object2, object2); - v1 = SpecialPhrases.getSpecialPhrase(amenity.getDefaultTag()+"_"+object1, v1); - v2 = SpecialPhrases.getSpecialPhrase(amenity.getDefaultTag()+"_"+object2, v2); + String v1 = subCategories.get(object1); + String v2 = subCategories.get(object2); return cl.compare(v1, v2); } }); @@ -227,9 +239,7 @@ public class EditPOIFilterActivity extends OsmandListActivity { for (int i = 0; i < array.length; i++) { final String subcategory = array[i]; - String name = SpecialPhrases.getSpecialPhrase(subcategory, subcategory); - visibleNames[i] = SpecialPhrases.getSpecialPhrase(amenity.getDefaultTag()+"_"+subcategory, - name); + visibleNames[i] = subCategories.get(subcategory); if (acceptedCategories == null) { selected[i] = true; } else { @@ -250,11 +260,11 @@ public class EditPOIFilterActivity extends OsmandListActivity { } } if (subCategories.size() == accepted.size()) { - filter.selectSubTypesToAccept(amenity, null); + filter.selectSubTypesToAccept(poiCategory, null); } else if(accepted.size() == 0){ - filter.setTypeToAccept(amenity, false); + filter.setTypeToAccept(poiCategory, false); } else { - filter.selectSubTypesToAccept(amenity, accepted); + filter.selectSubTypesToAccept(poiCategory, accepted); } helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); @@ -267,7 +277,7 @@ public class EditPOIFilterActivity extends OsmandListActivity { builder.setPositiveButton(EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - filter.selectSubTypesToAccept(amenity, null); + filter.selectSubTypesToAccept(poiCategory, null); helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); @@ -298,8 +308,8 @@ public class EditPOIFilterActivity extends OsmandListActivity { showDialog(getListAdapter().getItem(position)); } - class AmenityAdapter extends ArrayAdapter { - AmenityAdapter(AmenityType[] amenityTypes) { + class AmenityAdapter extends ArrayAdapter { + AmenityAdapter(List amenityTypes) { super(EditPOIFilterActivity.this, R.layout.editing_poi_filter_list, amenityTypes); } @@ -310,18 +320,18 @@ public class EditPOIFilterActivity extends OsmandListActivity { if (row == null) { row = inflater.inflate(R.layout.editing_poi_filter_list, parent, false); } - AmenityType model = getItem(position); + PoiCategory model = getItem(position); CheckBox check = (CheckBox) row.findViewById(R.id.filter_poi_check); check.setChecked(filter.isTypeAccepted(model)); TextView text = (TextView) row.findViewById(R.id.filter_poi_label); - text.setText(OsmAndFormatter.toPublicString(model, getMyApplication())); + text.setText(model.getTranslation()); addRowListener(model, text, check); return (row); } - private void addRowListener(final AmenityType model, final TextView text, final CheckBox check) { + private void addRowListener(final PoiCategory model, final TextView text, final CheckBox check) { text.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 9c37127838..3302174829 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -10,14 +10,13 @@ import net.osmand.CallbackWithObject; import net.osmand.ResultMatcher; import net.osmand.StateChangedListener; import net.osmand.access.AccessibleToast; -import net.osmand.data.AmenityType; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager.TileSourceTemplate; +import net.osmand.osm.PoiCategory; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.Item; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -25,8 +24,8 @@ import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.helpers.GpxUiHelper; -import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.poi.PoiFiltersHelper; +import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.MapVectorLayer; import net.osmand.plus.render.RenderingIcons; @@ -283,11 +282,11 @@ public class MapActivityLayers { it.reg(); userDefined.add(f); } - final AmenityType[] categories = AmenityType.getCategories(); - for(AmenityType t : categories){ - Item it = adapter.item(OsmAndFormatter.toPublicString(t, activity.getMyApplication())); - if(RenderingIcons.containsBigIcon(t.toString().toLowerCase())) { - it.icon(RenderingIcons.getBigIconResourceId(t.toString().toLowerCase())); + final List categories = getApplication().getPoiTypes().getCategories(); + for(PoiCategory t : categories){ + Item it = adapter.item(t.getTranslation()); + if(RenderingIcons.containsBigIcon(t.getKeyName())) { + it.icon(RenderingIcons.getBigIconResourceId(t.getKeyName())); } it.reg(); } @@ -312,7 +311,7 @@ public class MapActivityLayers { } else if (which <= userDefined.size() + 1) { filterId = userDefined.get(which - 2).getFilterId(); } else { - filterId = PoiFiltersHelper.getOsmDefinedFilterId(categories[which - userDefined.size() - 2]); + filterId = PoiFiltersHelper.getOsmDefinedFilterId(categories.get(which - userDefined.size() - 2)); } getApplication().getSettings().setPoiFilterForMap(filterId); PoiLegacyFilter f = poiFilters.getFilterById(filterId); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 61a440ac05..d60cdadffb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -12,7 +12,6 @@ import java.util.List; import net.osmand.ResultMatcher; import net.osmand.access.AccessibleToast; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.City; import net.osmand.data.LatLon; import net.osmand.data.MapObject; @@ -276,7 +275,7 @@ public class GeoIntentActivity extends OsmandListActivity { } Amenity point = new Amenity(); - ((Amenity) point).setType(AmenityType.USER_DEFINED); + ((Amenity) point).setType(getMyApplication().getPoiTypes().getUserDefinedCategory()); ((Amenity) point).setSubType(""); point.setLocation(lat, lon); point.setName("Lat: " + lat + ",Lon:" + lon); @@ -380,7 +379,7 @@ public class GeoIntentActivity extends OsmandListActivity { } @SuppressWarnings("unused") - private static class GeoPointSearch implements MyService { + private class GeoPointSearch implements MyService { private final MapObject point; private final int zoom; @@ -400,7 +399,7 @@ public class GeoIntentActivity extends OsmandListActivity { final Amenity amenity = new Amenity(); amenity.setLocation(lat, lon); amenity.setName(name); - amenity.setType(AmenityType.USER_DEFINED); + amenity.setType(getMyApplication().getPoiTypes().getUserDefinedCategory()); amenity.setSubType(""); this.point = amenity; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 5ba0220567..05381720ef 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -4,10 +4,6 @@ package net.osmand.plus.activities.search; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.support.v7.widget.PopupMenu; -import android.support.v7.widget.Toolbar; import gnu.trove.set.hash.TLongHashSet; import java.util.ArrayList; @@ -23,12 +19,9 @@ import net.osmand.ResultMatcher; import net.osmand.access.AccessibleToast; import net.osmand.access.NavigationInfo; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.LatLon; -import net.osmand.osm.MapRenderingTypes; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuAdapter.Item; -import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndConstants; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; @@ -38,7 +31,6 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.EditPOIFilterActivity; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.MapActivityActions; import net.osmand.plus.activities.OsmandListActivity; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.poi.NameFinderPoiFilter; @@ -55,6 +47,8 @@ import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.AsyncTask; @@ -62,12 +56,12 @@ import android.os.AsyncTask.Status; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.MenuItemCompat; +import android.support.v7.widget.PopupMenu; +import android.support.v7.widget.Toolbar; import android.text.Editable; -import android.text.Spannable; import android.text.SpannableString; import android.text.TextWatcher; import android.text.method.LinkMovementMethod; -import android.text.style.ForegroundColorSpan; import android.text.util.Linkify; import android.view.Gravity; import android.view.LayoutInflater; @@ -77,7 +71,6 @@ import android.view.MenuItem.OnMenuItemClickListener; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; -import android.view.Window; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -387,7 +380,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa private void showPoiCategoriesByNameFilter(String query, net.osmand.Location loc){ OsmandApplication app = (OsmandApplication) getApplication(); if(loc != null){ - Map> map = app.getResourceManager().searchAmenityCategoriesByName(query, loc.getLatitude(), loc.getLongitude()); + Map> map = app.getResourceManager().searchAmenityCategoriesByName(query, loc.getLatitude(), loc.getLongitude()); if(!map.isEmpty()){ PoiLegacyFilter filter = ((OsmandApplication)getApplication()).getPoiFilters().getFilterById(PoiLegacyFilter.CUSTOM_FILTER_ID); if(filter != null){ @@ -401,13 +394,13 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } } - private String typesToString(Map> map) { + private String typesToString(Map> map) { StringBuilder b = new StringBuilder(); int count = 0; - Iterator>> iterator = map.entrySet().iterator(); + Iterator>> iterator = map.entrySet().iterator(); while(iterator.hasNext() && count < 4){ - Entry> e = iterator.next(); - b.append("\n").append(OsmAndFormatter.toPublicString(e.getKey(), getMyApplication())).append(" - "); + Entry> e = iterator.next(); + b.append("\n").append(e.getKey().getTranslation()).append(" - "); if(e.getValue() == null){ b.append("..."); } else { @@ -833,14 +826,17 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa direction.setImageResource(R.drawable.closed_poi); } } - StringBuilder tag = new StringBuilder(); - StringBuilder value = new StringBuilder(); - MapRenderingTypes.getDefault().getAmenityTagValue(amenity.getType(), amenity.getSubType(), - tag, value); - if(RenderingIcons.containsBigIcon(tag + "_" + value)) { - icon.setImageResource(RenderingIcons.getBigIconResourceId(tag + "_" + value)); - } else if(RenderingIcons.containsBigIcon(value.toString())) { - icon.setImageResource(RenderingIcons.getBigIconResourceId(value.toString())); + PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); + if (st != null) { + if (RenderingIcons.containsBigIcon(st.getKeyName())) { + icon.setImageResource(RenderingIcons.getBigIconResourceId(st.getKeyName())); + } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + icon.setImageResource(RenderingIcons.getBigIconResourceId(st.getOsmTag() + "_" + st.getOsmValue())); + } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + icon.setImageResource(RenderingIcons.getBigIconResourceId(st.getOsmValue())); + } else { + icon.setImageDrawable(null); + } } else { icon.setImageDrawable(null); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index f50cb40a15..46f8828090 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import net.osmand.CallbackWithObject; -import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.plus.OsmAndFormatter; diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index a0ad180b90..5dccabf44a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -18,11 +18,11 @@ import net.osmand.binary.RouteDataObject; import net.osmand.data.Amenity; import net.osmand.data.Amenity.AmenityRoutePoint; import net.osmand.data.LocationPoint; -import net.osmand.osm.MapRenderingTypes; +import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; import net.osmand.plus.OsmandSettings.MetricsConstants; +import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.base.FavoriteImageDrawable; @@ -675,14 +675,17 @@ public class WaypointHelper { public Drawable getDrawable(Context uiCtx, OsmandApplication app) { if(type == POI) { Amenity amenity = ((AmenityLocationPoint) point).a; - StringBuilder tag = new StringBuilder(); - StringBuilder value = new StringBuilder(); - MapRenderingTypes.getDefault().getAmenityTagValue(amenity.getType(), amenity.getSubType(), - tag, value); - if(RenderingIcons.containsBigIcon(tag + "_" + value)) { - return uiCtx.getResources().getDrawable(RenderingIcons.getBigIconResourceId(tag + "_" + value)); - } else if(RenderingIcons.containsBigIcon(value.toString())) { - return uiCtx.getResources().getDrawable(RenderingIcons.getBigIconResourceId(value.toString())); + PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); + if (st != null) { + if (RenderingIcons.containsBigIcon(st.getKeyName())) { + return uiCtx.getResources().getDrawable( + RenderingIcons.getBigIconResourceId(st.getKeyName())); + } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + return uiCtx.getResources().getDrawable( + RenderingIcons.getBigIconResourceId(st.getOsmTag() + "_" + st.getOsmValue())); + } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + return uiCtx.getResources().getDrawable(RenderingIcons.getBigIconResourceId(st.getOsmValue())); + } } return null; } else if(type == TARGETS) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java index 176f3aa7ef..c83a282793 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java @@ -4,13 +4,16 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; import net.osmand.access.AccessibleToast; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; +import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapRenderingTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; import net.osmand.osm.edit.EntityInfo; import net.osmand.osm.edit.EntityParser; import net.osmand.osm.edit.Node; @@ -86,11 +89,15 @@ public class EditingPOIActivity implements DialogProvider { private static Bundle dialogBundle = new Bundle(); private OsmandSettings settings; + private MapPoiTypes poiTypes; + private Map allTranslatedSubTypes; public EditingPOIActivity(MapActivity uiContext){ this.ctx = uiContext; + poiTypes = uiContext.getMyApplication().getPoiTypes(); + allTranslatedSubTypes = poiTypes.getAllTranslatedNames(); settings = ((OsmandApplication) uiContext.getApplication()).getSettings(); if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx); @@ -127,11 +134,11 @@ public class EditingPOIActivity implements DialogProvider { public void showCreateDialog(double latitude, double longitude){ Node n = new Node(latitude, longitude, -1); n.putTag(OSMTagKey.OPENING_HOURS.getValue(), ""); //$NON-NLS-1$ - showPOIDialog(DIALOG_CREATE_POI, n, AmenityType.OTHER, ""); + showPOIDialog(DIALOG_CREATE_POI, n, poiTypes.getOtherPoiCategory(), ""); } - private void showPOIDialog(int dialogID, Node n, AmenityType type, String subType) { - Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault()); + private void showPOIDialog(int dialogID, Node n, PoiCategory type, String subType) { + Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault()); dialogBundle.putSerializable(KEY_AMENITY, a); dialogBundle.putSerializable(KEY_AMENITY_NODE, n); ctx.showDialog(dialogID); @@ -269,7 +276,13 @@ public class EditingPOIActivity implements DialogProvider { } else { value.setHint("Value"); } - Set subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet(); + Set subCategories = new LinkedHashSet(); + // could be osm values +// for (String s : poiTypes.getAllTranslatedNames().keySet()) { +// if (!subCategories.contains(s)) { +// subCategories.add(s); +// } +// } ; ArrayAdapter valueAdapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); value.setThreshold(1); value.setAdapter(valueAdapter); @@ -374,11 +387,11 @@ public class EditingPOIActivity implements DialogProvider { public void afterTextChanged(Editable s) { String str = s.toString(); a.setSubType(str); - AmenityType t = MapRenderingTypes.getDefault().getAmenityNameToType().get(str); - if(t != null && a.getType() != t){ - a.setType(t); - typeButton.setText(OsmAndFormatter.toPublicString(t, ctx.getMyApplication())); - updateSubTypesAdapter(t); + PoiType st = allTranslatedSubTypes.get(str); + if(st != null && a.getType() != st.getCategory() && st.getCategory() != null){ + a.setType(st.getCategory()); + typeButton.setText(st.getCategory().getTranslation()); + updateSubTypesAdapter(st.getCategory()); } } @@ -448,11 +461,16 @@ public class EditingPOIActivity implements DialogProvider { final String msg = n.getId() == -1 ? resources.getString(R.string.poi_action_add) : resources .getString(R.string.poi_action_change); OsmPoint.Action action = n.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; - StringBuilder tag = new StringBuilder(); - StringBuilder value = new StringBuilder(); String subType = typeText.getText().toString(); - MapRenderingTypes.getDefault().getAmenityTagValue(a.getType(), subType, tag, value); - n.putTag(tag.toString(), value.toString()); + if(allTranslatedSubTypes.get(subType) != null) { + PoiType pt = allTranslatedSubTypes.get(subType); + n.putTag(pt.getOsmTag() , pt.getOsmValue()); + if(pt.getOsmTag2() != null) { + n.putTag(pt.getOsmTag2(), pt.getOsmValue2()); + } + } else { + n.putTag(a.getType().getDefaultTag(), subType); + } String name = nameText.getText().toString(); if(name.length() > 0) { n.putTag(OSMTagKey.NAME.getValue(), name); @@ -508,11 +526,10 @@ public class EditingPOIActivity implements DialogProvider { } } - private void updateSubTypesAdapter(AmenityType t){ - - Set subCategories = new LinkedHashSet(MapRenderingTypes.getDefault().getAmenityAllSubCategories(t)); - for(String s : MapRenderingTypes.getDefault().getAmenityNameToType().keySet()){ - if(!subCategories.contains(s)){ + private void updateSubTypesAdapter(PoiCategory poiCategory) { + Set subCategories = new LinkedHashSet(poiTypes.getAllTranslatedNames(poiCategory).keySet()); + for (String s : poiTypes.getAllTranslatedNames().keySet()) { + if (!subCategories.contains(s)) { subCategories.add(s); } } @@ -522,7 +539,7 @@ public class EditingPOIActivity implements DialogProvider { private void updateType(Amenity a){ typeText.setText(a.getSubType()); - typeButton.setText(OsmAndFormatter.toPublicString(a.getType(), ctx.getMyApplication())); + typeButton.setText(a.getType().getTranslation()); updateSubTypesAdapter(a.getType()); } @@ -602,63 +619,62 @@ public class EditingPOIActivity implements DialogProvider { public Dialog onCreateDialog(int id) { Bundle args = dialogBundle; switch (id) { - case DIALOG_CREATE_POI: - case DIALOG_EDIT_POI: - return createPOIDialog(id,args); - case DIALOG_DELETE_POI: - return createDeleteDialog(args); - case DIALOG_SUB_CATEGORIES: { - Builder builder = new AlertDialog.Builder(ctx); - final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); - final String[] subCats = MapRenderingTypes.getDefault().getAmenityAllSubCategories(a.getType()). - toArray(new String[0]); - builder.setItems(subCats, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - typeText.setText(subCats[which]); - a.setSubType(subCats[which]); - ctx.removeDialog(DIALOG_SUB_CATEGORIES); - } - }); - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - ctx.removeDialog(DIALOG_SUB_CATEGORIES); - } - }); - return builder.create(); - } - case DIALOG_POI_TYPES: { - final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); - Builder builder = new AlertDialog.Builder(ctx); - final AmenityType[] categories = AmenityType.getCategories(); - String[] vals = new String[categories.length]; - for(int i=0; i categories = poiTypes.getCategories(); + String[] vals = new String[categories.size()]; + for (int i = 0; i < vals.length; i++) { + vals[i] = categories.get(i).getTranslation(); } + builder.setItems(vals, new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + PoiCategory aType = categories.get(which); + if (aType != a.getType()) { + a.setType(aType); + a.setSubType(""); //$NON-NLS-1$ + updateType(a); + } + ctx.removeDialog(DIALOG_POI_TYPES); + } + }); + builder.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + ctx.removeDialog(DIALOG_POI_TYPES); + } + }); + return builder.create(); + } + case DIALOG_OPENING_HOURS: { + return createOpenHoursDlg(); + } } return null; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index 19d3628e9e..ab0ca0391e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -1,11 +1,8 @@ package net.osmand.plus.osmedit; -import java.util.Map; - import net.osmand.PlatformUtil; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; -import net.osmand.osm.MapRenderingTypes; +import net.osmand.osm.PoiType; import net.osmand.osm.edit.EntityInfo; import net.osmand.osm.edit.Node; import net.osmand.osm.edit.OSMSettings.OSMTagKey; @@ -52,7 +49,8 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { @Override public Node loadNode(Amenity n) { - if(n.getId() % 2 == 1){ + PoiType st = n.getType().getPoiTypeByKeyName(n.getSubType()); + if(n.getId() % 2 == 1 || st == null){ // that's way id return null; } @@ -62,10 +60,8 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId); - StringBuilder tag = new StringBuilder(); - StringBuilder value = new StringBuilder(); - MapRenderingTypes.getDefault().getAmenityTagValue(n.getType(), n.getSubType(), tag, value); - entity.putTag(tag.toString(), value.toString()); + entity.putTag(st.getOsmTag(), st.getOsmValue()); + entity.putTag(st.getOsmTag2(), st.getOsmValue2()); entity.putTag(OSMTagKey.NAME.getValue(), n.getName()); entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java index 86fe5574a0..8f09462989 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java @@ -27,10 +27,9 @@ public class OpenstreetmapPoint extends OsmPoint implements Serializable { } public String getType() { - String type = AmenityType.valueToString(AmenityType.OTHER); - for(String k : entity.getTagKeySet()){ - if (!OSMTagKey.NAME.getValue().equals(k) && - !OSMTagKey.OPENING_HOURS.getValue().equals(k)) { + String type = "amenity"; + for (String k : entity.getTagKeySet()) { + if (!OSMTagKey.NAME.getValue().equals(k) && !OSMTagKey.OPENING_HOURS.getValue().equals(k)) { type = k; break; } diff --git a/OsmAnd/src/net/osmand/plus/poi/NameFinderPoiFilter.java b/OsmAnd/src/net/osmand/plus/poi/NameFinderPoiFilter.java index f79f0ecb45..e5e9790954 100644 --- a/OsmAnd/src/net/osmand/plus/poi/NameFinderPoiFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/NameFinderPoiFilter.java @@ -2,7 +2,6 @@ package net.osmand.plus.poi; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.util.ArrayList; @@ -11,11 +10,10 @@ import java.util.List; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; +import net.osmand.osm.MapPoiTypes; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.R.string; import net.osmand.util.MapUtils; import net.sf.junidecode.Junidecode; @@ -85,6 +83,7 @@ public class NameFinderPoiFilter extends PoiLegacyFilter { int eventType; int namedDepth= 0; Amenity a = null; + MapPoiTypes poiTypes = ((OsmandApplication) getApplication()).getPoiTypes(); while ((eventType = parser.next()) != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("searchresults")) { //$NON-NLS-1$ @@ -106,7 +105,7 @@ public class NameFinderPoiFilter extends PoiLegacyFilter { String name = parser.getAttributeValue("", "display_name"); //$NON-NLS-1$//$NON-NLS-2$ a.setName(name); a.setEnName(Junidecode.unidecode(name)); - a.setType(AmenityType.OTHER); + a.setType(poiTypes.getOtherPoiCategory()); a.setSubType(parser.getAttributeValue("", "type")); //$NON-NLS-1$//$NON-NLS-2$ if (matcher == null || matcher.publish(a)) { searchedAmenities.add(a); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 9e20e60d96..c6a7f90d92 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -10,10 +10,10 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import net.osmand.data.AmenityType; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.R.string; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteStatement; @@ -39,9 +39,11 @@ public class PoiFiltersHelper { private static final String UDF_PARKING = "parking"; private static final String[] DEL = new String[] {}; + private MapPoiTypes poiTypes; public PoiFiltersHelper(OsmandApplication application){ this.application = application; + poiTypes = application.getPoiTypes(); } public NameFinderPoiFilter getNameFinderPOIFilter() { if(nameFinderPOIFilter == null){ @@ -73,14 +75,14 @@ public class PoiFiltersHelper { return findPoiFilter(filterId, getUserDefinedPoiFilters(), getTopStandardFilters(), getOsmDefinedPoiFilters()); } - private void putAll(Map> types, AmenityType tp){ - types.put(tp, null); + private void putAll(Map> types, String tp) { + types.put(poiTypes.getPoiCategoryByName(tp), null); } - - private void putValues(Map> types, AmenityType tp,String... vls){ + + private void putValues(Map> types, String p, String... vls) { LinkedHashSet list = new LinkedHashSet(); - Collections.addAll(list, vls); - types.put(tp, list); + Collections.addAll(list, vls); + types.put(poiTypes.getPoiCategoryByName(p), list); } private List getUserDefinedDefaultFilters() { @@ -108,35 +110,35 @@ public class PoiFiltersHelper { return filters; } - private Map> configureDefaultUserDefinedFilter(Map> types, String key) { + private Map> configureDefaultUserDefinedFilter(Map> types, String key) { if(types == null) { - types = new LinkedHashMap>(); + types = new LinkedHashMap>(); } if(UDF_ACCOMMODATION.equals(key)){ - putValues(types, AmenityType.TOURISM, "camp_site", + putValues(types, "tourism", "camp_site", "caravan_site","picnic_site","alpine_hut", "chalet","guest_house", "hostel", "hotel","motel"); } else if (UDF_CAR_AID.equals(key)) { - putValues(types, AmenityType.TRANSPORTATION, "fuel", "car_wash", "car_repair","car", "car_sharing"); - putValues(types, AmenityType.SHOP, "fuel", "car_wash", "car_repair","car", "car_parts"); + putValues(types, "transportation", "fuel", "car_wash", "car_repair","car", "car_sharing"); + putValues(types, "shop", "fuel", "car_wash", "car_repair","car", "car_parts"); } else if (UDF_FOOD_SHOP.equals(key)) { - putValues(types, AmenityType.SHOP, "alcohol", "bakery", "beverages", "butcher", "convenience", "department_store", + putValues(types, "shop", "alcohol", "bakery", "beverages", "butcher", "convenience", "department_store", "convenience", "farm", "general", "ice_cream", "kiosk", "seafood", "supermarket", "variety_store"); } else if(UDF_FOR_TOURISTS.equals(key)){ - putAll(types, AmenityType.HISTORIC); - putAll(types, AmenityType.TOURISM); - putAll(types, AmenityType.FINANCE); - putAll(types, AmenityType.OSMWIKI); - putValues(types, AmenityType.OTHER, "place_of_worship", "internet_access_wlan", "internet_access_wired", + putAll(types, "historic"); + putAll(types, "tourism"); + putAll(types, "finance"); + 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)){ - putValues(types, AmenityType.TRANSPORTATION, "fuel"); + putValues(types, "transportation", "fuel"); } else if (UDF_PARKING.equals(key)) { - putValues(types, AmenityType.TRANSPORTATION, "parking", + putValues(types, "transportation", "parking", "bicycle_parking"); } else if (UDF_PUBLIC_TRANSPORT.equals(key)) { - putValues(types, AmenityType.TRANSPORTATION, "public_transport_stop_position", "public_transport_platform", + putValues(types, "transportation", "public_transport_stop_position", "public_transport_platform", "public_transport_station", // railway "railway_platform", "railway_station", "halt", "tram_stop", "subway_entrance", "railway_buffer_stop", @@ -151,19 +153,19 @@ public class PoiFiltersHelper { // "rail", "tram", "light_rail", "subway", "railway_narrow_gauge", "railway_monorail", "railway_funicular" ); } else if (UDF_RESTAURANTS.equals(key)) { - putValues(types, AmenityType.SUSTENANCE, "restaurant", + putValues(types, "sustenance", "restaurant", "cafe", "food_court", "fast_food", "pub", "bar", "biergarten"); } else if (UDF_SIGHTSEEING.equals(key)) { - putAll(types, AmenityType.HISTORIC); - putValues(types, AmenityType.TOURISM, "attraction", + putAll(types, "historic"); + putValues(types, "tourism", "attraction", "artwork","zoo","theme_park", "museum","viewpoint"); - putAll(types, AmenityType.OSMWIKI); - putValues(types, AmenityType.OTHER, "place_of_worship"); + putAll(types, "osmwiki"); + putValues(types, "other", "place_of_worship"); } else if (UDF_EMERGENCY.equals(key)) { - putAll(types, AmenityType.HEALTHCARE); - putAll(types, AmenityType.EMERGENCY); + putAll(types, "healthcare"); + putAll(types, "emergency"); } else if (UDF_ENTERTAINMENT.equals(key)) { - putAll(types, AmenityType.ENTERTAINMENT); + putAll(types, "entertainment"); } return types; } @@ -194,7 +196,7 @@ public class PoiFiltersHelper { if (cacheTopStandardFilters == null) { cacheTopStandardFilters = new ArrayList(); PoiLegacyFilter filter = new PoiLegacyFilter(application.getString(R.string.poi_filter_custom_filter), - PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap>(), application); //$NON-NLS-1$ + PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap>(), application); //$NON-NLS-1$ filter.setStandardFilter(true); cacheTopStandardFilters.add(filter); cacheTopStandardFilters.add(new PoiLegacyFilter(null, application)); @@ -205,8 +207,8 @@ public class PoiFiltersHelper { return Collections.unmodifiableList(cacheTopStandardFilters); } - public static String getOsmDefinedFilterId(AmenityType t){ - return PoiLegacyFilter.STD_PREFIX + t; + public static String getOsmDefinedFilterId(PoiCategory t){ + return PoiLegacyFilter.STD_PREFIX + t.getKeyName(); } public void updateFilters(boolean onlyAddFilters){ @@ -219,7 +221,7 @@ public class PoiFiltersHelper { public List getOsmDefinedPoiFilters(){ if(cacheOsmDefinedFilters == null){ cacheOsmDefinedFilters = new ArrayList(); - for(AmenityType t : AmenityType.getCategories()){ + for(PoiCategory t : poiTypes.getCategories()){ cacheOsmDefinedFilters.add(new PoiLegacyFilter(t, application)); } final Collator instance = Collator.getInstance(); @@ -394,18 +396,18 @@ public class PoiFiltersHelper { if(!addOnlyCategories){ db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$ } - Map> types = p.getAcceptedTypes(); + Map> types = p.getAcceptedTypes(); SQLiteStatement insertCategories = db.compileStatement("INSERT INTO " + CATEGORIES_NAME + " VALUES (?, ?, ?)"); //$NON-NLS-1$ //$NON-NLS-2$ - for(AmenityType a : types.keySet()){ + for(PoiCategory a : types.keySet()){ if(types.get(a) == null){ insertCategories.bindString(1, p.getFilterId()); - insertCategories.bindString(2, AmenityType.valueToString(a)); + insertCategories.bindString(2, a.getTranslation()); insertCategories.bindNull(3); insertCategories.execute(); } else { for(String s : types.get(a)){ insertCategories.bindString(1, p.getFilterId()); - insertCategories.bindString(2, AmenityType.valueToString(a)); + insertCategories.bindString(2, a.getTranslation()); insertCategories.bindString(3, s); insertCategories.execute(); } @@ -422,15 +424,15 @@ public class PoiFiltersHelper { if(conn != null){ SQLiteCursor query = conn.rawQuery("SELECT " + CATEGORIES_FILTER_ID +", " + CATEGORIES_COL_CATEGORY +"," + CATEGORIES_COL_SUBCATEGORY +" FROM " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ CATEGORIES_NAME, null); - Map>> map = new LinkedHashMap>>(); + Map>> map = new LinkedHashMap>>(); if(query.moveToFirst()){ do { String filterId = query.getString(0); if(!map.containsKey(filterId)){ - map.put(filterId, new LinkedHashMap>()); + map.put(filterId, new LinkedHashMap>()); } - Map> m = map.get(filterId); - AmenityType a = AmenityType.findOrCreateTypeNoReg(query.getString(1)); + Map> m = map.get(filterId); + PoiCategory a = poiTypes.getPoiCategoryByName(query.getString(1)); String subCategory = query.getString(2); if(subCategory == null){ m.put(a, null); @@ -450,7 +452,8 @@ public class PoiFiltersHelper { do { String filterId = query.getString(0); if(map.containsKey(filterId)){ - PoiLegacyFilter filter = new PoiLegacyFilter(query.getString(1), filterId, map.get(filterId), application); + PoiLegacyFilter filter = new PoiLegacyFilter(query.getString(1), filterId, + map.get(filterId), application); filter.setFilterByName(query.getString(2)); list.add(filter); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index a6116ca3cc..edf7cde3d9 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -1,5 +1,6 @@ package net.osmand.plus.poi; + import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; @@ -9,10 +10,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import net.osmand.IndexConstants; import net.osmand.ResultMatcher; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -26,7 +27,8 @@ public class PoiLegacyFilter { public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; //$NON-NLS-1$ public final static String BY_NAME_FILTER_ID = USER_PREFIX + "by_name"; //$NON-NLS-1$ - private Map> acceptedTypes = new LinkedHashMap>(); + private Map> acceptedTypes = new LinkedHashMap>(); private String filterByName = null; protected String filterId; @@ -39,15 +41,16 @@ public class PoiLegacyFilter { protected int distanceInd = 1; // in kilometers protected double[] distanceToSearchValues = new double[] {1, 2, 5, 10, 20, 50, 100, 200, 500 }; + private final MapPoiTypes poiTypes; // constructor for standard filters - public PoiLegacyFilter(AmenityType type, OsmandApplication application){ + public PoiLegacyFilter(PoiCategory type, OsmandApplication application){ this.app = application; isStandardFilter = true; filterId = STD_PREFIX + type; - name = type == null ? application.getString(R.string.poi_filter_closest_poi) : OsmAndFormatter.toPublicString(type, - application); //$NON-NLS-1$ + poiTypes = application.getPoiTypes(); + name = type == null ? application.getString(R.string.poi_filter_closest_poi) : type.getTranslation(); //$NON-NLS-1$ if(type == null){ initSearchAll(); } else { @@ -56,9 +59,10 @@ public class PoiLegacyFilter { } // constructor for user defined filters - public PoiLegacyFilter(String name, String filterId, Map> acceptedTypes, OsmandApplication app){ + public PoiLegacyFilter(String name, String filterId, Map> acceptedTypes, OsmandApplication app){ this.app = app; isStandardFilter = false; + poiTypes = app.getPoiTypes(); if(filterId == null){ filterId = USER_PREFIX + name.replace(' ', '_').toLowerCase(); } @@ -88,7 +92,7 @@ public class PoiLegacyFilter { } private void initSearchAll(){ - for(AmenityType t : AmenityType.getCategories()){ + for(PoiCategory t : poiTypes.getCategories()){ acceptedTypes.put(t, null); } distanceToSearchValues = new double[] {0.5, 1, 2, 5, 10, 20, 50, 100}; @@ -191,20 +195,20 @@ public class PoiLegacyFilter { * @param type * @return null if all subtypes are accepted/ empty list if type is not accepted at all */ - public Set getAcceptedSubtypes(AmenityType type){ + public Set getAcceptedSubtypes(PoiCategory type){ if(!acceptedTypes.containsKey(type)){ return Collections.emptySet(); } return acceptedTypes.get(type); } - public boolean isTypeAccepted(AmenityType t){ + public boolean isTypeAccepted(PoiCategory t){ return acceptedTypes.containsKey(t); } - public boolean acceptTypeSubtype(AmenityType t, String subtype){ - if(!AmenityType.isRegisteredType(t)) { - t = AmenityType.USER_DEFINED; + public boolean acceptTypeSubtype(PoiCategory t, String subtype){ + if(!poiTypes.isRegisteredType(t)) { + t = poiTypes.getOtherPoiCategory(); } if(!acceptedTypes.containsKey(t)){ return false; @@ -217,12 +221,12 @@ public class PoiLegacyFilter { } public void clearFilter(){ - acceptedTypes = new LinkedHashMap>(); + acceptedTypes = new LinkedHashMap>(); } public boolean areAllTypesAccepted(){ - if(AmenityType.getCategoriesSize() == acceptedTypes.size()){ - for(AmenityType a : acceptedTypes.keySet()){ + if(poiTypes.getCategories().size() == acceptedTypes.size()){ + for(PoiCategory a : acceptedTypes.keySet()){ if(acceptedTypes.get(a) != null){ return false; } @@ -233,7 +237,7 @@ public class PoiLegacyFilter { } - public void setTypeToAccept(AmenityType type, boolean accept){ + public void setTypeToAccept(PoiCategory type, boolean accept){ if(accept){ acceptedTypes.put(type, new LinkedHashSet()); } else { @@ -241,11 +245,11 @@ public class PoiLegacyFilter { } } - public void setMapToAccept(Map> newMap) { - Iterator>> iterator = newMap.entrySet().iterator(); + public void setMapToAccept(Map> newMap) { + Iterator>> iterator = newMap.entrySet().iterator(); acceptedTypes.clear(); while(iterator.hasNext()){ - Entry> e = iterator.next(); + Entry> e = iterator.next(); if(e.getValue() == null){ acceptedTypes.put(e.getKey(), null); } else { @@ -254,49 +258,13 @@ public class PoiLegacyFilter { } } - public String buildSqlWhereFilter(){ - if(areAllTypesAccepted()){ - return null; - } - assert IndexConstants.POI_TABLE != null : "use constants here to show table usage "; //$NON-NLS-1$ - if(acceptedTypes.size() == 0){ - return "1 > 1"; //$NON-NLS-1$ - } - StringBuilder b = new StringBuilder(); - b.append("("); //$NON-NLS-1$ - boolean first = true; - for(AmenityType a : acceptedTypes.keySet()){ - if(first){ - first = false; - } else { - b.append(" OR "); //$NON-NLS-1$ - } - b.append("(type = '").append(AmenityType.valueToString(a)).append("'"); //$NON-NLS-1$ //$NON-NLS-2$ - if(acceptedTypes.get(a) != null){ - LinkedHashSet list = acceptedTypes.get(a); - b.append(" AND subtype IN ("); //$NON-NLS-1$ - boolean bfirst = true; - for(String s : list){ - if(bfirst){ - bfirst = false; - } else { - b.append(", "); //$NON-NLS-1$ - } - b.append("'").append(s).append("'"); //$NON-NLS-1$ //$NON-NLS-2$ - } - b.append(")"); //$NON-NLS-1$ - } - b.append(")"); //$NON-NLS-1$ - } - b.append(")"); //$NON-NLS-1$ - return b.toString(); + + + public Map> getAcceptedTypes(){ + return new LinkedHashMap>(acceptedTypes); } - public Map> getAcceptedTypes(){ - return new LinkedHashMap>(acceptedTypes); - } - - public void selectSubTypesToAccept(AmenityType t, LinkedHashSet accept){ + public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet accept){ acceptedTypes.put(t, accept); } diff --git a/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java b/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java index e71ee1022a..5e5dbb4ec9 100644 --- a/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java @@ -7,10 +7,9 @@ import java.util.List; import net.osmand.ResultMatcher; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; +import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.R.string; import net.osmand.util.MapUtils; public class SearchByNameFilter extends PoiLegacyFilter { @@ -22,7 +21,7 @@ public class SearchByNameFilter extends PoiLegacyFilter { private String query = ""; //$NON-NLS-1$ public SearchByNameFilter(OsmandApplication application) { - super(application.getString(R.string.poi_filter_by_name), FILTER_ID, new LinkedHashMap>(), application); + super(application.getString(R.string.poi_filter_by_name), FILTER_ID, new LinkedHashMap>(), application); this.distanceToSearchValues = new double[] {100, 1000, 5000}; this.isStandardFilter = true; } diff --git a/OsmAnd/src/net/osmand/plus/resources/AmenityIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/resources/AmenityIndexRepositoryBinary.java index 6f624cfaf8..688965138e 100644 --- a/OsmAnd/src/net/osmand/plus/resources/AmenityIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/resources/AmenityIndexRepositoryBinary.java @@ -14,7 +14,7 @@ import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; +import net.osmand.osm.PoiCategory; import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.util.MapUtils; @@ -49,7 +49,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { } - public synchronized Map> searchAmenityCategoriesByName(String query, Map> map) { + public synchronized Map> searchAmenityCategoriesByName(String query, Map> map) { try { return index.searchPoiCategoriesByName(query, map); } catch (IOException e) { @@ -87,7 +87,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { long now = System.currentTimeMillis(); SearchPoiTypeFilter poiTypeFilter = new SearchPoiTypeFilter(){ @Override - public boolean accept(AmenityType type, String subcategory) { + public boolean accept(PoiCategory type, String subcategory) { return filter.acceptTypeSubtype(type, subcategory); } }; @@ -112,7 +112,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { long now = System.currentTimeMillis(); SearchPoiTypeFilter poiTypeFilter = new SearchPoiTypeFilter(){ @Override - public boolean accept(AmenityType type, String subcategory) { + public boolean accept(PoiCategory type, String subcategory) { return filter.acceptTypeSubtype(type, subcategory); } }; diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 479943dd71..2480bff395 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -27,7 +27,6 @@ import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.CachedOsmandIndexes; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.data.TransportStop; @@ -35,6 +34,7 @@ import net.osmand.map.ITileSource; import net.osmand.map.MapTileDownloader; import net.osmand.map.MapTileDownloader.DownloadRequest; import net.osmand.map.OsmandRegions; +import net.osmand.osm.PoiCategory; import net.osmand.plus.BusyIndicator; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -812,8 +812,8 @@ public class ResourceManager { return amenities; } - public Map> searchAmenityCategoriesByName(String searchQuery, double lat, double lon) { - Map> map = new LinkedHashMap>(); + public Map> searchAmenityCategoriesByName(String searchQuery, double lat, double lon) { + Map> map = new LinkedHashMap>(); for (AmenityIndexRepository index : amenityRepositories) { if (index instanceof AmenityIndexRepositoryBinary) { if (index.checkContains(lat, lon)) { diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 2c6d80ea12..3b331d6e5d 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -8,11 +8,11 @@ import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.access.AccessibleToast; import net.osmand.data.Amenity; -import net.osmand.data.AmenityType; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; -import net.osmand.osm.MapRenderingTypes; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiType; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.OsmAndFormatter; @@ -21,7 +21,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.poi.PoiLegacyFilter; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.resources.ResourceManager; -import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.MapTextLayer.MapTextProvider; @@ -206,6 +205,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon data.queryNewData(tileBox); objects = data.getResults(); if (objects != null) { + MapPoiTypes poiTypes = view.getApplication().getPoiTypes(); int r = getRadiusPoi(tileBox); for (Amenity o : objects) { int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation() @@ -215,13 +215,15 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon canvas.drawCircle(x, y, r, pointAltUI); canvas.drawCircle(x, y, r, point); String id = null; - StringBuilder tag = new StringBuilder(); - StringBuilder value = new StringBuilder(); - MapRenderingTypes.getDefault().getAmenityTagValue(o.getType(), o.getSubType(), tag, value); - if (RenderingIcons.containsIcon(tag + "_" + value)) { - id = tag + "_" + value; - } else if (RenderingIcons.containsIcon(tag.toString())) { - id = tag.toString(); + PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType()); + if (st != null) { + if (RenderingIcons.containsIcon(st.getKeyName())) { + id = st.getKeyName(); + } else if (RenderingIcons.containsIcon(st.getOsmTag() + "_" + st.getOsmValue())) { + id = st.getOsmTag() + "_" + st.getOsmValue(); + } else if (RenderingIcons.containsIcon(st.getOsmValue())) { + id = st.getOsmValue(); + } } if (id != null) { Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id); @@ -301,7 +303,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon Builder bs = new AlertDialog.Builder(view.getContext()); bs.setTitle(OsmAndFormatter.getPoiSimpleFormat(a, view.getApplication(), view.getSettings().usingEnglishNames())); - if (a.getType() == AmenityType.OSMWIKI) { + if (a.getType().isWiki()) { bs.setMessage(a.getDescription()); } else { bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false));