Search in sources :

Example 1 with CustomSearchPoiFilter

use of net.osmand.search.core.CustomSearchPoiFilter 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();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) FavouritePoint(net.osmand.data.FavouritePoint) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 2 with CustomSearchPoiFilter

use of net.osmand.search.core.CustomSearchPoiFilter 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();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter)

Example 3 with CustomSearchPoiFilter

use of net.osmand.search.core.CustomSearchPoiFilter 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 4 with CustomSearchPoiFilter

use of net.osmand.search.core.CustomSearchPoiFilter in project Osmand by osmandapp.

the class QuickSearchHelper method refreshCustomPoiFilters.

public void refreshCustomPoiFilters() {
    core.clearCustomSearchPoiFilters();
    PoiFiltersHelper poiFilters = app.getPoiFilters();
    for (CustomSearchPoiFilter udf : poiFilters.getUserDefinedPoiFilters()) {
        core.addCustomSearchPoiFilter(udf, 0);
    }
    PoiUIFilter localWikiPoiFilter = poiFilters.getLocalWikiPOIFilter();
    if (localWikiPoiFilter != null) {
        core.addCustomSearchPoiFilter(localWikiPoiFilter, 1);
    }
    core.addCustomSearchPoiFilter(poiFilters.getShowAllPOIFilter(), 1);
}
Also used : CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

CustomSearchPoiFilter (net.osmand.search.core.CustomSearchPoiFilter)4 Amenity (net.osmand.data.Amenity)3 AbstractPoiType (net.osmand.osm.AbstractPoiType)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 City (net.osmand.data.City)2 FavouritePoint (net.osmand.data.FavouritePoint)2 LatLon (net.osmand.data.LatLon)2 Street (net.osmand.data.Street)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiFilter (net.osmand.osm.PoiFilter)2 PoiType (net.osmand.osm.PoiType)2 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)2 Drawable (android.graphics.drawable.Drawable)1 File (java.io.File)1 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)1 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 FavoriteImageDrawable (net.osmand.plus.base.FavoriteImageDrawable)1 PoiFiltersHelper (net.osmand.plus.poi.PoiFiltersHelper)1 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)1