Search in sources :

Example 6 with PoiType

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

the class ContextMenuLayer method getPublicTransportTypes.

private List<String> getPublicTransportTypes() {
    if (publicTransportTypes == null) {
        publicTransportTypes = new ArrayList<>();
        List<PoiFilter> filters = activity.getMyApplication().getPoiTypes().getPoiCategoryByName("transportation").getPoiFilters();
        for (PoiFilter poiFilter : filters) {
            if (poiFilter.getKeyName().equals("public_transport")) {
                for (PoiType poiType : poiFilter.getPoiTypes()) {
                    publicTransportTypes.add(poiType.getKeyName());
                    for (PoiType poiAdditionalType : poiType.getPoiAdditionals()) {
                        publicTransportTypes.add(poiAdditionalType.getKeyName());
                    }
                }
            }
        }
    }
    return publicTransportTypes;
}
Also used : PoiFilter(net.osmand.osm.PoiFilter) PoiType(net.osmand.osm.PoiType)

Example 7 with PoiType

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

the class QuickSearchPoiFilterFragment method extractPoiAdditionals.

private void extractPoiAdditionals(Collection<PoiType> poiAdditionals, Map<String, List<PoiType>> additionalsMap, Set<String> excludedPoiAdditionalCategories, boolean extractAll) {
    for (PoiType poiType : poiAdditionals) {
        String category = poiType.getPoiAdditionalCategory();
        if (category == null) {
            category = "";
        }
        if (excludedPoiAdditionalCategories != null && excludedPoiAdditionalCategories.contains(category)) {
            continue;
        }
        if (collapsedCategories.contains(category) && !extractAll) {
            if (!additionalsMap.containsKey(category)) {
                additionalsMap.put(category, new ArrayList<PoiType>());
            }
            continue;
        }
        boolean showAll = showAllCategories.contains(category) || extractAll;
        String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
        if (!poiAdditionalsTranslations.containsKey(poiType)) {
            poiAdditionalsTranslations.put(poiType, poiType.getTranslation());
        }
        if (showAll || poiType.isTopVisible() || selectedPoiAdditionals.contains(keyName.replace(' ', ':'))) {
            List<PoiType> adds = additionalsMap.get(category);
            if (adds == null) {
                adds = new ArrayList<>();
                additionalsMap.put(category, adds);
            }
            if (!adds.contains(poiType)) {
                adds.add(poiType);
            }
        }
    }
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 8 with PoiType

use of net.osmand.osm.PoiType 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 9 with PoiType

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

the class SearchPOIActivity method showOptionsMenu.

private void showOptionsMenu(View v) {
    // Show menu with search all, name finder, name finder poi
    IconsCache iconsCache = getMyApplication().getIconsCache();
    final PopupMenu optionsMenu = new PopupMenu(this, v);
    final PoiUIFilter f = this.filter;
    MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_edit).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            PoiUIFilter custom = getMyApplication().getPoiFilters().getCustomPOIFilter();
            custom.replaceWithPoiFilter(f);
            showEditActivity(custom);
            return true;
        }
    });
    addFilter(optionsMenu, getString(R.string.shared_string_is_open));
    addFilter(optionsMenu, getString(R.string.shared_string_is_open_24_7));
    Map<String, PoiType> poiAdditionals = f.getPoiAdditionals();
    if (poiAdditionals != null) {
        TreeMap<String, PoiType> adds = new TreeMap<String, PoiType>();
        for (PoiType vtype : poiAdditionals.values()) {
            if (vtype.isTopVisible()) {
                adds.put(vtype.getTranslation().replace(' ', ':').toLowerCase(), vtype);
            }
        }
        for (String vtype : adds.keySet()) {
            addFilter(optionsMenu, vtype);
        }
    }
    optionsMenu.show();
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) PoiType(net.osmand.osm.PoiType) MenuItem(android.view.MenuItem) IconsCache(net.osmand.plus.IconsCache) TreeMap(java.util.TreeMap) PopupMenu(android.support.v7.widget.PopupMenu) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 10 with PoiType

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

the class EditPOIFilterActivity method showDialog.

private void showDialog(final PoiCategory poiCategory) {
    ListView lv = EditPOIFilterActivity.this.getListView();
    final int index = lv.getFirstVisiblePosition();
    View v = lv.getChildAt(0);
    final int top = (v == null) ? 0 : v.getTop();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    final LinkedHashMap<String, String> subCategories = new LinkedHashMap<String, String>();
    Set<String> acceptedCategories = filter.getAcceptedSubtypes(poiCategory);
    if (acceptedCategories != null) {
        for (String s : acceptedCategories) {
            subCategories.put(s, Algorithms.capitalizeFirstLetterAndLowercase(s));
        }
    }
    for (PoiType pt : poiCategory.getPoiTypes()) {
        subCategories.put(pt.getKeyName(), pt.getTranslation());
    }
    final String[] array = subCategories.keySet().toArray(new String[0]);
    final Collator cl = Collator.getInstance();
    cl.setStrength(Collator.SECONDARY);
    Arrays.sort(array, 0, array.length, new Comparator<String>() {

        @Override
        public int compare(String object1, String object2) {
            String v1 = subCategories.get(object1);
            String v2 = subCategories.get(object2);
            return cl.compare(v1, v2);
        }
    });
    final String[] visibleNames = new String[array.length];
    final boolean[] selected = new boolean[array.length];
    for (int i = 0; i < array.length; i++) {
        final String subcategory = array[i];
        visibleNames[i] = subCategories.get(subcategory);
        if (acceptedCategories == null) {
            selected[i] = true;
        } else {
            selected[i] = acceptedCategories.contains(subcategory);
        }
    }
    builder.setNeutralButton(EditPOIFilterActivity.this.getText(R.string.shared_string_close), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            LinkedHashSet<String> accepted = new LinkedHashSet<String>();
            for (int i = 0; i < selected.length; i++) {
                if (selected[i]) {
                    accepted.add(array[i]);
                }
            }
            if (subCategories.size() == accepted.size()) {
                filter.selectSubTypesToAccept(poiCategory, null);
            } else if (accepted.size() == 0) {
                filter.setTypeToAccept(poiCategory, false);
            } else {
                filter.selectSubTypesToAccept(poiCategory, accepted);
            }
            helper.editPoiFilter(filter);
            ListView lv = EditPOIFilterActivity.this.getListView();
            AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter();
            la.notifyDataSetChanged();
            lv.setSelectionFromTop(index, top);
        }
    });
    builder.setPositiveButton(EditPOIFilterActivity.this.getText(R.string.shared_string_select_all), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ListView lv = selectAllFromCategory(poiCategory);
            lv.setSelectionFromTop(index, top);
        }
    });
    builder.setMultiChoiceItems(visibleNames, selected, new DialogInterface.OnMultiChoiceClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int item, boolean isChecked) {
            selected[item] = isChecked;
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LinkedHashSet(java.util.LinkedHashSet) DialogInterface(android.content.DialogInterface) PoiType(net.osmand.osm.PoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) LinkedHashMap(java.util.LinkedHashMap) Collator(java.text.Collator) ListView(android.widget.ListView)

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