use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class SearchPoiFilterFragment method onListItemClick.
@Override
public void onListItemClick(ListView listView, View v, int position, long id) {
final Object item = getListAdapter().getItem(position);
ResourceManager rm = getApp().getResourceManager();
if (!rm.containsAmenityRepositoryToSearch(false)) {
Toast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
return;
}
if (item instanceof PoiUIFilter) {
PoiUIFilter model = ((PoiUIFilter) item);
if (PoiUIFilter.BY_NAME_FILTER_ID.equals(model.getFilterId()) || model instanceof NominatimPoiFilter) {
model.setFilterByName(searchEditText.getText().toString());
} else {
model.setFilterByName(model.getSavedFilterByName());
}
showFilterActivity(model.getFilterId());
} else {
PoiUIFilter custom = getApp().getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ((AbstractPoiType) item).getKeyName());
if (custom != null) {
if (item instanceof PoiType && ((PoiType) item).isAdditional()) {
// it is already set
} else {
custom.setFilterByName(null);
}
custom.clearFilter();
custom.updateTypesToAccept(((AbstractPoiType) item));
showFilterActivity(custom.getFilterId());
}
}
}
use of net.osmand.osm.PoiType 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.PoiType in project Osmand by osmandapp.
the class AmenityMenuController method getRightIconId.
private static int getRightIconId(Amenity amenity) {
String id = null;
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
if (st != null) {
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
id = st.getIconKeyName();
} else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
id = st.getOsmTag() + "_" + st.getOsmValue();
}
}
if (id != null) {
return RenderingIcons.getBigIconResourceId(id);
}
return 0;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class OsmAndFormatter method getPoiStringWithoutType.
public static String getPoiStringWithoutType(Amenity amenity, String locale, boolean transliterate) {
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
String nm = amenity.getSubType();
if (pt != null) {
nm = pt.getTranslation();
} else if (nm != null) {
nm = Algorithms.capitalizeFirstLetterAndLowercase(nm.replace('_', ' '));
}
String n = amenity.getName(locale, transliterate);
if (n.indexOf(nm) != -1) {
// no need to repeat this
return n;
}
if (n.length() == 0) {
return nm;
}
// $NON-NLS-1$
return nm + " " + n;
}
use of net.osmand.osm.PoiType 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();
}
Aggregations