Search in sources :

Example 1 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class TripHelper method buildTrip.

@NonNull
public Trip buildTrip(float density) {
    RoutingHelper routingHelper = app.getRoutingHelper();
    OsmandSettings settings = app.getSettings();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    TargetPoint pointToNavigate = targetPointsHelper.getPointToNavigate();
    Trip.Builder tripBuilder = new Trip.Builder();
    if (pointToNavigate != null) {
        Pair<Destination, TravelEstimate> dest = getDestination(pointToNavigate);
        tripBuilder.addDestination(dest.first, dest.second);
        lastDestination = dest.first;
        lastDestinationTravelEstimate = dest.second;
    } else {
        lastDestination = null;
        lastDestinationTravelEstimate = null;
    }
    boolean routeBeingCalculated = routingHelper.isRouteBeingCalculated();
    tripBuilder.setLoading(routeBeingCalculated);
    if (!routeBeingCalculated) {
        Step.Builder stepBuilder = new Step.Builder();
        Maneuver.Builder turnBuilder;
        TurnType turnType = null;
        boolean leftSide = settings.DRIVING_REGION.get().leftHandDriving;
        boolean deviatedFromRoute = routingHelper.isDeviatedFromRoute();
        int turnImminent = 0;
        int nextTurnDistance = 0;
        RouteCalculationResult.NextDirectionInfo nextDirInfo;
        RouteCalculationResult.NextDirectionInfo calc = new RouteCalculationResult.NextDirectionInfo();
        if (deviatedFromRoute) {
            turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
            nextTurnDistance = (int) routingHelper.getRouteDeviation();
        } else {
            nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
            if (nextDirInfo != null && nextDirInfo.distanceTo > 0 && nextDirInfo.directionInfo != null) {
                turnType = nextDirInfo.directionInfo.getTurnType();
                nextTurnDistance = nextDirInfo.distanceTo;
                turnImminent = nextDirInfo.imminent;
            }
        }
        if (turnType != null) {
            TurnDrawable drawable = new TurnDrawable(app, false);
            int height = (int) (TURN_IMAGE_SIZE_DP * density);
            int width = (int) (TURN_IMAGE_SIZE_DP * density);
            drawable.setBounds(0, 0, width, height);
            drawable.setTurnType(turnType);
            drawable.setTurnImminent(turnImminent, deviatedFromRoute);
            Bitmap turnBitmap = drawableToBitmap(drawable, width, height);
            turnBuilder = new Maneuver.Builder(getManeuverType(turnType));
            if (turnType.isRoundAbout()) {
                turnBuilder.setRoundaboutExitNumber(turnType.getExitOut());
            }
            turnBuilder.setIcon(new CarIcon.Builder(IconCompat.createWithBitmap(turnBitmap)).build());
        } else {
            turnBuilder = new Maneuver.Builder(Maneuver.TYPE_UNKNOWN);
        }
        Maneuver maneuver = turnBuilder.build();
        String cue = turnType != null ? RouteCalculationResult.toString(turnType, app, true) : "";
        stepBuilder.setManeuver(maneuver);
        stepBuilder.setCue(cue);
        nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, false);
        if (nextDirInfo != null && nextDirInfo.directionInfo != null && nextDirInfo.directionInfo.getTurnType() != null) {
            int[] lanes = nextDirInfo.directionInfo.getTurnType().getLanes();
            int locimminent = nextDirInfo.imminent;
            // Do not show too far
            if ((nextDirInfo.distanceTo > 800 && nextDirInfo.directionInfo.getTurnType().isSkipToSpeak()) || nextDirInfo.distanceTo > 1200) {
                lanes = null;
            }
            // int dist = nextDirInfo.distanceTo;
            if (lanes != null) {
                for (int lane : lanes) {
                    int firstTurnType = TurnType.getPrimaryTurn(lane);
                    int secondTurnType = TurnType.getSecondaryTurn(lane);
                    int thirdTurnType = TurnType.getTertiaryTurn(lane);
                    Lane.Builder laneBuilder = new Lane.Builder();
                    laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(firstTurnType, leftSide)), (lane & 1) == 1));
                    if (secondTurnType > 0) {
                        laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(secondTurnType, leftSide)), false));
                    }
                    if (thirdTurnType > 0) {
                        laneBuilder.addDirection(LaneDirection.create(getLaneDirection(TurnType.valueOf(thirdTurnType, leftSide)), false));
                    }
                    stepBuilder.addLane(laneBuilder.build());
                }
                LanesDrawable lanesDrawable = new LanesDrawable(app, 1f, TURN_LANE_IMAGE_SIZE * density, TURN_LANE_IMAGE_MIN_DELTA * density, TURN_LANE_IMAGE_MARGIN * density, TURN_LANE_IMAGE_SIZE * density);
                lanesDrawable.lanes = lanes;
                lanesDrawable.imminent = locimminent == 0;
                lanesDrawable.isNightMode = app.getDaynightHelper().isNightMode();
                // prefer 500 x 74 dp
                lanesDrawable.updateBounds();
                Bitmap lanesBitmap = drawableToBitmap(lanesDrawable, lanesDrawable.getIntrinsicWidth(), lanesDrawable.getIntrinsicHeight());
                stepBuilder.setLanesImage(new CarIcon.Builder(IconCompat.createWithBitmap(lanesBitmap)).build());
            }
        }
        int leftTurnTimeSec = routingHelper.getLeftTimeNextTurn();
        long turnArrivalTime = System.currentTimeMillis() + leftTurnTimeSec * 1000L;
        Distance stepDistance = getDistance(app, nextTurnDistance);
        DateTimeWithZone stepDateTime = DateTimeWithZone.create(turnArrivalTime, TimeZone.getDefault());
        TravelEstimate.Builder stepTravelEstimateBuilder = new TravelEstimate.Builder(stepDistance, stepDateTime);
        stepTravelEstimateBuilder.setRemainingTimeSeconds(leftTurnTimeSec);
        Step step = stepBuilder.build();
        TravelEstimate stepTravelEstimate = stepTravelEstimateBuilder.build();
        tripBuilder.addStep(step, stepTravelEstimate);
        lastStep = step;
        lastStepTravelEstimate = stepTravelEstimate;
        if (!deviatedFromRoute) {
            nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc, true);
            CurrentStreetName currentName = routingHelper.getCurrentName(nextDirInfo);
            tripBuilder.setCurrentRoad(currentName.text);
            lastCurrentRoad = currentName.text;
        } else {
            lastCurrentRoad = null;
        }
    } else {
        lastStep = null;
        lastStepTravelEstimate = null;
    }
    return tripBuilder.build();
}
Also used : Destination(androidx.car.app.navigation.model.Destination) Step(androidx.car.app.navigation.model.Step) Maneuver(androidx.car.app.navigation.model.Maneuver) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) Bitmap(android.graphics.Bitmap) RouteCalculationResult(net.osmand.plus.routing.RouteCalculationResult) DateTimeWithZone(androidx.car.app.model.DateTimeWithZone) TurnDrawable(net.osmand.plus.views.mapwidgets.TurnDrawable) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) Distance(androidx.car.app.model.Distance) Trip(androidx.car.app.navigation.model.Trip) Lane(androidx.car.app.navigation.model.Lane) CurrentStreetName(net.osmand.plus.routing.CurrentStreetName) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TurnType(net.osmand.router.TurnType) LanesDrawable(net.osmand.plus.views.mapwidgets.LanesDrawable) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TravelEstimate(androidx.car.app.navigation.model.TravelEstimate) NonNull(androidx.annotation.NonNull)

