Search in sources :

Example 51 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class QuickSearchListFragment method showResult.

public void showResult(SearchResult searchResult) {
    if (searchResult.location != null) {
        OsmandApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, a));
                break;
            case RECENT_OBJ:
                HistoryEntry entry = (HistoryEntry) object;
                pointDescription = entry.getName();
                if (pointDescription.isPoi()) {
                    Amenity amenity = app.getSearchUICore().findAmenity(entry.getName().getName(), entry.getLat(), entry.getLon(), lang, transliterate);
                    if (amenity != null) {
                        object = amenity;
                        pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
                        pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, amenity));
                    }
                } else if (pointDescription.isFavorite()) {
                    LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
                    List<FavouritePoint> favs = app.getFavorites().getFavouritePoints();
                    for (FavouritePoint f : favs) {
                        if (entryLatLon.equals(new LatLon(f.getLatitude(), f.getLongitude())) && pointDescription.getName().equals(f.getName())) {
                            object = f;
                            pointDescription = f.getPointDescription();
                            break;
                        }
                    }
                }
                break;
            case FAVORITE:
                FavouritePoint fav = (FavouritePoint) object;
                pointDescription = fav.getPointDescription();
                break;
            case VILLAGE:
            case CITY:
                String cityName = searchResult.localeName;
                String typeNameCity = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameCity, cityName);
                pointDescription.setIconName("ic_action_building_number");
                break;
            case STREET:
                String streetName = searchResult.localeName;
                String typeNameStreet = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameStreet, streetName);
                pointDescription.setIconName("ic_action_street_name");
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
            case WPT:
                GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object;
                pointDescription = wpt.getPointDescription(getMyApplication());
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.preferredZoom, pointDescription, object);
    }
}
Also used : Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) City(net.osmand.data.City) GPXUtilities(net.osmand.plus.GPXUtilities) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Street(net.osmand.data.Street) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4