use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class AmenityMenuBuilder method buildInternal.
@Override
public void buildInternal(View view) {
boolean hasWiki = false;
MapPoiTypes poiTypes = app.getPoiTypes();
String preferredLang = getPreferredMapAppLang();
List<AmenityInfoRow> infoRows = new LinkedList<>();
List<AmenityInfoRow> descriptions = new LinkedList<>();
Map<String, List<PoiType>> poiAdditionalCategories = new HashMap<>();
AmenityInfoRow cuisineRow = null;
for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
int iconId = 0;
Drawable icon = null;
int textColor = 0;
String key = e.getKey();
String vl = e.getValue();
if (key.equals("image") || key.equals("mapillary") || key.equals("subway_region")) {
continue;
}
String textPrefix = "";
CollapsableView collapsableView = null;
boolean collapsable = false;
boolean isWiki = false;
boolean isText = false;
boolean isDescription = false;
boolean needLinks = !"population".equals(key);
boolean isPhoneNumber = false;
boolean isUrl = false;
boolean isCuisine = false;
int poiTypeOrder = 0;
String poiTypeKeyName = "";
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) {
pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl);
}
PoiType pType = null;
if (pt != null) {
pType = (PoiType) pt;
if (pType.isFilterOnly()) {
continue;
}
poiTypeOrder = pType.getOrder();
poiTypeKeyName = pType.getKeyName();
}
if (pType != null && !pType.isText()) {
String categoryName = pType.getPoiAdditionalCategory();
if (!Algorithms.isEmpty(categoryName)) {
List<PoiType> poiAdditionalCategoryTypes = poiAdditionalCategories.get(categoryName);
if (poiAdditionalCategoryTypes == null) {
poiAdditionalCategoryTypes = new ArrayList<>();
poiAdditionalCategories.put(categoryName, poiAdditionalCategoryTypes);
}
poiAdditionalCategoryTypes.add(pType);
continue;
}
}
if (amenity.getType().isWiki()) {
if (!hasWiki) {
String lng = amenity.getContentLanguage("content", preferredLang, "en");
if (Algorithms.isEmpty(lng)) {
lng = "en";
}
final String langSelected = lng;
String content = amenity.getDescription(langSelected);
vl = (content != null) ? Html.fromHtml(content).toString() : "";
if (vl.length() > 300) {
vl = vl.substring(0, 300);
}
hasWiki = true;
isWiki = true;
needLinks = false;
} else {
continue;
}
} else if (key.startsWith("name:")) {
continue;
} else if (Amenity.OPENING_HOURS.equals(key)) {
iconId = R.drawable.ic_action_time;
collapsableView = getCollapsableTextView(view.getContext(), true, amenity.getOpeningHours());
collapsable = true;
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (rs != null) {
vl = rs.toLocalString();
Calendar inst = Calendar.getInstance();
inst.setTimeInMillis(System.currentTimeMillis());
boolean opened = rs.isOpenedForTime(inst);
if (opened) {
textColor = R.color.color_ok;
} else {
textColor = R.color.color_invalid;
}
}
needLinks = false;
} else if (Amenity.PHONE.equals(key)) {
iconId = R.drawable.ic_action_call_dark;
isPhoneNumber = true;
} else if (Amenity.WEBSITE.equals(key)) {
iconId = R.drawable.ic_world_globe_dark;
isUrl = true;
} else if (Amenity.CUISINE.equals(key)) {
isCuisine = true;
iconId = R.drawable.ic_action_cuisine;
StringBuilder sb = new StringBuilder();
for (String c : e.getValue().split(";")) {
if (sb.length() > 0) {
sb.append(", ");
sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
} else {
sb.append(poiTypes.getPoiTranslation("cuisine_" + c));
}
}
textPrefix = app.getString(R.string.poi_cuisine);
vl = sb.toString();
} else if (key.contains(Amenity.ROUTE)) {
continue;
} else {
if (key.contains(Amenity.DESCRIPTION)) {
iconId = R.drawable.ic_action_note_dark;
} else {
iconId = R.drawable.ic_action_info_dark;
}
if (pType != null) {
poiTypeOrder = pType.getOrder();
poiTypeKeyName = pType.getKeyName();
if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
icon = getRowIcon(view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue());
}
if (!pType.isText()) {
vl = pType.getTranslation();
} else {
isText = true;
isDescription = iconId == R.drawable.ic_action_note_dark;
textPrefix = pType.getTranslation();
vl = amenity.unzipContent(e.getValue());
}
if (!isDescription && icon == null) {
icon = getRowIcon(view.getContext(), pType.getIconKeyName());
if (isText && icon != null) {
textPrefix = "";
}
}
if (icon == null && isText) {
iconId = R.drawable.ic_action_note_dark;
}
} else {
textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey());
vl = amenity.unzipContent(e.getValue());
}
}
if (vl.startsWith("http://") || vl.startsWith("https://") || vl.startsWith("HTTP://") || vl.startsWith("HTTPS://")) {
isUrl = true;
}
boolean matchWidthDivider = !isDescription && isWiki;
AmenityInfoRow row;
if (isDescription) {
row = new AmenityInfoRow(key, R.drawable.ic_action_note_dark, textPrefix, vl, collapsable, collapsableView, 0, false, true, true, 0, "", false, false, matchWidthDivider, 0);
} else if (icon != null) {
row = new AmenityInfoRow(key, icon, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
} else {
row = new AmenityInfoRow(key, iconId, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
}
if (isDescription) {
descriptions.add(row);
} else {
if (!isCuisine) {
infoRows.add(row);
} else {
cuisineRow = row;
}
}
}
if (cuisineRow != null) {
boolean hasCuisineOrDish = poiAdditionalCategories.get(Amenity.CUISINE) != null || poiAdditionalCategories.get(Amenity.DISH) != null;
if (!hasCuisineOrDish) {
infoRows.add(cuisineRow);
}
}
for (Map.Entry<String, List<PoiType>> e : poiAdditionalCategories.entrySet()) {
String categoryName = e.getKey();
List<PoiType> categoryTypes = e.getValue();
if (categoryTypes.size() > 0) {
Drawable icon;
PoiType pType = categoryTypes.get(0);
String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
String poiAddidionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
icon = getRowIcon(view.getContext(), poiAddidionalIconName);
if (icon == null) {
icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
}
if (icon == null) {
icon = getRowIcon(view.getContext(), pType.getIconKeyName());
}
if (icon == null) {
icon = getRowIcon(R.drawable.ic_action_note_dark);
}
StringBuilder sb = new StringBuilder();
for (PoiType pt : categoryTypes) {
if (sb.length() > 0) {
sb.append(" • ");
}
sb.append(pt.getTranslation());
}
boolean cuisineOrDish = categoryName.equals(Amenity.CUISINE) || categoryName.equals(Amenity.DISH);
CollapsableView collapsableView = getPoiAdditionalCollapsableView(view.getContext(), true, categoryTypes, cuisineOrDish ? cuisineRow : null);
infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, pType.getPoiAdditionalCategoryTranslation(), sb.toString(), true, collapsableView, 0, false, false, false, pType.getOrder(), pType.getKeyName(), false, false, false, 1));
}
}
Collections.sort(infoRows, new Comparator<AmenityInfoRow>() {
@Override
public int compare(AmenityInfoRow row1, AmenityInfoRow row2) {
if (row1.order < row2.order) {
return -1;
} else if (row1.order == row2.order) {
return row1.name.compareTo(row2.name);
} else {
return 1;
}
}
});
for (AmenityInfoRow info : infoRows) {
buildAmenityRow(view, info);
}
String langSuffix = ":" + preferredLang;
AmenityInfoRow descInPrefLang = null;
for (AmenityInfoRow desc : descriptions) {
if (desc.key.length() > langSuffix.length() && desc.key.substring(desc.key.length() - langSuffix.length(), desc.key.length()).equals(langSuffix)) {
descInPrefLang = desc;
break;
}
}
if (descInPrefLang != null) {
descriptions.remove(descInPrefLang);
descriptions.add(0, descInPrefLang);
}
for (AmenityInfoRow info : descriptions) {
buildAmenityRow(view, info);
}
if (processNearstWiki() && nearestWiki.size() > 0) {
AmenityInfoRow wikiInfo = new AmenityInfoRow("nearest_wiki", R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, getCollapsableWikiView(view.getContext(), true), 0, false, false, false, 1000, null, false, false, false, 0);
buildAmenityRow(view, wikiInfo);
}
OsmandSettings st = ((OsmandApplication) mapActivity.getApplicationContext()).getSettings();
boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
if (osmEditingEnabled && amenity.getId() != null && amenity.getId() > 0 && (amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) {
String link;
if (amenity.getId() % 2 == 0) {
link = "https://www.openstreetmap.org/node/";
} else {
link = "https://www.openstreetmap.org/way/";
}
buildRow(view, R.drawable.ic_action_info_dark, null, link + (amenity.getId() >> 1), 0, false, null, true, 0, true, null, false);
}
buildRow(view, R.drawable.ic_action_get_my_location, null, PointDescription.getLocationName(app, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", " "), 0, false, null, false, 0, false, null, false);
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class OsmAndFormatter method getAmenityDescriptionContent.
public static String getAmenityDescriptionContent(OsmandApplication ctx, Amenity amenity, boolean shortDescription) {
StringBuilder d = new StringBuilder();
if (amenity.getType().isWiki()) {
return "";
}
MapPoiTypes poiTypes = ctx.getPoiTypes();
for (Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
String key = e.getKey();
String vl = e.getValue();
if (key.startsWith("name:")) {
continue;
} else if (vl.length() >= 150) {
if (shortDescription) {
continue;
}
} 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)) {
d.append(ctx.getString(R.string.website) + ": ");
} else {
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(e.getKey());
if (pt != null) {
if (pt instanceof PoiType && !((PoiType) pt).isText()) {
vl = pt.getTranslation();
} else {
vl = pt.getTranslation() + ": " + amenity.unzipContent(e.getValue());
}
} else {
vl = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey()) + ": " + amenity.unzipContent(e.getValue());
}
}
d.append(vl).append('\n');
}
return d.toString().trim();
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class AppInitializer method initPoiTypes.
private void initPoiTypes() {
if (app.getAppPath("poi_types.xml").exists()) {
app.poiTypes.init(app.getAppPath("poi_types.xml").getAbsolutePath());
} else {
app.poiTypes.init();
}
final Resources en = getLocalizedResources("en");
app.poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {
@Override
public String getTranslation(AbstractPoiType type) {
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getTranslation(baseLangType) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
}
return getTranslation(type.getIconKeyName());
}
@Override
public String getTranslation(String keyName) {
try {
Field f = R.string.class.getField("poi_" + keyName);
if (f != null) {
Integer in = (Integer) f.get(null);
return app.getString(in);
}
} catch (Exception e) {
}
return null;
}
@Override
public String getSynonyms(AbstractPoiType type) {
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getSynonyms(baseLangType);
}
return getSynonyms(type.getIconKeyName());
}
@Override
public String getSynonyms(String keyName) {
try {
Field f = R.string.class.getField("synonyms_poi_" + keyName);
if (f != null) {
Integer in = (Integer) f.get(null);
return app.getString(in);
}
} catch (Exception e) {
}
return "";
}
@Override
public String getEnTranslation(AbstractPoiType type) {
AbstractPoiType baseLangType = type.getBaseLangType();
if (baseLangType != null) {
return getEnTranslation(baseLangType) + " (" + app.getLangTranslation(type.getLang()).toLowerCase() + ")";
}
return getEnTranslation(type.getIconKeyName());
}
@Override
public String getEnTranslation(String keyName) {
if (en == null) {
return Algorithms.capitalizeFirstLetter(keyName.replace('_', ' '));
}
try {
Field f = R.string.class.getField("poi_" + keyName);
if (f != null) {
Integer in = (Integer) f.get(null);
return en.getString(in);
}
} catch (Exception e) {
}
return null;
}
});
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class PoiUIFilter method fillPoiAdditionals.
private void fillPoiAdditionals(AbstractPoiType pt, boolean allFromCategory) {
for (PoiType add : pt.getPoiAdditionals()) {
poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
}
if (pt instanceof PoiCategory && allFromCategory) {
for (PoiFilter pf : ((PoiCategory) pt).getPoiFilters()) {
fillPoiAdditionals(pf, true);
}
for (PoiType ps : ((PoiCategory) pt).getPoiTypes()) {
fillPoiAdditionals(ps, false);
}
} else if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
fillPoiAdditionals(ps, false);
}
}
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class OpenstreetmapLocalUtil method loadNode.
@Override
public Node loadNode(Amenity n) {
PoiType poiType = n.getType().getPoiTypeByKeyName(n.getSubType());
if (n.getId() % 2 == 1 || poiType == null) {
// that's way id
return null;
}
long nodeId = n.getId() >> 1;
// EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId);
entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation());
if (poiType.getOsmTag2() != null) {
entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
if (!Algorithms.isEmpty(n.getName())) {
entity.putTagNoLC(OSMTagKey.NAME.getValue(), n.getName());
}
if (!Algorithms.isEmpty(n.getOpeningHours())) {
entity.putTagNoLC(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours());
}
for (Map.Entry<String, String> entry : n.getAdditionalInfo().entrySet()) {
AbstractPoiType abstractPoi = MapPoiTypes.getDefault().getAnyPoiAdditionalTypeByKey(entry.getKey());
if (abstractPoi != null && abstractPoi instanceof PoiType) {
PoiType p = (PoiType) abstractPoi;
if (!p.isNotEditableOsm() && !Algorithms.isEmpty(p.getOsmTag())) {
entity.putTagNoLC(p.getOsmTag(), entry.getValue());
}
}
}
// check whether this is node (because id of node could be the same as relation)
if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
return entity;
}
return null;
}
Aggregations