use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class QuickSearchListItem method getIcon.
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) {
return null;
}
int iconId = -1;
switch(searchResult.objectType) {
case CITY:
return getIcon(app, R.drawable.ic_action_building_number);
case VILLAGE:
return getIcon(app, R.drawable.ic_action_home_dark);
case POSTCODE:
case STREET:
return getIcon(app, R.drawable.ic_action_street_name);
case HOUSE:
return getIcon(app, R.drawable.ic_action_building);
case STREET_INTERSECTION:
return getIcon(app, R.drawable.ic_action_intersection);
case POI_TYPE:
if (searchResult.object instanceof AbstractPoiType) {
String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
if (!Algorithms.isEmpty(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
}
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
iconId = RenderingIcons.getBigIconResourceId(res.toString());
} else {
iconId = R.drawable.mx_user_defined;
}
}
if (iconId > 0) {
return getIcon(app, iconId);
} else {
return getIcon(app, R.drawable.ic_action_search_dark);
}
case POI:
Amenity amenity = (Amenity) searchResult.object;
String id = getAmenityIconName(app, amenity);
Drawable icon = null;
if (id != null) {
iconId = RenderingIcons.getBigIconResourceId(id);
if (iconId > 0) {
icon = getIcon(app, iconId);
}
}
if (icon == null) {
return getIcon(app, R.drawable.ic_action_search_dark);
} else {
return icon;
}
case LOCATION:
return getIcon(app, R.drawable.ic_action_world_globe);
case FAVORITE:
FavouritePoint fav = (FavouritePoint) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false);
case FAVORITE_GROUP:
FavoriteGroup group = (FavoriteGroup) searchResult.object;
int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color;
return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000);
case REGION:
return getIcon(app, R.drawable.ic_world_globe_dark);
case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object;
if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
String iconName = entry.getName().getIconName();
if (RenderingIcons.containsBigIcon(iconName)) {
iconId = RenderingIcons.getBigIconResourceId(iconName);
} else {
iconId = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
}
}
if (iconId <= 0) {
iconId = SearchHistoryFragment.getItemIcon(entry.getName());
}
try {
return getIcon(app, iconId);
} catch (Exception e) {
return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
}
case WPT:
WptPt wpt = (WptPt) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}
use of net.osmand.osm.AbstractPoiType in project Osmand by osmandapp.
the class QuickSearchHelper method findAmenity.
public Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<Amenity> amenities = app.getResourceManager().searchAmenities(new SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return true;
}
@Override
public boolean isEmpty() {
return false;
}
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
MapPoiTypes types = app.getPoiTypes();
for (Amenity amenity : amenities) {
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
if (poiSimpleFormat.equals(name)) {
return amenity;
}
}
for (Amenity amenity : amenities) {
String amenityName = amenity.getName(lang, transliterate);
if (Algorithms.isEmpty(amenityName)) {
AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
if (st != null) {
amenityName = st.getTranslation();
} else {
amenityName = amenity.getSubType();
}
}
if (name.contains(amenityName)) {
return amenity;
}
}
return null;
}
Aggregations