Search in sources :

Example 71 with PointDescription

use of net.osmand.data.PointDescription 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)

Example 72 with PointDescription

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

the class MapMarkersWidgetsFactory method updateUI.

private void updateUI(LatLon loc, Float heading, MapMarker marker, ImageView arrowImg, TextView distText, ImageButton okButton, TextView addressText, boolean firstLine, boolean customLocation) {
    float[] mes = new float[2];
    if (loc != null && marker.point != null) {
        Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
    }
    if (customLocation) {
        heading = 0f;
    }
    boolean newImage = false;
    DirectionDrawable dd;
    if (!(arrowImg.getDrawable() instanceof DirectionDrawable)) {
        newImage = true;
        dd = new DirectionDrawable(map, arrowImg.getWidth(), arrowImg.getHeight());
    } else {
        dd = (DirectionDrawable) arrowImg.getDrawable();
    }
    dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarker.getColorId(marker.colorIndex));
    if (heading != null && loc != null) {
        dd.setAngle(mes[1] - heading + 180 + screenOrientation);
    }
    if (newImage) {
        arrowImg.setImageDrawable(dd);
    }
    arrowImg.invalidate();
    int dist = (int) mes[0];
    String txt;
    if (loc != null) {
        txt = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
    } else {
        txt = "—";
    }
    if (txt != null) {
        distText.setText(txt);
    }
    updateVisibility(okButton, !customLocation && loc != null && dist < MIN_DIST_OK_VISIBLE);
    String descr;
    PointDescription pd = marker.getPointDescription(map);
    if (Algorithms.isEmpty(pd.getName())) {
        descr = pd.getTypeName();
    } else {
        descr = pd.getName();
    }
    if (!firstLine && !isLandscapeLayout()) {
        descr = "  •  " + descr;
    }
    addressText.setText(descr);
}
Also used : PointDescription(net.osmand.data.PointDescription) DirectionDrawable(net.osmand.plus.views.DirectionDrawable)

Aggregations

PointDescription (net.osmand.data.PointDescription)72 LatLon (net.osmand.data.LatLon)44 View (android.view.View)16 ImageView (android.widget.ImageView)13 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)13 FavouritePoint (net.osmand.data.FavouritePoint)12 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)11 OsmandApplication (net.osmand.plus.OsmandApplication)10 OsmandSettings (net.osmand.plus.OsmandSettings)10 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 Amenity (net.osmand.data.Amenity)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 Intent (android.content.Intent)6 Paint (android.graphics.Paint)6 LinearLayout (android.widget.LinearLayout)6 Location (net.osmand.Location)6 DialogInterface (android.content.DialogInterface)5