Search in sources :

Example 16 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class PoiFiltersHelper method getLocalWikiPOIFilter.

public PoiUIFilter getLocalWikiPOIFilter() {
    if (localWikiPoiFilter == null) {
        PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place");
        if (place != null && !Algorithms.isEmpty(application.getLanguage())) {
            PoiUIFilter filter = new PoiUIFilter(place, application, " " + // $NON-NLS-1$
            application.getLangTranslation(application.getLanguage()));
            filter.setSavedFilterByName("wiki:lang:" + application.getLanguage());
            filter.setStandardFilter(true);
            localWikiPoiFilter = filter;
        }
    }
    return localWikiPoiFilter;
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 17 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class PoiUIFilter method fillPoiAdditionals.

private void fillPoiAdditionals(AbstractPoiType pt, boolean allFromCategory) {
    for (PoiType add : pt.getPoiAdditionals()) {
        poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
        poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
    }
    if (pt instanceof PoiCategory && allFromCategory) {
        for (PoiFilter pf : ((PoiCategory) pt).getPoiFilters()) {
            fillPoiAdditionals(pf, true);
        }
        for (PoiType ps : ((PoiCategory) pt).getPoiTypes()) {
            fillPoiAdditionals(ps, false);
        }
    } else if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
        for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
            fillPoiAdditionals(ps, false);
        }
    }
}
Also used : PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 18 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class PoiUIFilter method addOtherPoiAdditionals.

private void addOtherPoiAdditionals() {
    for (PoiType add : poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized()) {
        poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
        poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
    }
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 19 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class PoiUIFilter method getNameFilterInternal.

private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
    final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
    return new AmenityNameFilter() {

        @Override
        public boolean accept(Amenity a) {
            if (sm != null) {
                String lower = OsmAndFormatter.getPoiStringWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
                if (!sm.matches(lower)) {
                    return false;
                }
            }
            if (poiAdditionals != null) {
                Map<PoiType, PoiType> textPoiAdditionalsMap = new HashMap<>();
                Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
                for (PoiType pt : poiAdditionals) {
                    String category = pt.getPoiAdditionalCategory();
                    List<PoiType> types = poiAdditionalCategoriesMap.get(category);
                    if (types == null) {
                        types = new ArrayList<>();
                        poiAdditionalCategoriesMap.put(category, types);
                    }
                    types.add(pt);
                    String osmTag = pt.getOsmTag();
                    if (osmTag.length() < pt.getKeyName().length()) {
                        PoiType textPoiType = poiTypes.getTextPoiAdditionalByKey(osmTag);
                        if (textPoiType != null) {
                            textPoiAdditionalsMap.put(pt, textPoiType);
                        }
                    }
                }
                for (List<PoiType> types : poiAdditionalCategoriesMap.values()) {
                    boolean acceptedAnyInCategory = false;
                    for (PoiType p : types) {
                        String inf = a.getAdditionalInfo(p.getKeyName());
                        if (inf != null) {
                            acceptedAnyInCategory = true;
                            break;
                        } else {
                            PoiType textPoiType = textPoiAdditionalsMap.get(p);
                            if (textPoiType != null) {
                                inf = a.getAdditionalInfo(textPoiType.getKeyName());
                                if (!Algorithms.isEmpty(inf)) {
                                    String[] items = inf.split(";");
                                    String val = p.getOsmValue().trim().toLowerCase();
                                    for (String item : items) {
                                        if (item.trim().toLowerCase().equals(val)) {
                                            acceptedAnyInCategory = true;
                                            break;
                                        }
                                    }
                                    if (acceptedAnyInCategory) {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (!acceptedAnyInCategory) {
                        return false;
                    }
                }
            }
            if (allTime) {
                if (!"24/7".equalsIgnoreCase(a.getOpeningHours()) && !"Mo-Su 00:00-24:00".equalsIgnoreCase(a.getOpeningHours())) {
                    return false;
                }
            }
            if (open) {
                OpeningHours rs = OpeningHoursParser.parseOpenedHours(a.getOpeningHours());
                if (rs != null) {
                    Calendar inst = Calendar.getInstance();
                    inst.setTimeInMillis(System.currentTimeMillis());
                    boolean work = rs.isOpenedForTime(inst);
                    if (!work) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : Amenity(net.osmand.data.Amenity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) OpeningHours(net.osmand.util.OpeningHoursParser.OpeningHours) CollatorStringMatcher(net.osmand.CollatorStringMatcher) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with PoiType

use of net.osmand.osm.PoiType in project Osmand by osmandapp.

the class PoiUIFilter method getNameFilter.

public AmenityNameFilter getNameFilter(String filter) {
    if (Algorithms.isEmpty(filter)) {
        return new AmenityNameFilter() {

            @Override
            public boolean accept(Amenity a) {
                return true;
            }
        };
    }
    StringBuilder nmFilter = new StringBuilder();
    String[] items = filter.split(" ");
    boolean allTime = false;
    boolean open = false;
    List<PoiType> poiAdditionalsFilter = null;
    for (String s : items) {
        s = s.trim();
        if (!Algorithms.isEmpty(s)) {
            if (getNameToken24H().equalsIgnoreCase(s)) {
                allTime = true;
            } else if (getNameTokenOpen().equalsIgnoreCase(s)) {
                open = true;
            } else if (poiAdditionals.containsKey(s.toLowerCase())) {
                if (poiAdditionalsFilter == null) {
                    poiAdditionalsFilter = new ArrayList<>();
                }
                PoiType pt = poiAdditionals.get(s.toLowerCase());
                if (pt != null) {
                    poiAdditionalsFilter.add(pt);
                }
            } else {
                nmFilter.append(s).append(" ");
            }
        }
    }
    return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter);
}
Also used : Amenity(net.osmand.data.Amenity) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Aggregations

PoiType (net.osmand.osm.PoiType)49 AbstractPoiType (net.osmand.osm.AbstractPoiType)30 PoiCategory (net.osmand.osm.PoiCategory)11 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 View (android.view.View)8 TextView (android.widget.TextView)8 Map (java.util.Map)8 Amenity (net.osmand.data.Amenity)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 AdapterView (android.widget.AdapterView)5 HashMap (java.util.HashMap)5 List (java.util.List)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 LinkedHashSet (java.util.LinkedHashSet)4 LatLon (net.osmand.data.LatLon)4 PoiFilter (net.osmand.osm.PoiFilter)4 Node (net.osmand.osm.edit.Node)4