Search in sources :

Example 1 with PlanRouteOptionsFragmentListener

use of net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener in project Osmand by osmandapp.

the class PlanRouteFragment method createOptionsFragmentListener.

private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
    return new PlanRouteOptionsFragmentListener() {

        private MapActivity mapActivity = getMapActivity();

        @Override
        public void selectOnClick() {
            selectAllOnClick();
        }

        @Override
        public void navigateOnClick() {
            if (mapActivity != null) {
                boolean hasTargets = false;
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                List<MapMarker> markers = markersHelper.getSelectedMarkers();
                if (markers.size() > 0) {
                    int i = 0;
                    if (markersHelper.isStartFromMyLocation()) {
                        targetPointsHelper.clearStartPoint(false);
                    } else {
                        MapMarker m = markers.get(i++);
                        targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), false, m.getPointDescription(mapActivity));
                    }
                    List<TargetPoint> targetPoints = new ArrayList<>();
                    for (int k = i; k < markers.size(); k++) {
                        MapMarker m = markers.get(k);
                        TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), m.getPointDescription(mapActivity));
                        targetPoints.add(t);
                    }
                    if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) {
                        TargetPoint end = targetPointsHelper.getPointToStart();
                        if (end == null) {
                            Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
                            if (loc != null) {
                                end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, getString(R.string.shared_string_my_location)));
                            }
                        }
                        if (end != null) {
                            targetPoints.add(end);
                        }
                    }
                    RoutingHelper routingHelper = mapActivity.getRoutingHelper();
                    boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode();
                    targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute);
                    hasTargets = true;
                } else {
                    targetPointsHelper.clearStartPoint(false);
                    targetPointsHelper.clearPointToNavigate(false);
                }
                planRouteContext.setNavigationFromMarkers(true);
                dismiss();
                mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
            }
        }

        @Override
        public void makeRoundTripOnClick() {
            roundTripOnClick();
        }

        @Override
        public void doorToDoorOnClick() {
            if (mapActivity != null) {
                OsmandApplication app = mapActivity.getMyApplication();
                Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
                boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
                if (selectedCount > (startFromLocation ? 0 : 1)) {
                    sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc);
                }
            }
        }

        @Override
        public void reverseOrderOnClick() {
            if (mapActivity != null) {
                markersHelper.reverseActiveMarkersOrder();
                adapter.reloadData();
                adapter.notifyDataSetChanged();
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PlanRouteOptionsFragmentListener(net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Aggregations

ArrayList (java.util.ArrayList)1 Location (net.osmand.Location)1 LatLon (net.osmand.data.LatLon)1 PointDescription (net.osmand.data.PointDescription)1 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 MapActivity (net.osmand.plus.activities.MapActivity)1 PlanRouteOptionsFragmentListener (net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener)1 RoutingHelper (net.osmand.plus.routing.RoutingHelper)1