Search in sources :

Example 21 with AbstractPoiType

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;
}
Also used : Amenity(net.osmand.data.Amenity) WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) Drawable(android.graphics.drawable.Drawable) FavoriteImageDrawable(net.osmand.plus.base.FavoriteImageDrawable) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint)

Example 22 with AbstractPoiType

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;
}
Also used : Amenity(net.osmand.data.Amenity) SearchPoiTypeFilter(net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) QuadRect(net.osmand.data.QuadRect) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Aggregations

AbstractPoiType (net.osmand.osm.AbstractPoiType)22 PoiType (net.osmand.osm.PoiType)12 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 Amenity (net.osmand.data.Amenity)6 Drawable (android.graphics.drawable.Drawable)5 View (android.view.View)5 TextView (android.widget.TextView)5 PoiCategory (net.osmand.osm.PoiCategory)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)4 SpannableString (android.text.SpannableString)3 File (java.io.File)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 City (net.osmand.data.City)3 FavouritePoint (net.osmand.data.FavouritePoint)3 LatLon (net.osmand.data.LatLon)3 PoiFilter (net.osmand.osm.PoiFilter)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)3