From a9c6f8ebd349d54b645c19d18c5fb9f8b86a37d7 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 24 Nov 2013 21:29:50 +0100 Subject: [PATCH] Support custom categories and put them into USER_DEFINED --- .../net/osmand/binary/BinaryInspector.java | 6 +++--- .../src/net/osmand/data/AmenityType.java | 21 +++++++------------ .../src/net/osmand/osm/MapRenderingTypes.java | 2 +- .../src/net/osmand/plus/OsmAndFormatter.java | 5 ++++- OsmAnd/src/net/osmand/plus/PoiFilter.java | 2 +- .../activities/search/SearchPOIActivity.java | 10 +++------ .../net/osmand/plus/views/POIMapLayer.java | 6 +++--- 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index d19bf2734f..90b84fbccc 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -55,11 +55,11 @@ public class BinaryInspector { BinaryInspector in = new BinaryInspector(); in.inspector(args); // test cases show info - /*in.inspector(new String[]{ + in.inspector(new String[]{ "-vpoi", //"-vmap", "-vmapobjects", //"-vstreets", "-bbox=14.4,50.1,14.5,50.01", - "/home/victor/projects/osmand/osm-gen/Map.obf"});*/ + "/home/victor/projects/osmand/osm-gen/Austria_europe.obf"}); } private void printToFile(String s) throws IOException { @@ -809,7 +809,7 @@ public class BinaryInspector { println("\t\t\t" + st.name + " " + (st.text ? "text":(" encoded " + st.possibleValues.size()))); } req.poiTypeFilter = null;//TODO: for test only - index.searchPoi(p, req); +// index.searchPoi(p, req); } diff --git a/OsmAnd-java/src/net/osmand/data/AmenityType.java b/OsmAnd-java/src/net/osmand/data/AmenityType.java index afbb153ba1..88c7df0113 100644 --- a/OsmAnd-java/src/net/osmand/data/AmenityType.java +++ b/OsmAnd-java/src/net/osmand/data/AmenityType.java @@ -60,12 +60,14 @@ public class AmenityType { this.ordinal = ordinal; } - public static AmenityType findRegisteredType(String s) { - return findRegisteredType(s, OTHER); - } - public static AmenityType findOrCreateTypeNoReg(String s) { - AmenityType type = findRegisteredType(s, null); + AmenityType type = null; + for (AmenityType t : amenityTypes.values()) { + if (t.name.equalsIgnoreCase(s)) { + type = t; + break; + } + } if(type == null) { type = new AmenityType(s, s, -1); } @@ -77,15 +79,6 @@ public class AmenityType { return type.ordinal >= 0; } - public static AmenityType findRegisteredType(String s, AmenityType def) { - for (AmenityType t : amenityTypes.values()) { - if (t.name.equalsIgnoreCase(s)) { - return t; - } - } - return def; - } - public static AmenityType getAndRegisterType(String name) { return reg(name, name); } diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index 040cb7e087..487417e544 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -383,7 +383,7 @@ public class MapRenderingTypes { if (poiParentCategory != null) { - rtype.poiCategory = AmenityType.findRegisteredType(poiParentCategory, null); + rtype.poiCategory = AmenityType.getAndRegisterType(poiParentCategory); rtype.poiSpecified = true; } if (poiParentPrefix != null) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 45366e9b6a..89d0ed7bcf 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -166,11 +166,14 @@ public class OsmAndFormatter { return type + " " + n; //$NON-NLS-1$ } - public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity) { + public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity, boolean shortDescription) { StringBuilder d = new StringBuilder(); for(Entry e : amenity.getAdditionalInfo().entrySet()) { String key = e.getKey(); if(Amenity.DESCRIPTION.equals(key)) { + if(amenity.getType() == AmenityType.OSMWIKI && shortDescription) { + continue; + } } else if(Amenity.OPENING_HOURS.equals(key)) { d.append(ctx.getString(R.string.opening_hours) + " : "); } else if(Amenity.PHONE.equals(key)) { diff --git a/OsmAnd/src/net/osmand/plus/PoiFilter.java b/OsmAnd/src/net/osmand/plus/PoiFilter.java index dc334b9eda..ca0f24713b 100644 --- a/OsmAnd/src/net/osmand/plus/PoiFilter.java +++ b/OsmAnd/src/net/osmand/plus/PoiFilter.java @@ -201,7 +201,7 @@ public class PoiFilter { public boolean acceptTypeSubtype(AmenityType t, String subtype){ if(!AmenityType.isRegisteredType(t)) { - t = AmenityType.OTHER; + t = AmenityType.USER_DEFINED; } if(!acceptedTypes.containsKey(t)){ return false; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 4d7ca64530..cdc6ca54a0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -555,12 +555,12 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa ActionItem poiDescription = new ActionItem(); poiDescription.setIcon(getResources().getDrawable(R.drawable.ic_action_note_light)); poiDescription.setTitle(getString(R.string.poi_context_menu_showdescription)); - final String d = getDescriptionContent(amenity); + final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false); poiDescription.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - // Build text + // Build text(amenity) // Find and format links SpannableString spannable = new SpannableString(d); @@ -600,10 +600,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } - private String getDescriptionContent(final Amenity amenity) { - return OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity); - } - static class SearchAmenityRequest { private static final int SEARCH_AGAIN = 1; @@ -876,7 +872,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading); if (direction != null) attributes.add(direction); - String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity).split("\n"); + String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false).split("\n"); for(String s: as) { attributes.add(s.replace(':', ' ')); } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 1cc2d8483d..ec8cdc2563 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -111,7 +111,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) { String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getApplication(), view.getSettings().USE_ENGLISH_NAMES.get()); - res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n)); + res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n, true)); return res; } @@ -322,7 +322,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } } }; - if(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a).length() > 0){ + if(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false).length() > 0){ adapter.item(R.string.poi_context_menu_showdescription) .icons(R.drawable.ic_action_note_dark,R.drawable.ic_action_note_light) .listen(listener).reg(); @@ -343,7 +343,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon if(a.getType() == AmenityType.OSMWIKI) { bs.setMessage(a.getDescription()); } else { - bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a)); + bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false)); } bs.show(); }