public void executeInstructions()

in car_app_library/navigation/common/src/main/java/androidx/car/app/sample/navigation/common/nav/NavigationService.java [193:325]


    public void executeInstructions(@NonNull List<Instruction> instructions) {
        mScript =
                Script.execute(
                        instructions,
                        (instruction, nextInstruction) -> {
                            switch (instruction.getType()) {
                                case START_NAVIGATION:
                                    startNavigation();
                                    break;
                                case END_NAVIGATION:
                                    endNavigationFromScript();
                                    break;
                                case ADD_DESTINATION_NAVIGATION:
                                    Destination destination = instruction.getDestination();
                                    mDestinations.add(destination);
                                    break;
                                case POP_DESTINATION_NAVIGATION:
                                    mDestinations.remove(0);
                                    break;
                                case ADD_STEP_NAVIGATION:
                                    Step step = instruction.getStep();
                                    mSteps.add(step);
                                    break;
                                case POP_STEP_NAVIGATION:
                                    mSteps.remove(0);
                                    break;
                                case SET_TRIP_POSITION_NAVIGATION:
                                    if (mIsNavigating) {
                                        TravelEstimate destinationTravelEstimate =
                                                instruction.getDestinationTravelEstimate();
                                        TravelEstimate stepTravelEstimate =
                                                instruction.getStepTravelEstimate();
                                        Trip.Builder tripBuilder = new Trip.Builder();
                                        tripBuilder
                                                .addStep(mSteps.get(0), stepTravelEstimate)
                                                .addDestination(
                                                        mDestinations.get(0),
                                                        destinationTravelEstimate)
                                                .setLoading(false);

                                        if (instruction.getShouldShowNextStep()
                                                && nextInstruction != null && mSteps.size() > 1) {
                                            Step nextStep = mSteps.get(1);
                                            TravelEstimate nextStepTravelEstimate =
                                                    nextInstruction.getStepTravelEstimate();
                                            if (nextStepTravelEstimate != null) {
                                                tripBuilder.addStep(nextStep,
                                                        nextStepTravelEstimate);
                                            }
                                        }

                                        String road = instruction.getRoad();
                                        if (road != null) {
                                            tripBuilder.setCurrentRoad(road);
                                        }
                                        mNavigationManager.updateTrip(tripBuilder.build());

                                        if (++mStepsSent % 10 == 0) {
                                            // For demo purposes only play audio of next turn every
                                            // 10 steps.
                                            playNavigationDirection(R.raw.turn_right);
                                            mNotificationManager.notify(
                                                    NOTIFICATION_ID,
                                                    getTrafficAccidentWarningNotification());
                                        }

                                        update(
                                                /* isNavigating= */ true,
                                                /* isRerouting= */ false,
                                                /* hasArrived= */ false,
                                                mDestinations,
                                                mSteps,
                                                destinationTravelEstimate,
                                                instruction.getStepRemainingDistance(),
                                                instruction.getShouldNotify(),
                                                instruction.getNotificationTitle(),
                                                instruction.getNotificationContent(),
                                                instruction.getNotificationIcon(),
                                                instruction.getShouldShowNextStep(),
                                                instruction.getShouldShowLanes(),
                                                instruction.getJunctionImage());
                                    }
                                    break;
                                case SET_REROUTING:
                                    if (mIsNavigating) {
                                        TravelEstimate destinationTravelEstimate =
                                                instruction.getDestinationTravelEstimate();
                                        Trip.Builder tripBuilder = new Trip.Builder();
                                        tripBuilder
                                                .addDestination(
                                                        mDestinations.get(0),
                                                        destinationTravelEstimate)
                                                .setLoading(true);
                                        mNavigationManager.updateTrip(tripBuilder.build());
                                        update(
                                                /* isNavigating= */ true,
                                                /* isRerouting= */ true,
                                                /* hasArrived= */ false,
                                                null,
                                                null,
                                                null,
                                                null,
                                                instruction.getShouldNotify(),
                                                instruction.getNotificationTitle(),
                                                instruction.getNotificationContent(),
                                                instruction.getNotificationIcon(),
                                                instruction.getShouldShowNextStep(),
                                                instruction.getShouldShowLanes(),
                                                instruction.getJunctionImage());
                                    }
                                    break;
                                case SET_ARRIVED:
                                    if (mIsNavigating) {
                                        update(
                                                /* isNavigating= */ true,
                                                /* isRerouting= */ false,
                                                /* hasArrived= */ true,
                                                mDestinations,
                                                null,
                                                null,
                                                null,
                                                instruction.getShouldNotify(),
                                                instruction.getNotificationTitle(),
                                                instruction.getNotificationContent(),
                                                instruction.getNotificationIcon(),
                                                instruction.getShouldShowNextStep(),
                                                instruction.getShouldShowLanes(),
                                                instruction.getJunctionImage());
                                    }
                                    break;
                            }
                        });
    }