Fix osmo group

This commit is contained in:
Victor Shcherb 2015-05-27 00:09:48 +02:00
parent 524743cf4a
commit d478d14a73
9 changed files with 82 additions and 33 deletions

View file

@ -6,6 +6,7 @@ import java.util.Map;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.util.Algorithms;
public class Amenity extends MapObject { public class Amenity extends MapObject {
@ -14,6 +15,7 @@ public class Amenity extends MapObject {
public static final String PHONE = "phone"; public static final String PHONE = "phone";
public static final String DESCRIPTION = "description"; public static final String DESCRIPTION = "description";
public static final String OPENING_HOURS = "opening_hours"; public static final String OPENING_HOURS = "opening_hours";
public static final String CONTENT = "content";
private static final long serialVersionUID = 132083949926339552L; private static final long serialVersionUID = 132083949926339552L;
private String subType; private String subType;
@ -118,8 +120,57 @@ public class Amenity extends MapObject {
setAdditionalInfo(PHONE, phone); setAdditionalInfo(PHONE, phone);
} }
public String getDescription() { public String getName(String lang) {
return getAdditionalInfo(DESCRIPTION); 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) { public void setDescription(String description) {

View file

@ -160,7 +160,7 @@ public class OsmAndFormatter {
return ""; return "";
} }
public static String getPoiStringWithoutType(Amenity amenity, boolean en) { public static String getPoiStringWithoutType(Amenity amenity, String locale) {
PoiCategory pc = amenity.getType(); PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
String nm = amenity.getSubType(); String nm = amenity.getSubType();
@ -169,7 +169,7 @@ public class OsmAndFormatter {
} else if(nm != null){ } else if(nm != null){
nm = Algorithms.capitalizeFirstLetterAndLowercase(nm.replace('_', ' ')); nm = Algorithms.capitalizeFirstLetterAndLowercase(nm.replace('_', ' '));
} }
String n = amenity.getName(en); String n = amenity.getName(locale);
if (n.indexOf(nm) != -1) { if (n.indexOf(nm) != -1) {
// type is contained in name e.g. // type is contained in name e.g.
// n = "Bakery the Corner" // n = "Bakery the Corner"

View file

@ -176,7 +176,7 @@ public class GeoIntentActivity extends OsmandListActivity {
private PointDescription getString(MapObject o) { private PointDescription getString(MapObject o) {
if (o instanceof Amenity) { if (o instanceof Amenity) {
return new PointDescription(PointDescription.POINT_TYPE_POI, 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) { if (o instanceof Street) {
return new PointDescription(PointDescription.POINT_TYPE_ADDRESS, ((Street) o).getCity().getName() + " " + o.getName()); return new PointDescription(PointDescription.POINT_TYPE_ADDRESS, ((Street) o).getCity().getName() + " " + o.getName());

View file

@ -541,7 +541,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity,
settings.usingEnglishNames()); app.getSettings().MAP_PREFERRED_LOCALE.get());
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat); PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
int z = Math.max(16, settings.getLastKnownMapZoom()); int z = Math.max(16, settings.getLastKnownMapZoom());
final PopupMenu optionsMenu = new PopupMenu(this, view); final PopupMenu optionsMenu = new PopupMenu(this, view);
@ -566,7 +566,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
// Create dialog // Create dialog
Builder bs = new AlertDialog.Builder(view.getContext()); Builder bs = new AlertDialog.Builder(view.getContext());
bs.setTitle(OsmAndFormatter.getPoiStringWithoutType(amenity, bs.setTitle(OsmAndFormatter.getPoiStringWithoutType(amenity,
settings.usingEnglishNames())); app.getSettings().MAP_PREFERRED_LOCALE.get()));
bs.setMessage(spannable); bs.setMessage(spannable);
AlertDialog dialog = bs.show(); AlertDialog dialog = bs.show();
@ -583,7 +583,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
item.setOnMenuItemClickListener(new OnMenuItemClickListener() { item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
showPOIDetails(amenity, settings.usingEnglishNames()); showPOIDetails(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get());
return true; return true;
} }
}); });
@ -804,7 +804,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
if (mes != null) { if (mes != null) {
distance = " " + OsmAndFormatter.getFormattedDistance((int) mes[0], getMyApplication()) + " "; //$NON-NLS-1$ 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); label.setText(poiType);
distanceText.setText(distance); distanceText.setText(distance);
return (row); 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); 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() { b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {

View file

@ -774,7 +774,7 @@ public class WaypointHelper {
@Override @Override
public PointDescription getPointDescription(Context ctx) { public PointDescription getPointDescription(Context ctx) {
return new PointDescription(PointDescription.POINT_TYPE_POI, return new PointDescription(PointDescription.POINT_TYPE_POI,
OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().usingEnglishNames())); OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get()));
} }
@Override @Override

View file

@ -180,7 +180,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
private void prepareDeleteDialog(Dialog dlg, Bundle args) { private void prepareDeleteDialog(Dialog dlg, Bundle args) {
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template), 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) { private Dialog createDeleteDialog(final Bundle args) {

View file

@ -1078,22 +1078,21 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
createMenuItem(oldMenu, SETTINGS_ID, R.string.shared_string_settings, R.drawable.ic_action_settings, createMenuItem(oldMenu, SETTINGS_ID, R.string.shared_string_settings, R.drawable.ic_action_settings,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS); MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
boolean portrait = AndroidUiHelper.isOrientationPortrait(this); boolean portrait = AndroidUiHelper.isOrientationPortrait(this);
if (portrait) { if (selectedObject == null) {
menu = getClearToolbar(true).getMenu(); if (portrait) {
} else { menu = getClearToolbar(true).getMenu();
getClearToolbar(false); } 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); return super.onCreateOptionsMenu(menu);
} }

View file

@ -295,13 +295,12 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
final CollatorStringMatcher sm = final CollatorStringMatcher sm =
nmFilter.length() > 0 ? nmFilter.length() > 0 ?
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
final boolean en = app.getSettings().usingEnglishNames();
return new AmenityNameFilter() { return new AmenityNameFilter() {
@Override @Override
public boolean accept(Amenity a) { public boolean accept(Amenity a) {
if (sm != null) { if (sm != null) {
String lower = OsmAndFormatter.getPoiStringWithoutType(a, en); String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get());
if (!sm.matches(lower)) { if (!sm.matches(lower)) {
return false; return false;
} }

View file

@ -159,7 +159,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) { private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) {
String format = OsmAndFormatter.getPoiStringWithoutType(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)); res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n, true));
return res; return res;
} }
@ -310,9 +310,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private void showDescriptionDialog(Amenity a) { private void showDescriptionDialog(Amenity a) {
Builder bs = new AlertDialog.Builder(view.getContext()); 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()) { if (a.getType().isWiki()) {
bs.setMessage(a.getDescription()); bs.setMessage(a.getDescription(view.getSettings().MAP_PREFERRED_LOCALE.get()));
} else { } else {
bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false)); bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false));
} }