Search in sources :

Example 66 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class WaypointHelper method calculatePoi.

protected void calculatePoi(RouteCalculationResult route, List<LocationPointWrapper> locationPoints, boolean announcePOI) {
    if (app.getPoiFilters().isShowingAnyPoi()) {
        final List<Location> locs = route.getImmutableAllLocations();
        List<Amenity> amenities = new ArrayList<>();
        for (PoiUIFilter pf : app.getPoiFilters().getSelectedPoiFilters()) {
            amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius));
        }
        for (Amenity a : amenities) {
            AmenityRoutePoint rp = a.getRoutePoint();
            int i = locs.indexOf(rp.pointA);
            if (i >= 0) {
                LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a), (float) rp.deviateDistance, i);
                lwp.deviationDirectionRight = rp.deviationDirectionRight;
                lwp.setAnnounce(announcePOI);
                locationPoints.add(lwp);
            }
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 67 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    helper = app.getRoutingHelper();
    view = inflater.inflate(R.layout.route_info_layout, container, false);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(R.string.shared_string_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ((ImageView) view.findViewById(R.id.distance_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_route_distance));
    ((ImageView) view.findViewById(R.id.time_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_time_span));
    buildMenuButtons();
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setBackgroundColor(getResources().getColor(app.getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
    View topShadowView = inflater.inflate(R.layout.list_shadow_header, listView, false);
    listView.addHeaderView(topShadowView, null, false);
    View bottomShadowView = inflater.inflate(R.layout.list_shadow_footer, listView, false);
    listView.addFooterView(bottomShadowView, null, false);
    adapter = new RouteInfoAdapter(helper.getRouteDirections());
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position < 2) {
                return;
            }
            RouteDirectionInfo item = adapter.getItem(position - 2);
            Location loc = helper.getLocationFromRouteDirection(item);
            if (loc != null) {
                MapRouteInfoMenu.directionInfo = position - 2;
                OsmandSettings settings = getMyApplication().getSettings();
                settings.setMapLocationToShow(loc.getLatitude(), loc.getLongitude(), Math.max(13, settings.getLastKnownMapZoom()), new PointDescription(PointDescription.POINT_TYPE_MARKER, item.getDescriptionRoutePart() + " " + getTimeDescription(item)), false, null);
                MapActivity.launchMapActivityMoveToTop(getActivity());
                dismiss();
            }
        }
    });
    int dist = helper.getLeftDistance();
    int time = helper.getLeftTime();
    int hours = time / (60 * 60);
    int minutes = (time / 60) % 60;
    ((TextView) view.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(dist, app));
    StringBuilder timeStr = new StringBuilder();
    if (hours > 0) {
        timeStr.append(hours).append(" ").append(getString(R.string.osmand_parking_hour)).append(" ");
    }
    if (minutes > 0) {
        timeStr.append(minutes).append(" ").append(getString(R.string.osmand_parking_minute));
    }
    ((TextView) view.findViewById(R.id.time)).setText(timeStr);
    view.findViewById(R.id.go_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity activity = (MapActivity) getActivity();
            if (activity != null) {
                activity.getMapLayers().getMapControlsLayer().startNavigation();
                dismiss();
            }
        }
    });
    makeGpx();
    if (hasHeights) {
        View headerView = inflater.inflate(R.layout.route_info_header, null);
        buildHeader(headerView);
        listView.addHeaderView(headerView);
    }
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandSettings(net.osmand.plus.OsmandSettings) PointDescription(net.osmand.data.PointDescription) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) Location(net.osmand.Location)

Example 68 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method makeGpx.

private void makeGpx() {
    double lastHeight = HEIGHT_UNDEFINED;
    gpx = new GPXFile();
    List<Location> locations = helper.getRoute().getRouteLocations();
    if (locations != null) {
        Track track = new Track();
        TrkSegment seg = new TrkSegment();
        for (Location l : locations) {
            WptPt point = new WptPt();
            point.lat = l.getLatitude();
            point.lon = l.getLongitude();
            if (l.hasAltitude()) {
                if (!hasHeights) {
                    hasHeights = true;
                }
                float h = (float) l.getAltitude();
                point.ele = h;
                if (lastHeight == HEIGHT_UNDEFINED && seg.points.size() > 0) {
                    for (WptPt pt : seg.points) {
                        if (Double.isNaN(pt.ele)) {
                            pt.ele = h;
                        }
                    }
                }
                lastHeight = h;
            }
            seg.points.add(point);
        }
        track.segments.add(seg);
        gpx.tracks.add(track);
        String groupName = getMyApplication().getString(R.string.current_route);
        GpxDisplayGroup group = getMyApplication().getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName);
        if (group != null && group.getModifiableList().size() > 0) {
            gpxItem = group.getModifiableList().get(0);
            if (gpxItem != null) {
                gpxItem.route = true;
            }
        }
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) Track(net.osmand.plus.GPXUtilities.Track) Location(net.osmand.Location)

Example 69 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method getNextRecordingLocation.

private LatLon getNextRecordingLocation() {
    double lat = mapActivity.getMapLocation().getLatitude();
    double lon = mapActivity.getMapLocation().getLongitude();
    Location loc = app.getLocationProvider().getLastKnownLocation();
    if (loc != null) {
        lat = loc.getLatitude();
        lon = loc.getLongitude();
    }
    return new LatLon(lat, lon);
}
Also used : LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 70 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method indexSingleFile.

public boolean indexSingleFile(File f) {
    boolean oldFileExist = recordingByFileName.containsKey(f.getName());
    if (oldFileExist) {
        return false;
    }
    Recording r = new Recording(f);
    String fileName = f.getName();
    String otherName = r.getOtherName(fileName);
    int i = otherName.indexOf('.');
    if (i > 0) {
        otherName = otherName.substring(0, i);
    }
    r.file = f;
    GeoParsedPoint geo = MapUtils.decodeShortLinkString(otherName);
    r.lat = geo.getLatitude();
    r.lon = geo.getLongitude();
    Float heading = app.getLocationProvider().getHeading();
    Location loc = app.getLocationProvider().getLastKnownLocation();
    if (lastTakingPhoto != null && lastTakingPhoto.getName().equals(f.getName())) {
        float rot = heading != null ? heading : 0;
        try {
            r.updatePhotoInformation(r.lat, r.lon, loc, rot == 0 ? Double.NaN : rot);
        } catch (IOException e) {
            log.error("Error updating EXIF information " + e.getMessage(), e);
        }
        lastTakingPhoto = null;
    }
    recordings.registerObject(r.lat, r.lon, r);
    Map<String, Recording> newMap = new LinkedHashMap<>(recordingByFileName);
    newMap.put(f.getName(), r);
    recordingByFileName = newMap;
    if (isRecording()) {
        AVActionType type = currentRecording.type;
        finishRecording();
        if (type != AVActionType.REC_AUDIO && (!AV_RECORDER_SPLIT.get() || type != AVActionType.REC_VIDEO)) {
            final Recording recordingForMenu = r;
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    updateContextMenu(recordingForMenu);
                }
            }, 200);
        }
    }
    return true;
}
Also used : IOException(java.io.IOException) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) LinkedHashMap(java.util.LinkedHashMap) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5