Search in sources :

Example 1 with NavigationManagerCallback

use of androidx.car.app.navigation.NavigationManagerCallback 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)

Aggregations

NavigationManager (androidx.car.app.navigation.NavigationManager)1 NavigationManagerCallback (androidx.car.app.navigation.NavigationManagerCallback)1 TripHelper (net.osmand.plus.auto.TripHelper)1 RoutingHelper (net.osmand.plus.routing.RoutingHelper)1