Example 2 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper 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, mapActivity.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 : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PlanRouteOptionsFragmentListener(net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 3 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class AddPointBottomSheetDialog method getAdapterOnClickListener.

private OnClickListener getAdapterOnClickListener(final List<Object> items) {
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) v.getTag();
            int position = viewHolder != null ? viewHolder.getAdapterPosition() : RecyclerView.NO_POSITION;
            if (mapActivity == null || position == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = items.get(position);
            if (item.equals(FAVORITES)) {
                openFavoritesDialog();
            } else if (item.equals(MARKERS)) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker(-1, pointType);
                dismiss();
            } else if (item instanceof MapMarker) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker((MapMarker) item, pointType);
                dismiss();
            } else {
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                Pair<LatLon, PointDescription> pair = getLocationAndDescrFromItem(item);
                LatLon ll = pair.first;
                PointDescription name = pair.second;
                if (ll == null) {
                    if (item instanceof PointType) {
                        AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item);
                    } else {
                        dismiss();
                    }
                } else {
                    FavouritesHelper favorites = requiredMyApplication().getFavoritesHelper();
                    switch(pointType) {
                        case START:
                            targetPointsHelper.setStartPoint(ll, true, name);
                            break;
                        case TARGET:
                            targetPointsHelper.navigateToPoint(ll, true, -1, name);
                            break;
                        case INTERMEDIATE:
                            targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), name);
                            break;
                        case HOME:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null);
                            break;
                        case WORK:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.WORK, null);
                            break;
                        case PARKING:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.PARKING, null);
                            break;
                    }
                    dismiss();
                }
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) PointType(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType) RecyclerView(androidx.recyclerview.widget.RecyclerView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Example 4 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class MapRouteInfoMenu method updateStartPointView.

private void updateStartPointView() {
    MapActivity mapActivity = getMapActivity();
    final View mainView = getMainView();
    if (mapActivity == null || mainView == null) {
        return;
    }
    setupFromText(mainView);
    View fromLayout = mainView.findViewById(R.id.FromLayout);
    fromLayout.setOnClickListener(v -> {
        MapActivity mapActv = getMapActivity();
        if (mapActv != null) {
            AddPointBottomSheetDialog.showInstance(mapActv, PointType.START);
        }
    });
    FrameLayout fromButton = mainView.findViewById(R.id.from_button);
    boolean isFollowTrack = mapActivity.getMyApplication().getRoutingHelper().getCurrentGPXRoute() != null;
    if (isFollowTrack) {
        fromButton.setVisibility(View.GONE);
    } else {
        fromButton.setVisibility(View.VISIBLE);
    }
    LinearLayout fromButtonContainer = mainView.findViewById(R.id.from_button_container);
    setupButtonBackground(fromButton, fromButtonContainer);
    ImageView swapDirectionView = mainView.findViewById(R.id.from_button_image_view);
    setupButtonIcon(swapDirectionView, R.drawable.ic_action_change_navigation_points);
    fromButton.setOnClickListener(view -> {
        MapActivity mapActv = getMapActivity();
        if (mapActv != null) {
            OsmandApplication app = mapActv.getMyApplication();
            TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
            TargetPoint startPoint = targetPointsHelper.getPointToStart();
            TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
            Location loc = app.getLocationProvider().getLastKnownLocation();
            if (loc == null && startPoint == null && endPoint == null) {
                app.showShortToastMessage(R.string.add_start_and_end_points);
            } else if (endPoint == null) {
                app.showShortToastMessage(R.string.mark_final_location_first);
            } else {
                GPXRouteParamsBuilder gpxParams = app.getRoutingHelper().getCurrentGPXRoute();
                if (gpxParams != null) {
                    boolean reverse = !gpxParams.isReverse();
                    LocalRoutingParameter parameter = new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, app.getString(R.string.gpx_option_reverse_route), reverse);
                    app.getRoutingOptionsHelper().applyRoutingParameter(parameter, reverse);
                } else {
                    if (startPoint == null && loc != null) {
                        startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActv.getString(R.string.shared_string_my_location)));
                    }
                    if (startPoint != null) {
                        int intermediateSize = targetPointsHelper.getIntermediatePoints().size();
                        if (intermediateSize > 1) {
                            WaypointDialogHelper.reverseAllPoints(app, mapActv, mapActv.getDashboard().getWaypointDialogHelper());
                        } else {
                            WaypointDialogHelper.switchStartAndFinish(mapActv.getMyApplication(), mapActv, mapActv.getDashboard().getWaypointDialogHelper(), true);
                        }
                    } else {
                        app.showShortToastMessage(R.string.route_add_start_point);
                    }
                }
            }
        }
    });
    updateFromIcon(mainView);
    final View textView = mainView.findViewById(R.id.from_button_description);
    if (!swapButtonCollapsing && !swapButtonCollapsed && fromButton.getVisibility() == View.VISIBLE && textView.getVisibility() == View.VISIBLE) {
        swapButtonCollapsing = true;
        collapseButtonAnimated(R.id.from_button, R.id.from_button_description, success -> {
            swapButtonCollapsing = false;
            swapButtonCollapsed = success;
        });
    } else if (swapButtonCollapsed) {
        textView.setVisibility(View.GONE);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) OtherLocalRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherLocalRoutingParameter) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) View(android.view.View) TextView(android.widget.TextView) OtherLocalRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherLocalRoutingParameter) LocalRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter) LatLon(net.osmand.data.LatLon) FrameLayout(android.widget.FrameLayout) PointDescription(net.osmand.data.PointDescription) ImageView(android.widget.ImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 5 with TargetPointsHelper

use of net.osmand.plus.helpers.TargetPointsHelper in project Osmand by osmandapp.

the class FailSafeFuntions method restoreRoutingMode.

public static void restoreRoutingMode(final MapActivity ma) {
    final OsmandApplication app = ma.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final Handler uiHandler = new Handler();
    final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
    final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (pointToNavigate == null && gpxPath == null) {
        notRestoreRoutingMode(ma, app);
    } else {
        quitRouteRestoreDialog = false;
        Runnable encapsulate = new Runnable() {

            int delay = 7;

            Runnable delayDisplay = null;

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ma);
                final TextView tv = new TextView(ma);
                tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                tv.setPadding(7, 5, 7, 5);
                builder.setView(tv);
                builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        restoreRoutingModeInner();
                    }
                });
                builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        notRestoreRoutingMode(ma, app);
                    }
                });
                final AlertDialog dlg = builder.show();
                dlg.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                dlg.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                delayDisplay = new Runnable() {

                    @Override
                    public void run() {
                        if (!quitRouteRestoreDialog) {
                            delay--;
                            tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                            if (delay <= 0) {
                                try {
                                    if (dlg.isShowing() && !quitRouteRestoreDialog) {
                                        dlg.dismiss();
                                    }
                                    quitRouteRestoreDialog = true;
                                    restoreRoutingModeInner();
                                } catch (Exception e) {
                                    // swalow view not attached exception
                                    log.error(e.getMessage() + "", e);
                                }
                            } else {
                                uiHandler.postDelayed(delayDisplay, 1000);
                            }
                        }
                    }
                };
                delayDisplay.run();
            }

            private void restoreRoutingModeInner() {
                AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {

                    @Override
                    protected GPXFile doInBackground(String... params) {
                        if (gpxPath != null) {
                            // Reverse also should be stored ?
                            GPXFile f = GPXUtilities.loadGPXFile(new File(gpxPath));
                            if (f.error != null) {
                                return null;
                            }
                            return f;
                        } else {
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(GPXFile result) {
                        final GPXRouteParamsBuilder gpxRoute;
                        if (result != null) {
                            gpxRoute = new GPXRouteParamsBuilder(result, settings);
                            if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
                                gpxRoute.setCalculateOsmAndRouteParts(true);
                            }
                            if (settings.GPX_ROUTE_CALC.get()) {
                                gpxRoute.setCalculateOsmAndRoute(true);
                            }
                            if (settings.GPX_ROUTE_SEGMENT.get() != -1) {
                                gpxRoute.setSelectedSegment(settings.GPX_ROUTE_SEGMENT.get());
                            }
                        } else {
                            gpxRoute = null;
                        }
                        TargetPoint endPoint = pointToNavigate;
                        if (endPoint == null) {
                            notRestoreRoutingMode(ma, app);
                        } else {
                            enterRoutingMode(ma, gpxRoute);
                        }
                    }
                };
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
            }
        };
        encapsulate.run();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) OnDismissListener(android.content.DialogInterface.OnDismissListener) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)42 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 LatLon (net.osmand.data.LatLon)22 OsmandApplication (net.osmand.plus.OsmandApplication)19 MapActivity (net.osmand.plus.activities.MapActivity)14 View (android.view.View)11 RoutingHelper (net.osmand.plus.routing.RoutingHelper)11 TextView (android.widget.TextView)10 PointDescription (net.osmand.data.PointDescription)9 ImageView (android.widget.ImageView)8 ArrayList (java.util.ArrayList)8 Location (net.osmand.Location)8 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)7 Bundle (android.os.Bundle)4 OnClickListener (android.view.View.OnClickListener)4 FavouritePoint (net.osmand.data.FavouritePoint)4 DialogInterface (android.content.DialogInterface)3 HorizontalScrollView (android.widget.HorizontalScrollView)3 ImageButton (android.widget.ImageButton)3 LinearLayout (android.widget.LinearLayout)3