Search in sources :

Example 11 with AbstractPoiType

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

the class SampleApplication method initPoiTypes.

public void initPoiTypes() {
    File poiTypesFile = new File(Environment.getExternalStorageDirectory() + "/osmand/poi_types.xml");
    if (poiTypesFile.exists()) {
        poiTypes.init(poiTypesFile.getAbsolutePath());
    } else {
        poiTypes.init();
    }
    poiTypes.setPoiTranslator(new MapPoiTypes.PoiTranslator() {

        @Override
        public String getTranslation(AbstractPoiType type) {
            if (type.getBaseLangType() != null) {
                return getTranslation(type.getBaseLangType()) + " (" + getLangTranslation(type.getLang()).toLowerCase() + ")";
            }
            try {
                Field f = R.string.class.getField("poi_" + type.getIconKeyName());
                if (f != null) {
                    Integer in = (Integer) f.get(null);
                    return getString(in);
                }
            } catch (Exception e) {
                System.err.println("No translation for " + type.getIconKeyName() + " " + e.getMessage());
            }
            return null;
        }

        @Override
        public String getTranslation(String keyName) {
            return null;
        }

        @Override
        public String getEnTranslation(AbstractPoiType type) {
            if (type.getBaseLangType() != null) {
                return getEnTranslation(type.getBaseLangType()) + " (" + getLangTranslation(type.getLang()).toLowerCase() + ")";
            }
            return getEnTranslation(type.getIconKeyName());
        }

        @Override
        public String getEnTranslation(String keyName) {
            return Algorithms.capitalizeFirstLetter(keyName.replace('_', ' '));
        }

        @Override
        public String getSynonyms(AbstractPoiType type) {
            AbstractPoiType baseLangType = type.getBaseLangType();
            if (baseLangType != null) {
                return getSynonyms(baseLangType);
            }
            return getSynonyms(type.getIconKeyName());
        }

        @Override
        public String getSynonyms(String keyName) {
            try {
                Field f = R.string.class.getField("synonyms_poi_" + keyName);
                if (f != null) {
                    Integer in = (Integer) f.get(null);
                    return getString(in);
                }
            } catch (Exception e) {
            }
            return "";
        }
    });
    searchUICore.initSearchUICore();
}
Also used : Field(java.lang.reflect.Field) AbstractPoiType(net.osmand.osm.AbstractPoiType) File(java.io.File) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Example 12 with AbstractPoiType

use of net.osmand.osm.AbstractPoiType 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 13 with AbstractPoiType

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

the class QuickSearchListItem method getIcon.

public static Drawable getIcon(SampleApplication app, SearchResult searchResult) {
    if (searchResult == null || searchResult.objectType == null) {
        return null;
    }
    int iconId;
    switch(searchResult.objectType) {
        case CITY:
            return app.getIconsCache().getIcon("ic_action_building_number", R.color.osmand_orange);
        case VILLAGE:
            return app.getIconsCache().getIcon("ic_action_home_dark", R.color.osmand_orange);
        case POSTCODE:
        case STREET:
            return app.getIconsCache().getIcon("ic_action_street_name", R.color.osmand_orange);
        case HOUSE:
            return app.getIconsCache().getIcon("ic_action_building", R.color.osmand_orange);
        case STREET_INTERSECTION:
            return app.getIconsCache().getIcon("ic_action_intersection", R.color.osmand_orange);
        case POI_TYPE:
            iconId = getPoiTypeIconId(app, (AbstractPoiType) searchResult.object);
            if (iconId != 0) {
                return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
            } else {
                return null;
            }
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            iconId = getAmenityIconId(amenity);
            if (iconId != 0) {
                return app.getIconsCache().getOsmandIcon(iconId, R.color.osmand_orange);
            } else {
                return null;
            }
        case LOCATION:
            return app.getIconsCache().getIcon("ic_action_world_globe", R.color.osmand_orange);
        case REGION:
            return app.getIconsCache().getIcon("ic_world_globe_dark", R.color.osmand_orange);
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) AbstractPoiType(net.osmand.osm.AbstractPoiType)

Example 14 with AbstractPoiType

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

the class AdvancedEditPoiFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_edit_poi_advanced, container, false);
    deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark, getActivity().getResources().getColor(R.color.dash_search_icon_dark));
    nameTextView = (TextView) view.findViewById(R.id.nameTextView);
    amenityTagTextView = (TextView) view.findViewById(R.id.amenityTagTextView);
    amenityTextView = (TextView) view.findViewById(R.id.amenityTextView);
    LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
    final MapPoiTypes mapPoiTypes = getMyApplication().getPoiTypes();
    mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
    // It is possible to not restart initialization every time, and probably move initialization to appInit
    Map<String, PoiType> translatedTypes = getData().getAllTranslatedSubTypes();
    HashSet<String> tagKeys = new HashSet<>();
    HashSet<String> valueKeys = new HashSet<>();
    for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
        addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
    }
    addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
    mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
    mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
    Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
    addTagButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mAdapter.addTagView("", "");
        }
    });
    return view;
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) AbstractPoiType(net.osmand.osm.AbstractPoiType) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) MapPoiTypes(net.osmand.osm.MapPoiTypes) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LinearLayout(android.widget.LinearLayout) HashSet(java.util.HashSet) Nullable(android.support.annotation.Nullable)

Example 15 with AbstractPoiType

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

the class RenderedObjectMenuController method addPlainMenuItems.

@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) {
    MapPoiTypes poiTypes = getMapActivity().getMyApplication().getPoiTypes();
    for (Map.Entry<String, String> entry : renderedObject.getTags().entrySet()) {
        if (entry.getKey().equalsIgnoreCase("maxheight")) {
            AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(entry.getKey());
            if (pt != null) {
                addPlainMenuItem(R.drawable.ic_action_note_dark, null, pt.getTranslation() + ": " + entry.getValue(), false, false, null);
            }
        }
    }
    boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
    if (osmEditingEnabled && renderedObject.getId() != null && renderedObject.getId() > 0 && (renderedObject.getId() % 2 == 1 || (renderedObject.getId() >> 7) < Integer.MAX_VALUE)) {
        String link;
        if ((renderedObject.getId() >> 6) % 2 == 1) {
            link = "https://www.openstreetmap.org/node/";
        } else {
            link = "https://www.openstreetmap.org/way/";
        }
        addPlainMenuItem(R.drawable.ic_action_info_dark, null, link + (renderedObject.getId() >> 7), true, true, null);
    }
    addMyLocationToPlainItems(latLon);
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) Map(java.util.Map) MapPoiTypes(net.osmand.osm.MapPoiTypes) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin)

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