Search in sources :

Example 1 with TripHelper

use of net.osmand.plus.auto.TripHelper in project Osmand by osmandapp.

the class NavigationService method setCarContext.

/**
 * Sets the {@link CarContext} to use while the service is running.
 */
public void setCarContext(@Nullable CarContext carContext) {
    this.carContext = carContext;
    if (carContext != null) {
        this.tripHelper = new TripHelper(getApp());
        this.navigationManager = carContext.getCarService(NavigationManager.class);
        this.navigationManager.setNavigationManagerCallback(new NavigationManagerCallback() {

            @Override
            public void onStopNavigation() {
                getApp().stopNavigation();
            }

            @Override
            public void onAutoDriveEnabled() {
                CarToast.makeText(carContext, "Auto drive enabled", CarToast.LENGTH_LONG).show();
                OsmAndLocationSimulation sim = getApp().getLocationProvider().getLocationSimulation();
                RoutingHelper routingHelper = getApp().getRoutingHelper();
                if (!sim.isRouteAnimating() && routingHelper.isFollowingMode() && routingHelper.isRouteCalculated() && !routingHelper.isRouteBeingCalculated()) {
                    sim.startStopRouteAnimation(null);
                }
            }
        });
    // Uncomment if navigating
    // mNavigationManager.navigationStarted();
    } else {
        this.navigationManager = null;
    }
}
Also used : NavigationManager(androidx.car.app.navigation.NavigationManager) TripHelper(net.osmand.plus.auto.TripHelper) RoutingHelper(net.osmand.plus.routing.RoutingHelper) NavigationManagerCallback(androidx.car.app.navigation.NavigationManagerCallback)

Example 2 with TripHelper

use of net.osmand.plus.auto.TripHelper in project Osmand by osmandapp.

the class NavigationService method updateCarNavigation.

public void updateCarNavigation() {
    OsmandApplication app = getApp();
    RoutingHelper routingHelper = app.getRoutingHelper();
    TripHelper tripHelper = this.tripHelper;
    if (carNavigationActive && tripHelper != null && routingHelper.isRouteCalculated() && routingHelper.isFollowingMode()) {
        NavigationSession carNavigationSession = app.getCarNavigationSession();
        if (carNavigationSession != null) {
            NavigationScreen navigationScreen = carNavigationSession.getNavigationScreen();
            if (navigationScreen != null) {
                float density = navigationScreen.getSurfaceRenderer().getDensity();
                if (density == 0) {
                    density = 1;
                }
                Trip trip = tripHelper.buildTrip(density);
                navigationManager.updateTrip(trip);
                List<Destination> destinations = null;
                Destination destination = tripHelper.getLastDestination();
                TravelEstimate destinationTravelEstimate = tripHelper.getLastDestinationTravelEstimate();
                if (destination != null) {
                    destinations = Collections.singletonList(destination);
                }
                TravelEstimate lastStepTravelEstimate = tripHelper.getLastStepTravelEstimate();
                navigationScreen.updateTrip(true, routingHelper.isRouteBeingCalculated(), false, /*routingHelper.isRouteWasFinished()*/
                destinations, trip.getSteps(), destinationTravelEstimate, lastStepTravelEstimate != null ? lastStepTravelEstimate.getRemainingDistance() : null, false, true, null);
            }
        }
    }
}
Also used : Destination(androidx.car.app.navigation.model.Destination) NavigationScreen(net.osmand.plus.auto.NavigationScreen) Trip(androidx.car.app.navigation.model.Trip) TripHelper(net.osmand.plus.auto.TripHelper) RoutingHelper(net.osmand.plus.routing.RoutingHelper) NavigationSession(net.osmand.plus.auto.NavigationSession) TravelEstimate(androidx.car.app.navigation.model.TravelEstimate)

Aggregations

TripHelper (net.osmand.plus.auto.TripHelper)2 RoutingHelper (net.osmand.plus.routing.RoutingHelper)2 NavigationManager (androidx.car.app.navigation.NavigationManager)1 NavigationManagerCallback (androidx.car.app.navigation.NavigationManagerCallback)1 Destination (androidx.car.app.navigation.model.Destination)1 TravelEstimate (androidx.car.app.navigation.model.TravelEstimate)1 Trip (androidx.car.app.navigation.model.Trip)1 NavigationScreen (net.osmand.plus.auto.NavigationScreen)1 NavigationSession (net.osmand.plus.auto.NavigationSession)1