diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index 92be128f99..256958cd9d 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -6,6 +6,7 @@ import java.util.Map; import net.osmand.Location; import net.osmand.osm.PoiCategory; +import net.osmand.util.Algorithms; public class Amenity extends MapObject { @@ -14,6 +15,7 @@ public class Amenity extends MapObject { public static final String PHONE = "phone"; public static final String DESCRIPTION = "description"; public static final String OPENING_HOURS = "opening_hours"; + public static final String CONTENT = "content"; private static final long serialVersionUID = 132083949926339552L; private String subType; @@ -118,8 +120,57 @@ public class Amenity extends MapObject { setAdditionalInfo(PHONE, phone); } - public String getDescription() { - return getAdditionalInfo(DESCRIPTION); + public String getName(String lang) { + if (lang != null) { + String translateName; + if (lang.equals("en")) { + translateName = getEnName(); + } else { + translateName = getAdditionalInfo("name:" + lang); + } + if (!Algorithms.isEmpty(translateName)) { + return translateName; + } + } + if (!Algorithms.isEmpty(getName())) { + return getName(); + } + for (String nm : additionalInfo.keySet()) { + if (nm.startsWith("name:")) { + return getAdditionalInfo(nm); + } + } + return ""; + } + public String getContentLang(String tag, String lang) { + if (lang != null) { + String translateName = getAdditionalInfo(tag + ":" + lang); + if (!Algorithms.isEmpty(translateName)) { + return translateName; + } + } + String plainName = getAdditionalInfo(tag); + if (!Algorithms.isEmpty(plainName)) { + return plainName; + } + String enName = getAdditionalInfo(tag + ":en"); + if (!Algorithms.isEmpty(enName)) { + return enName; + } + for (String nm : additionalInfo.keySet()) { + if (nm.startsWith(tag + ":")) { + return getAdditionalInfo(nm); + } + } + return null; + } + + public String getDescription(String lang) { + String info = getContentLang(DESCRIPTION, lang); + if(!Algorithms.isEmpty(info)) { + return info; + } + return getContentLang(CONTENT, lang); } public void setDescription(String description) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 2862bf1026..f548be9765 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -160,7 +160,7 @@ public class OsmAndFormatter { return ""; } - public static String getPoiStringWithoutType(Amenity amenity, boolean en) { + public static String getPoiStringWithoutType(Amenity amenity, String locale) { PoiCategory pc = amenity.getType(); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); String nm = amenity.getSubType(); @@ -169,7 +169,7 @@ public class OsmAndFormatter { } else if(nm != null){ nm = Algorithms.capitalizeFirstLetterAndLowercase(nm.replace('_', ' ')); } - String n = amenity.getName(en); + String n = amenity.getName(locale); if (n.indexOf(nm) != -1) { // type is contained in name e.g. // n = "Bakery the Corner" diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index d25a9e3aaa..196a2e5dc7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -176,7 +176,7 @@ public class GeoIntentActivity extends OsmandListActivity { private PointDescription getString(MapObject o) { if (o instanceof Amenity) { return new PointDescription(PointDescription.POINT_TYPE_POI, - OsmAndFormatter.getPoiStringWithoutType((Amenity) o, false)); + OsmAndFormatter.getPoiStringWithoutType((Amenity) o, ((OsmandApplication) getApplication()).getSettings().MAP_PREFERRED_LOCALE.get())); } if (o instanceof Street) { return new PointDescription(PointDescription.POINT_TYPE_ADDRESS, ((Street) o).getCity().getName() + " " + o.getName()); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 9fc991296f..58471b9d86 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -541,7 +541,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); final OsmandSettings settings = app.getSettings(); String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, - settings.usingEnglishNames()); + app.getSettings().MAP_PREFERRED_LOCALE.get()); PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat); int z = Math.max(16, settings.getLastKnownMapZoom()); final PopupMenu optionsMenu = new PopupMenu(this, view); @@ -566,7 +566,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa // Create dialog Builder bs = new AlertDialog.Builder(view.getContext()); bs.setTitle(OsmAndFormatter.getPoiStringWithoutType(amenity, - settings.usingEnglishNames())); + app.getSettings().MAP_PREFERRED_LOCALE.get())); bs.setMessage(spannable); AlertDialog dialog = bs.show(); @@ -583,7 +583,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa item.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - showPOIDetails(amenity, settings.usingEnglishNames()); + showPOIDetails(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get()); return true; } }); @@ -804,7 +804,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa if (mes != null) { distance = " " + OsmAndFormatter.getFormattedDistance((int) mes[0], getMyApplication()) + " "; //$NON-NLS-1$ } - String poiType = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().usingEnglishNames()); + String poiType = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get()); label.setText(poiType); distanceText.setText(distance); return (row); @@ -852,9 +852,9 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } } - private void showPOIDetails(final Amenity amenity, boolean en) { + private void showPOIDetails(final Amenity amenity, String lang) { AlertDialog.Builder b = new AlertDialog.Builder(SearchPOIActivity.this); - b.setTitle(OsmAndFormatter.getPoiStringWithoutType(amenity, en)); + b.setTitle(OsmAndFormatter.getPoiStringWithoutType(amenity, lang)); b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index a6240a39f8..8ac2be0a98 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -774,7 +774,7 @@ public class WaypointHelper { @Override public PointDescription getPointDescription(Context ctx) { return new PointDescription(PointDescription.POINT_TYPE_POI, - OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().usingEnglishNames())); + OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get())); } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java index 1efa1ae3f5..962f3faffa 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java @@ -180,7 +180,7 @@ public class EditingPOIDialogProvider implements DialogProvider { private void prepareDeleteDialog(Dialog dlg, Bundle args) { Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template), - OsmAndFormatter.getPoiStringWithoutType(a, settings.usingEnglishNames()))); + OsmAndFormatter.getPoiStringWithoutType(a, settings.MAP_PREFERRED_LOCALE.get()))); } private Dialog createDeleteDialog(final Bundle args) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 22120f3637..5be0f3988d 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -1078,22 +1078,21 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements createMenuItem(oldMenu, SETTINGS_ID, R.string.shared_string_settings, R.drawable.ic_action_settings, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); boolean portrait = AndroidUiHelper.isOrientationPortrait(this); - if (portrait) { - menu = getClearToolbar(true).getMenu(); - } else { - getClearToolbar(false); + if (selectedObject == null) { + if (portrait) { + menu = getClearToolbar(true).getMenu(); + } else { + getClearToolbar(false); + } + createMenuItem(menu, CONNECT_TO, R.string.osmo_connect, 0, 0,/* R.drawable.ic_action_marker_light, */ + MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + // createMenuItem(menu, SHARE_SESSION, R.string.osmo_share_session, + // R.drawable.ic_action_gshare_dark, + // MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + createMenuItem(menu, CREATE_GROUP, R.string.osmo_create_group, 0, 0, + // R.drawable.ic_group_add, + MenuItemCompat.SHOW_AS_ACTION_ALWAYS); } - createMenuItem(menu, CONNECT_TO, R.string.osmo_connect, - 0, 0,/*R.drawable.ic_action_marker_light,*/ - MenuItemCompat.SHOW_AS_ACTION_ALWAYS); -// createMenuItem(menu, SHARE_SESSION, R.string.osmo_share_session, -// R.drawable.ic_action_gshare_dark, -// MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - createMenuItem(menu, CREATE_GROUP, R.string.osmo_create_group, - 0, 0, -// R.drawable.ic_group_add, - MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - return super.onCreateOptionsMenu(menu); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index 03e2da96a2..f34ae9a374 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -295,13 +295,12 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; - final boolean en = app.getSettings().usingEnglishNames(); return new AmenityNameFilter() { @Override public boolean accept(Amenity a) { if (sm != null) { - String lower = OsmAndFormatter.getPoiStringWithoutType(a, en); + String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get()); if (!sm.matches(lower)) { return false; } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index e2fe66d21c..547cf47b19 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -159,7 +159,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) { String format = OsmAndFormatter.getPoiStringWithoutType(n, - view.getSettings().usingEnglishNames()); + view.getSettings().MAP_PREFERRED_LOCALE.get()); res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n, true)); return res; } @@ -310,9 +310,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon private void showDescriptionDialog(Amenity a) { Builder bs = new AlertDialog.Builder(view.getContext()); - bs.setTitle(OsmAndFormatter.getPoiStringWithoutType(a, view.getSettings().usingEnglishNames())); + bs.setTitle(OsmAndFormatter.getPoiStringWithoutType(a, view.getSettings().MAP_PREFERRED_LOCALE.get())); if (a.getType().isWiki()) { - bs.setMessage(a.getDescription()); + bs.setMessage(a.getDescription(view.getSettings().MAP_PREFERRED_LOCALE.get())); } else { bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false)); }