use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class SampleApplication method initPoiTypes.
public void initPoiTypes() {
File poiTypesFile = new File(Environment.getExternalStorageDirectory() + "/osmand/poi_types.xml");
if (poiTypesFile.exists()) {
poiTypes.init(poiTypesFile.getAbsolutePath());
} else {
poiTypes.init();
}
poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {
@Override
public String getTranslation(AbstractPoiType type) {
if (type.getBaseLangType() != null) {
return getTranslation(type.getBaseLangType()) + " (" + getLangTranslation(type.getLang()).toLowerCase() + ")";
}
try {
Field f = R.string.class.getField("poi_" + type.getIconKeyName());
if (f != null) {
Integer in = (Integer) f.get(null);
return getString(in);
}
} catch (Exception e) {
System.err.println("No translation for " + type.getIconKeyName() + " " + e.getMessage());
}
return null;
}
@Override
public String getTranslation(String keyName) {
return null;
}
@Override
public String getEnTranslation(AbstractPoiType type) {
if (type.getBaseLangType() != null) {
return getEnTranslation(type.getBaseLangType()) + " (" + getLangTranslation(type.getLang()).toLowerCase() + ")";
}
return getEnTranslation(type.getIconKeyName());
}
@Override
public String getEnTranslation(String keyName) {
return Algorithms.capitalizeFirstLetter(keyName.replace('_', ' '));
}
@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 getString(in);
}
} catch (Exception e) {
}
return "";
}
});
searchUICore.initSearchUICore();
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class QuickSearchListItem method getTypeName.
public static String getTypeName(SampleApplication app, SearchResult searchResult) {
switch(searchResult.objectType) {
case CITY:
City city = (City) searchResult.object;
return getCityTypeStr(app, city.getType());
case POSTCODE:
return app.getString("postcode");
case VILLAGE:
city = (City) searchResult.object;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (searchResult.distRelatedObjectName > 0) {
return getCityTypeStr(app, city.getType()) + " • " + SampleFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString("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 (searchResult.localeRelatedObjectName == null) {
String locationCountry = app.getRegions().getCountryName(latLon);
searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
}
return searchResult.localeRelatedObjectName;
case REGION:
BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
break;
case UNKNOWN_NAME_FILTER:
break;
}
return searchResult.objectType.name();
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class QuickSearchListItem method getIcon.
public static Drawable getIcon(SampleApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) {
return null;
}
int iconId;
switch(searchResult.objectType) {
case CITY:
return app.getIconsCache().getIcon("ic_action_building_number", R.color.osmand_orange);
case VILLAGE:
return app.getIconsCache().getIcon("ic_action_home_dark", R.color.osmand_orange);
case POSTCODE:
case STREET:
return app.getIconsCache().getIcon("ic_action_street_name", R.color.osmand_orange);
case HOUSE:
return app.getIconsCache().getIcon("ic_action_building", R.color.osmand_orange);
case STREET_INTERSECTION:
return app.getIconsCache().getIcon("ic_action_intersection", R.color.osmand_orange);
case POI_TYPE:
iconId = getPoiTypeIconId(app, (AbstractPoiType) searchResult.object);
if (iconId != 0) {
return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
} else {
return null;
}
case POI:
Amenity amenity = (Amenity) searchResult.object;
iconId = getAmenityIconId(amenity);
if (iconId != 0) {
return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
} else {
return null;
}
case LOCATION:
return app.getIconsCache().getIcon("ic_action_world_globe", R.color.osmand_orange);
case REGION:
return app.getIconsCache().getIcon("ic_world_globe_dark", R.color.osmand_orange);
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class AdvancedEditPoiFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_edit_poi_advanced, container, false);
deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark, getActivity().getResources().getColor(R.color.dash_search_icon_dark));
nameTextView = (TextView) view.findViewById(R.id.nameTextView);
amenityTagTextView = (TextView) view.findViewById(R.id.amenityTagTextView);
amenityTextView = (TextView) view.findViewById(R.id.amenityTextView);
LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
final MapPoiTypes mapPoiTypes = getMyApplication().getPoiTypes();
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
// It is possible to not restart initialization every time, and probably move initialization to appInit
Map<String, PoiType> translatedTypes = getData().getAllTranslatedSubTypes();
HashSet<String> tagKeys = new HashSet<>();
HashSet<String> valueKeys = new HashSet<>();
for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
}
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
addTagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAdapter.addTagView("", "");
}
});
return view;
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class RenderedObjectMenuController method addPlainMenuItems.
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
MapPoiTypes poiTypes = getMapActivity().getMyApplication().getPoiTypes();
for (Map.Entry<String, String> entry : renderedObject.getTags().entrySet()) {
if (entry.getKey().equalsIgnoreCase("maxheight")) {
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(entry.getKey());
if (pt != null) {
addPlainMenuItem(R.drawable.ic_action_note_dark, null, pt.getTranslation() + ": " + entry.getValue(), false, false, null);
}
}
}
boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
if (osmEditingEnabled && renderedObject.getId() != null && renderedObject.getId() > 0 && (renderedObject.getId() % 2 == 1 || (renderedObject.getId() >> 7) < Integer.MAX_VALUE)) {
String link;
if ((renderedObject.getId() >> 6) % 2 == 1) {
link = "https://www.openstreetmap.org/node/";
} else {
link = "https://www.openstreetmap.org/way/";
}
addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> 7), true, true, null);
}
addMyLocationToPlainItems(latLon);
}
Aggregations