From 99f2d384830a46a0d24b3cad16aa336e6a0d0710 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 24 Nov 2013 19:45:00 +0100 Subject: [PATCH] Update osmand application --- OsmAnd-java/src/net/osmand/data/Amenity.java | 23 +++++++++------- .../src/net/osmand/plus/OsmAndFormatter.java | 25 +++++++++++++++++ .../activities/search/SearchPOIActivity.java | 27 +++++-------------- .../net/osmand/plus/views/POIMapLayer.java | 12 +-------- 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index a91428a51c..284b28e8d4 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -7,6 +7,11 @@ import java.util.Map; public class Amenity extends MapObject { + public static final String WEBSITE = "website"; + public static final String PHONE = "phone"; + public static final String DESCRIPTION = "description"; + public static final String OPENING_HOURS = "opening_hours"; + private static final long serialVersionUID = 132083949926339552L; private String subType; private AmenityType type; @@ -54,7 +59,7 @@ public class Amenity extends MapObject { public void setAdditionalInfo(Map additionalInfo) { this.additionalInfo = additionalInfo; - openingHours = additionalInfo.get("opening_hours"); + openingHours = additionalInfo.get(OPENING_HOURS); } @@ -63,7 +68,7 @@ public class Amenity extends MapObject { this.additionalInfo = new LinkedHashMap(); } this.additionalInfo.put(tag, value); - if("opening_hours".equals(tag)) { + if(OPENING_HOURS.equals(tag)) { this.openingHours = value; } } @@ -75,31 +80,31 @@ public class Amenity extends MapObject { } public String getSite() { - return getAdditionalInfo("website"); + return getAdditionalInfo(WEBSITE); } public void setSite(String site) { - setAdditionalInfo("website", site); + setAdditionalInfo(WEBSITE, site); } public String getPhone() { - return getAdditionalInfo("phone"); + return getAdditionalInfo(PHONE); } public void setPhone(String phone) { - setAdditionalInfo("phone", phone); + setAdditionalInfo(PHONE, phone); } public String getDescription() { - return getAdditionalInfo("description"); + return getAdditionalInfo(DESCRIPTION); } public void setDescription(String description) { - setAdditionalInfo("description", description); + setAdditionalInfo(DESCRIPTION, description); } public void setOpeningHours(String openingHours) { - setAdditionalInfo("opening_hours", openingHours); + setAdditionalInfo(OPENING_HOURS, openingHours); } diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index a872347b2c..45366e9b6a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -2,6 +2,7 @@ package net.osmand.plus; import java.lang.reflect.Field; import java.text.MessageFormat; +import java.util.Map.Entry; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; @@ -126,6 +127,8 @@ public class OsmAndFormatter { return ctx.getString(R.string.city_type_village); case SUBURB: return ctx.getString(R.string.city_type_suburb); + default: + break; } return ""; } @@ -162,4 +165,26 @@ public class OsmAndFormatter { } return type + " " + n; //$NON-NLS-1$ } + + public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity) { + StringBuilder d = new StringBuilder(); + for(Entry e : amenity.getAdditionalInfo().entrySet()) { + String key = e.getKey(); + if(Amenity.DESCRIPTION.equals(key)) { + } else if(Amenity.OPENING_HOURS.equals(key)) { + d.append(ctx.getString(R.string.opening_hours) + " : "); + } else if(Amenity.PHONE.equals(key)) { + d.append(ctx.getString(R.string.phone) + " : "); + } else if(Amenity.WEBSITE.equals(key)) { + if(amenity.getType() == AmenityType.OSMWIKI) { + continue; + } + d.append(ctx.getString(R.string.website) + " : "); + } else { + d.append(e.getKey() + " : "); + } + d.append(e.getValue()).append('\n'); + } + return d.toString().trim(); + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index c8bacb8718..4d7ca64530 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -555,7 +555,7 @@ 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 StringBuilder d = getDescriptionContent(amenity); + final String d = getDescriptionContent(amenity); poiDescription.setOnClickListener(new OnClickListener() { @Override @@ -600,21 +600,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } - private StringBuilder getDescriptionContent(final Amenity amenity) { - StringBuilder d = new StringBuilder(); - if(amenity.getOpeningHours() != null) { - d.append(getString(R.string.opening_hours) + " : ").append(amenity.getOpeningHours()).append("\n"); - } - if(amenity.getPhone() != null) { - d.append(getString(R.string.phone) + " : ").append(amenity.getPhone()).append("\n"); - } - if(amenity.getSite() != null) { - d.append(getString(R.string.website) + " : ").append(amenity.getSite()).append("\n"); - } - if(amenity.getDescription() != null) { - d.append(amenity.getDescription()); - } - return d; + private String getDescriptionContent(final Amenity amenity) { + return OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity); } @@ -889,10 +876,10 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading); if (direction != null) attributes.add(direction); - if (amenity.getPhone() != null) - attributes.add(getString(R.string.phone) + " " + amenity.getPhone()); - if (amenity.getOpeningHours() != null) - attributes.add(getString(R.string.opening_hours) + " " + amenity.getOpeningHours()); + String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity).split("\n"); + for(String s: as) { + attributes.add(s.replace(':', ' ')); + } attributes.add(getString(R.string.navigate_point_latitude) + " " + Double.toString(amenity.getLocation().getLatitude())); attributes.add(getString(R.string.navigate_point_longitude) + " " + Double.toString(amenity.getLocation().getLongitude())); b.setItems(attributes.toArray(new String[attributes.size()]), diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index d1fe8c16d6..dfca0f9dd8 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -8,7 +8,6 @@ import java.util.List; import net.osmand.PlatformUtil; 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; @@ -111,16 +110,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); - if (n.getOpeningHours() != null) { - res.append("\n").append(view.getContext().getString(R.string.opening_hours)).append(" : ").append(n.getOpeningHours()); //$NON-NLS-1$ //$NON-NLS-2$ - } - if (n.getPhone() != null) { - res.append("\n").append(view.getContext().getString(R.string.phone)).append(" : ").append(n.getPhone()); //$NON-NLS-1$ //$NON-NLS-2$ - } - if (n.getSite() != null && n.getType() != AmenityType.OSMWIKI) { - res.append("\n").append(view.getContext().getString(R.string.website)).append(" : ").append(n.getSite()); //$NON-NLS-1$ //$NON-NLS-2$ - } + res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n)); return res; }