use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class ContextMenuLayer method getPublicTransportTypes.
private List<String> getPublicTransportTypes() {
if (publicTransportTypes == null) {
publicTransportTypes = new ArrayList<>();
List<PoiFilter> filters = activity.getMyApplication().getPoiTypes().getPoiCategoryByName("transportation").getPoiFilters();
for (PoiFilter poiFilter : filters) {
if (poiFilter.getKeyName().equals("public_transport")) {
for (PoiType poiType : poiFilter.getPoiTypes()) {
publicTransportTypes.add(poiType.getKeyName());
for (PoiType poiAdditionalType : poiType.getPoiAdditionals()) {
publicTransportTypes.add(poiAdditionalType.getKeyName());
}
}
}
}
}
return publicTransportTypes;
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method extractPoiAdditionals.
private void extractPoiAdditionals(Collection<PoiType> poiAdditionals, Map<String, List<PoiType>> additionalsMap, Set<String> excludedPoiAdditionalCategories, boolean extractAll) {
for (PoiType poiType : poiAdditionals) {
String category = poiType.getPoiAdditionalCategory();
if (category == null) {
category = "";
}
if (excludedPoiAdditionalCategories != null && excludedPoiAdditionalCategories.contains(category)) {
continue;
}
if (collapsedCategories.contains(category) && !extractAll) {
if (!additionalsMap.containsKey(category)) {
additionalsMap.put(category, new ArrayList<PoiType>());
}
continue;
}
boolean showAll = showAllCategories.contains(category) || extractAll;
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
if (!poiAdditionalsTranslations.containsKey(poiType)) {
poiAdditionalsTranslations.put(poiType, poiType.getTranslation());
}
if (showAll || poiType.isTopVisible() || selectedPoiAdditionals.contains(keyName.replace(' ', ':'))) {
List<PoiType> adds = additionalsMap.get(category);
if (adds == null) {
adds = new ArrayList<>();
additionalsMap.put(category, adds);
}
if (!adds.contains(poiType)) {
adds.add(poiType);
}
}
}
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class QuickSearchListItem method getTypeName.
public static String getTypeName(OsmandApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case CITY:
City city = (City) searchResult.object;
return getCityTypeStr(app, city.getType());
case POSTCODE:
return app.getString(R.string.postcode);
case VILLAGE:
city = (City) searchResult.object;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (searchResult.distRelatedObjectName > 0) {
return getCityTypeStr(app, city.getType()) + " • " + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString(R.string.shared_string_from) + " " + searchResult.localeRelatedObjectName;
} else {
return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
}
} else {
return getCityTypeStr(app, city.getType());
}
case STREET:
StringBuilder streetBuilder = new StringBuilder();
if (searchResult.localeName.endsWith(")")) {
int i = searchResult.localeName.indexOf('(');
if (i > 0) {
streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
}
}
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (streetBuilder.length() > 0) {
streetBuilder.append(", ");
}
streetBuilder.append(searchResult.localeRelatedObjectName);
}
return streetBuilder.toString();
case HOUSE:
if (searchResult.relatedObject != null) {
Street relatedStreet = (Street) searchResult.relatedObject;
if (relatedStreet.getCity() != null) {
return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
} else {
return searchResult.localeRelatedObjectName;
}
}
return "";
case STREET_INTERSECTION:
Street street = (Street) searchResult.object;
if (street.getCity() != null) {
return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
}
return "";
case POI_TYPE:
String res = "";
if (searchResult.object instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
if (abstractPoiType instanceof PoiCategory) {
res = "";
} else if (abstractPoiType instanceof PoiFilter) {
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
} else if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType;
res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
if (res == null) {
res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
}
if (res == null) {
res = "";
}
} else {
res = "";
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
res = ((CustomSearchPoiFilter) searchResult.object).getName();
}
return res;
case POI:
Amenity amenity = (Amenity) searchResult.object;
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
String typeStr = amenity.getSubType();
if (pt != null) {
typeStr = pt.getTranslation();
} else if (typeStr != null) {
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
}
return typeStr;
case LOCATION:
LatLon latLon = searchResult.location;
if (latLon != null && searchResult.localeRelatedObjectName == null) {
String locationCountry = app.getRegions().getCountryName(latLon);
searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
}
return searchResult.localeRelatedObjectName;
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
return fav.getCategory().length() == 0 ? app.getString(R.string.shared_string_favorites) : fav.getCategory();
case FAVORITE_GROUP:
return app.getString(R.string.shared_string_my_favorites);
case REGION:
BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
break;
case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object;
boolean hasTypeInDescription = !Algorithms.isEmpty(entry.getName().getTypeName());
if (hasTypeInDescription) {
return entry.getName().getTypeName();
} else {
return "";
}
case WPT:
StringBuilder sb = new StringBuilder();
GPXFile gpx = (GPXFile) searchResult.relatedObject;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
sb.append(searchResult.localeRelatedObjectName);
}
if (gpx != null && !Algorithms.isEmpty(gpx.path)) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(new File(gpx.path).getName());
}
return sb.toString();
case UNKNOWN_NAME_FILTER:
break;
}
return searchResult.objectType.name();
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class SearchPOIActivity method showOptionsMenu.
private void showOptionsMenu(View v) {
// Show menu with search all, name finder, name finder poi
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(this, v);
final PoiUIFilter f = this.filter;
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_edit).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
PoiUIFilter custom = getMyApplication().getPoiFilters().getCustomPOIFilter();
custom.replaceWithPoiFilter(f);
showEditActivity(custom);
return true;
}
});
addFilter(optionsMenu, getString(R.string.shared_string_is_open));
addFilter(optionsMenu, getString(R.string.shared_string_is_open_24_7));
Map<String, PoiType> poiAdditionals = f.getPoiAdditionals();
if (poiAdditionals != null) {
TreeMap<String, PoiType> adds = new TreeMap<String, PoiType>();
for (PoiType vtype : poiAdditionals.values()) {
if (vtype.isTopVisible()) {
adds.put(vtype.getTranslation().replace(' ', ':').toLowerCase(), vtype);
}
}
for (String vtype : adds.keySet()) {
addFilter(optionsMenu, vtype);
}
}
optionsMenu.show();
}
use of net.osmand.osm.PoiType in project Osmand by osmandapp.
the class EditPOIFilterActivity method showDialog.
private void showDialog(final PoiCategory poiCategory) {
ListView lv = EditPOIFilterActivity.this.getListView();
final int index = lv.getFirstVisiblePosition();
View v = lv.getChildAt(0);
final int top = (v == null) ? 0 : v.getTop();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final LinkedHashMap<String, String> subCategories = new LinkedHashMap<String, String>();
Set<String> acceptedCategories = filter.getAcceptedSubtypes(poiCategory);
if (acceptedCategories != null) {
for (String s : acceptedCategories) {
subCategories.put(s, Algorithms.capitalizeFirstLetterAndLowercase(s));
}
}
for (PoiType pt : poiCategory.getPoiTypes()) {
subCategories.put(pt.getKeyName(), pt.getTranslation());
}
final String[] array = subCategories.keySet().toArray(new String[0]);
final Collator cl = Collator.getInstance();
cl.setStrength(Collator.SECONDARY);
Arrays.sort(array, 0, array.length, new Comparator<String>() {
@Override
public int compare(String object1, String object2) {
String v1 = subCategories.get(object1);
String v2 = subCategories.get(object2);
return cl.compare(v1, v2);
}
});
final String[] visibleNames = new String[array.length];
final boolean[] selected = new boolean[array.length];
for (int i = 0; i < array.length; i++) {
final String subcategory = array[i];
visibleNames[i] = subCategories.get(subcategory);
if (acceptedCategories == null) {
selected[i] = true;
} else {
selected[i] = acceptedCategories.contains(subcategory);
}
}
builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.shared_string_close), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LinkedHashSet<String> accepted = new LinkedHashSet<String>();
for (int i = 0; i < selected.length; i++) {
if (selected[i]) {
accepted.add(array[i]);
}
}
if (subCategories.size() == accepted.size()) {
filter.selectSubTypesToAccept(poiCategory, null);
} else if (accepted.size() == 0) {
filter.setTypeToAccept(poiCategory, false);
} else {
filter.selectSubTypesToAccept(poiCategory, accepted);
}
helper.editPoiFilter(filter);
ListView lv = EditPOIFilterActivity.this.getListView();
AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter();
la.notifyDataSetChanged();
lv.setSelectionFromTop(index, top);
}
});
builder.setPositiveButton(EditPOIFilterActivity.this.getText(R.string.shared_string_select_all), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListView lv = selectAllFromCategory(poiCategory);
lv.setSelectionFromTop(index, top);
}
});
builder.setMultiChoiceItems(visibleNames, selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int item, boolean isChecked) {
selected[item] = isChecked;
}
});
builder.show();
}
Aggregations