Search in sources :

Example 11 with HistoryEntry

use of net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry 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

HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)11 LatLon (net.osmand.data.LatLon)7 FavouritePoint (net.osmand.data.FavouritePoint)5 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 Amenity (net.osmand.data.Amenity)3 PointDescription (net.osmand.data.PointDescription)3 AbstractPoiType (net.osmand.osm.AbstractPoiType)3 Intent (android.content.Intent)2 FragmentActivity (android.support.v4.app.FragmentActivity)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 File (java.io.File)2 List (java.util.List)2 City (net.osmand.data.City)2 Street (net.osmand.data.Street)2 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)2 WptPt (net.osmand.plus.GPXUtilities.WptPt)2