Android Auto के लिए नेविगेशन चालू करें

इस सेक्शन में यह बताया गया है कि अपने ऐप्लिकेशन के नेविगेशन अनुभव को इन-डैश हेड यूनिट पर दिखाने के लिए, 'कार के लिए Android ऐप्लिकेशन' की लाइब्रेरी के साथ नेविगेशन SDK टूल का इस्तेमाल कैसे किया जा सकता है. अगर किसी उपयोगकर्ता का इन-डैश सिस्टम Android Auto पर काम करता है, तो उपयोगकर्ता अपने फ़ोन को यूनिट से कनेक्ट करके, सीधे अपनी कार के डिसप्ले पर आपके ऐप्लिकेशन का इस्तेमाल कर सकते हैं. आवाज़ से रास्ता बताने की सुविधा, कार के स्पीकर पर भी काम करती है.

एक इन-डैश हेड यूनिट, जो Android Auto के लिए चालू किए गए ऐप्लिकेशन का इस्तेमाल करके, निर्देशों के साथ नेविगेशन दिखाता है.

कार के लिए Android ऐप्लिकेशन की लाइब्रेरी की मदद से, Android ऐप्लिकेशन को Android Auto पर चलाया जा सकता है. इसके लिए, ड्राइवर की सुरक्षा के लिए मंज़ूरी वाले विज़ुअल टेंप्लेट का सेट उपलब्ध कराया जाता है. ड्राइविंग

नेविगेशन SDK टूल की मदद से काम करने वाले ऐप्लिकेशन को Android Auto के साथ काम करने के लिए चालू करने पर, नेविगेशन अनुभव के लिए आपको एक अलग व्यू मिलता है. इससे दो मैप व्यू मिलते हैं—एक फ़ोन के लिए और दूसरा हेड यूनिट के लिए. दोनों डिसप्ले को Navigator.java से दिशा-निर्देश मिलता है, जो सिंगलटन है.

इन-डैशबोर्ड सिस्टम, सुरक्षा से जुड़े ऐसे इंटरैक्टिव एलिमेंट दिखाता है जिन्हें अनुमति मिली है. इससे लोग बिना किसी रुकावट के अपने डेस्टिनेशन पर सुरक्षित तरीके से नेविगेट कर सकते हैं. उपयोगकर्ता आपके ऐप्लिकेशन की खास सुविधाओं के साथ इंटरैक्ट भी कर सकता है. जैसे, ऑर्डर स्वीकार या अस्वीकार करना या मैप पर ग्राहक की जगह देखना. ऑर्डर की स्थिति के अपडेट, डैशबोर्ड यूनिट पर भी दिख सकते हैं.

एक इन-डैश हेड यूनिट, जो Android Auto के साथ मोड़-दर-मोड़ निर्देश दिखाता है. Android फ़ोन, जो खास जानकारी के लिए बताए गए रास्ते को दिखाता है.

अटैच किए गए फ़ोन पर, आपके ऐप्लिकेशन में स्टैंडर्ड नेविगेशन SDK टूल या कोई अन्य व्यू या वर्कफ़्लो दिखता रहेगा. इससे आपको अपनी पसंद के मुताबिक फ़ंक्शन बनाने में मदद मिलती है जो शायद कार की स्क्रीन पर ठीक से काम न करे.

सेट अप करें

अपने ऐप्लिकेशन को Android Auto के साथ काम करने के लिए सबसे पहले Android Auto के साथ कार सेवा सेट अप करें और फिर अपने नेविगेशन SDK ऐप्लिकेशन में TurnByTurn लाइब्रेरी को चालू करना शामिल है.

Android Auto से शुरू करें

Android Auto के साथ काम करने के लिए डिज़ाइन की गई नेविगेशन SDK सुविधाओं के साथ काम शुरू करने से पहले, आपको अपने ऐप्लिकेशन के लिए कार सेवा सेट अप करनी होगी, ताकि Android Auto उसे खोज सके.

इन चरणों का पालन करें, जो सभी Android for Cars डेवलपर दस्तावेज़ में मिल सकते हैं:

  1. Android Auto की बुनियादी सुविधाओं के बारे में जानें.
  2. Android for Cars ऐप्लिकेशन की लाइब्रेरी इंस्टॉल करें.
  3. अपने ऐप्लिकेशन की मेनिफ़ेस्ट फ़ाइल को कॉन्फ़िगर करें, ताकि इसमें Android Auto को शामिल किया जा सके.
  4. एलान करें कि अपने मेनिफ़ेस्ट में कार का ऐप्लिकेशन कम से कम 1 लेवल पर सेट हो.
  5. अपना CarAppService और सेशन बनाएं.

नेविगेशन SDK टूल सेट अप करना

कार ऐप्लिकेशन की सेवा शुरू करने के बाद, नेविगेशन SDK टूल का इस्तेमाल किया जा सकता है.

  1. अगर आपने अपने ऐप्लिकेशन में नेविगेशन SDK को पहले से इंटिग्रेट नहीं किया है, तो अपना प्रोजेक्ट सेट अप करें.
  2. अपने ऐप्लिकेशन के लिए टर्नबायटर्न दिशा-निर्देश फ़ीड चालू करें.
  3. ज़रूरी नहीं. नेविगेशन SDK टूल से मिले जनरेट किए गए आइकॉन का इस्तेमाल करें.
  4. Screen क्लास में दिए गए Android Auto Surface पर NavigationViewForAuto क्लास का इस्तेमाल करके, मैप बनाएं.
  5. Android Auto नेविगेशन टेंप्लेट को टर्नबायटर्न लाइब्रेरी के डेटा से भरें.

अब आपके पास अपने ऐप्लिकेशन के लिए नेविगेशन जानकारी देने के लिए एक रजिस्टर की गई सेवा है और आपका ऐप्लिकेशन Android Auto से कनेक्ट हो सकता है, इसलिए आप Android Auto के साथ आपके ऐप्लिकेशन के ठीक से काम करने के लिए ज़रूरी नेविगेशन एलिमेंट को बनाने के लिए तैयार हैं:

मैप और नेविगेशन यूज़र इंटरफ़ेस (यूआई) बनाएं

NavigationViewForAuto क्लास, Android Auto स्क्रीन पर मैप और नेविगेशन यूज़र इंटरफ़ेस (यूआई) रेंडर करती है. इसमें काफ़ी हद तक फ़ोन के लिए NavigationView जैसी ही सुविधाएं हैं. हालांकि, इनमें बहुत कम इंटरैक्ट किया जाता है. Android Auto से मिले प्लैटफ़ॉर्म पर ड्रॉ करने के लिए, NavigationViewForAuto का इस्तेमाल करें:

private boolean isSurfaceReady(SurfaceContainer surfaceContainer) {
  return surfaceContainer.getSurface() != null
        && surfaceContainer.getDpi() != 0
        && surfaceContainer.getHeight() != 0
        && surfaceContainer.getWidth() != 0;
}

@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
  if (!isSurfaceReady(surfaceContainer)) {
    return;
   }
  virtualDisplay =
      getCarContext()
          .getSystemService(DisplayManager.class)
          .createVirtualDisplay(
            VIRTUAL_DISPLAY_NAME,
            surfaceContainer.getWidth(),
            surfaceContainer.getHeight(),
            surfaceContainer.getDpi(),
            surfaceContainer.getSurface(),
            DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
    presentation = new Presentation(getCarContext(), virtualDisplay.getDisplay());

    navigationView = new NavigationViewForAuto(getCarContext());
    navigationView.onCreate(null);
    navigationView.onStart();
    navigationView.onResume();

    presentation.setContentView(navigationView);
    presentation.show();

    navigationView.getMapAsync(googleMap -> this.googleMap = googleMap);
  }

@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer) {
  navigationView.onPause();
  navigationView.onStop();
  navigationView.onDestroy();

  presentation.dismiss();
  virtualDisplay.release();
}

मैप इंटरैक्शन चालू करें

ड्राइवर की सुरक्षा के लिए, Android Auto, स्क्रीन पर होने वाले इंटरैक्शन को SurfaceCallback के अलग-अलग तरीकों के हिसाब से सीमित करता है. इन-डैश स्क्रीन पर मैप के साथ ड्राइवर के सीमित इंटरैक्शन की सुविधा देने के लिए, इन कॉलबैक का इस्तेमाल करें. उदाहरण के लिए, onClick और onScale, उपयोगकर्ता के टैप और पिंच जेस्चर के मुताबिक हैं. इंटरैक्टिविटी कॉलबैक को मैप ऐक्शन स्ट्रिप का इस्तेमाल, इस तरह करना चाहिए:

  • मैप इंटरैक्टिविटी कॉलबैक पाने के लिए, आपके ऐप्लिकेशन को Action.PAN बटन का इस्तेमाल करना होगा.

  • उपयोगकर्ता की अन्य कार्रवाइयों के लिए, मैप ऐक्शन बार में बटन जोड़ें.

सरफ़ेस कॉलबैक चालू करें

@NonNull
@Override
public Template onGetTemplate() {
  return new NavigationTemplate.Builder()
    .setActionStrip(new ActionStrip.Builder().build())
    .setMapActionStrip(new ActionStrip.Builder().addAction(Action.PAN).build())
    .build();
}

पिंच करके ज़ूम करें

@Override
public void onScale(float focusX, float focusY, float scaleFactor) {
  CameraUpdate update =
      CameraUpdateFactory.zoomBy((scaleFactor - 1),
                                  new Point((int) focusX, (int) focusY));
  googleMap.animateCamera(update); // map is set in onSurfaceAvailable.
}

पैनिंग

@Override
public void onScroll(float distanceX, float distanceY) {
  googleMap.moveCamera(CameraUpdateFactory.scrollBy(distanceX, distanceY));
}

नेविगेशन के निर्देश दिखाएं

इस सेक्शन में नेविगेशन पोस्ट के लिए ऑब्ज़र्वर सेट अप करने और टर्न कार्ड टेंप्लेट में नेविगेशन के निर्देश अपने-आप भरने का तरीका बताया गया है.

Android Auto के दिशा-निर्देश के लिए
टर्न कार्ड.

Android Auto नेविगेशन टेंप्लेट से आपको एक टर्न कार्ड मिलता है, जिसमें मौजूदा यात्रा से जुड़ी नेविगेशन की जानकारी दिखती है. नेविगेशन SDK टूल में मौजूद TurnByturn लाइब्रेरी, नेविगेशन की यह जानकारी देती है. इसका इस्तेमाल आपका कोड, Android Auto के नेविगेशन टेंप्लेट को पॉप्युलेट करने के लिए करता है.

ऑब्ज़र्वर सेट अप करना

नीचे दिए गए उदाहरण में, SampleApplication एक कस्टम ऐप्लिकेशन क्लास है, जो किसी MutableLiveData<NavInfo> ऑब्जेक्ट को बनाए रखता है. जब ऑब्ज़र्वर को नेविगेटर ऑब्जेक्ट से अपडेट मिलता है, तो यह NavInfo ऑब्जेक्ट को उस NavInfoMutableLiveData में पोस्ट करता है जिसे SampleApplication क्लास मैनेज करती है.

नीचे दिए गए उदाहरण में, Android Auto स्क्रीन को लागू करने के लिए, इस ऑब्जेक्ट के लिए एक ऑब्ज़र्वर रजिस्टर किया गया है.

public SampleAndroidAutoNavigationScreen(@NonNull CarContext carContext,
                                     SampleApplication application) {
  super(carContext);
  getCarContext().getCarService(AppManager.class).setSurfaceCallback(this);
  application.getNavInfoMutableLiveData().observe(this, this::processNextStep);
}

नेविगेशन की जानकारी अपने-आप भरना

नीचे दिया गया कोड स्निपेट यह दिखाता है कि Android Auto टेंप्लेट में रूटिंग की मौजूदा जानकारी कैसे डाली जाती है. इसमें चरण, दूरी, और आइकॉन शामिल हैं. फ़ीड डिसप्ले को भरें पेज पर जाकर, इन डिसप्ले एलिमेंट के बारे में ज़्यादा पढ़ा जा सकता है.

कोड का उदाहरण देखने के लिए बड़ा करें.

private RoutingInfo currentRoutingInfo;

@NonNull
@Override
public Template onGetTemplate() {
NavigationTemplate.Builder navigationTemplateBuilder =
  new NavigationTemplate.Builder()
    .setActionStrip(...)
    .setMapActionStrip(...)
  if (currentRoutingInfo != null) {
    navigationTemplateBuilder.setNavigationInfo(currentRoutingInfo);
  }
  return navigationTemplateBuilder.build();
}

private void processNextStep(NavInfo navInfo) {
  if (navInfo == null || navinfo.getCurrentStep() == null) {
    return;
  }

/**
*   Converts data received from the Navigation data feed
*   into Android-Auto compatible data structures. For more information
*   see the "Ensure correct maneuver types" below.
*/
  Step currentStep = buildStepFromStepInfo(navInfo.getCurrentStep());
  Distance distanceToStep =
              buildDistanceFromMeters(navInfo.getDistanceToCurrentStepMeters());

  currentRoutingInfo =
     new RoutingInfo.Builder().setCurrentStep(currentStep, distanceToStep).build();

  // Invalidate the current template which leads to another onGetTemplate call.
  invalidate();
}

private Step buildStepFromStepInfo(StepInfo stepInfo) {
  IconCompat maneuverIcon =
               IconCompat.createWithBitmap(stepInfo.getManeuverBitmap());
  Maneuver.Builder
            maneuverBuilder = newManeuver.Builder(
                  ManeuverConverter
                          .getAndroidAutoManeuverType(stepInfo.getManeuver()));
  CarIcon maneuverCarIcon = new CarIcon.Builder(maneuverIcon).build();
  maneuverBuilder.setIcon(maneuverCarIcon);
  Step.Builder stepBuilder =
    new Step.Builder()
       .setRoad(stepInfo.getFullRoadName())
       .setCue(stepInfo.getFullInstructionText())
       .setManeuver(maneuverBuilder.build());

  if (stepInfo.getLanes() != null
           && stepInfo.getLanesBitmap() != null) {
    for (Lane lane : buildAndroidAutoLanesFromStep(stepInfo)) {
      stepBuilder.addLane(lane);
    }
    IconCompat lanesIcon =
               IconCompat.createWithBitmap(stepInfo.getLanesBitmap());
    CarIcon lanesImage = new CarIcon.Builder(lanesIcon).build();
    stepBuilder.setLanesImage(lanesImage);
  }
    return stepBuilder.build();
}

/*
*   Constructs a {@code Distance} object in imperial measurement units.
*   In a real world scenario, units would be based on locale.
*/
private Distance buildDistanceFromMeters(int distanceMeters) {

// Distance can be negative so set the min distance to 0.
  int remainingFeet = (int) max(0, distanceMeters * DistanceConstants.FEET_PER_METER);
  double remainingMiles = ((double) remainingFeet) / DistanceConstants.FEET_PER_MILE;

// Only use the tenths place digit if distance is less than 10 miles and show
// feet if distance is less than 0.25 miles.

  if (remainingMiles >= DistanceConstants.MIN_MILES_TO_SHOW_INTEGER) {
    return Distance.create((int) round(remainingMiles), Distance.UNIT_MILES);
  } else if (remainingMiles >= 0.25) {
    return Distance.create((int) remainingMiles, Distance.UNIT_MILES);
  } else {
    return Distance.create(remainingFeet, Distance.UNIT_FEET);
  }
}

पक्का करें कि अलग-अलग तरह की गतिविधियां सही हों

Android Auto कार की लाइब्रेरी में इस्तेमाल किए जाने वाले दांव-पेच, दोनों एक-एक तरीके हैं. इन्हें TurnByTurn लाइब्रेरी की मदद से उपलब्ध कराया गया है. हालांकि, आपको नेविगेशन SDK टूल की मदद से, Android Auto Car लाइब्रेरी में दिए गए निर्देश को एक मान्य जानकारी में बदलना होगा. नीचे दी गई टेबल में कुछ फ़ील्ड के पत्रों से जुड़े नतीजे दिखाए गए हैं. इसके बाद, आपकी सुविधा के लिए सैंपल कन्वर्टर टूल का इस्तेमाल किया गया है.

मोड़-दर-मोड़ लाइब्रेरी मैन्युवर Android Auto की सुविधा
DEPART TYPE_DEPART
DESTINATION TYPE_DESTINATION
DESTINATION_LEFT TYPE_DESTINATION_LEFT
DESTINATION_RIGHT TYPE_DESTINATION_RIGHT
TURN_U_TURN_CLOCKWISE TYPE_U_TURN_RIGHT
ON_RAMP_LEFT TYPE_ON_RAMP_NORMAL_LEFT
ON_RAMP_RIGHT TYPE_ON_RAMP_NORMAL_RIGHT
ON_RAMP_SLIGHT_LEFT TYPE_ON_RAMP_SLIGHT_LEFT
FORK_RIGHT TYPE_FORK_RIGHT

कोड का उदाहरण देखने के लिए बड़ा करें.

import com.google.android.libraries.mapsplatform.turnbyturn.model.Maneuver;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;

/** Converter that converts between turn-by-turn and Android Auto Maneuvers. */
public final class ManeuverConverter {
  private ManeuverConverter() {}

  // Map from turn-by-turn Maneuver to Android Auto Maneuver.Type.
  private static final ImmutableMap<Integer, Integer> MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE =
      ImmutableMap.<Integer, Integer>builder()
          .put(Maneuver.DEPART, androidx.car.app.navigation.model.Maneuver.TYPE_DEPART)
          .put(Maneuver.DESTINATION, androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION)
          .put(
              Maneuver.DESTINATION_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION_LEFT)
          .put(
              Maneuver.DESTINATION_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION_RIGHT)
          .put(Maneuver.STRAIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_STRAIGHT)
          .put(Maneuver.TURN_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_NORMAL_LEFT)
          .put(
              Maneuver.TURN_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_TURN_NORMAL_RIGHT)
          .put(Maneuver.TURN_KEEP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_KEEP_LEFT)
          .put(Maneuver.TURN_KEEP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_KEEP_RIGHT)
          .put(
              Maneuver.TURN_SLIGHT_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SLIGHT_LEFT)
          .put(
              Maneuver.TURN_SLIGHT_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SLIGHT_RIGHT)
          .put(
              Maneuver.TURN_SHARP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SHARP_LEFT)
          .put(
              Maneuver.TURN_SHARP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_RIGHT)
          .put(
              Maneuver.TURN_U_TURN_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_U_TURN_RIGHT)
          .put(
              Maneuver.TURN_U_TURN_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_U_TURN_LEFT)
          .put(
              Maneuver.MERGE_UNSPECIFIED,
              androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_SIDE_UNSPECIFIED)
          .put(Maneuver.MERGE_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_LEFT)
          .put(Maneuver.MERGE_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_RIGHT)
          .put(Maneuver.FORK_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_FORK_LEFT)
          .put(Maneuver.FORK_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_FORK_RIGHT)
          .put(
              Maneuver.ON_RAMP_UNSPECIFIED,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT)
          .put(
              Maneuver.ON_RAMP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_LEFT)
          .put(
              Maneuver.ON_RAMP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT)
          .put(
              Maneuver.ON_RAMP_KEEP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_LEFT)
          .put(
              Maneuver.ON_RAMP_KEEP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT)
          .put(
              Maneuver.ON_RAMP_SLIGHT_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SLIGHT_LEFT)
          .put(
              Maneuver.ON_RAMP_SLIGHT_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SLIGHT_RIGHT)
          .put(
              Maneuver.ON_RAMP_SHARP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_LEFT)
          .put(
              Maneuver.ON_RAMP_SHARP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_RIGHT)
          .put(
              Maneuver.ON_RAMP_U_TURN_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_U_TURN_RIGHT)
          .put(
              Maneuver.ON_RAMP_U_TURN_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_U_TURN_LEFT)
          .put(
              Maneuver.OFF_RAMP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_LEFT)
          .put(
              Maneuver.OFF_RAMP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_RIGHT)
          .put(
              Maneuver.OFF_RAMP_KEEP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_LEFT)
          .put(
              Maneuver.OFF_RAMP_KEEP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_RIGHT)
          .put(
              Maneuver.OFF_RAMP_SLIGHT_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_LEFT)
          .put(
              Maneuver.OFF_RAMP_SLIGHT_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_RIGHT)
          .put(
              Maneuver.OFF_RAMP_SHARP_LEFT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_LEFT)
          .put(
              Maneuver.OFF_RAMP_SHARP_RIGHT,
              androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_RIGHT)
          .put(
              Maneuver.ROUNDABOUT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW)
          .put(
              Maneuver.ROUNDABOUT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW)
          .put(
              Maneuver.ROUNDABOUT_STRAIGHT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_CW)
          .put(
              Maneuver.ROUNDABOUT_STRAIGHT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_CCW)
          .put(
              Maneuver.ROUNDABOUT_LEFT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_LEFT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_RIGHT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_RIGHT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SLIGHT_LEFT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SLIGHT_LEFT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SLIGHT_RIGHT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SLIGHT_RIGHT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SHARP_LEFT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SHARP_LEFT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SHARP_RIGHT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_SHARP_RIGHT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_U_TURN_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_U_TURN_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver
                  .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE)
          .put(
              Maneuver.ROUNDABOUT_EXIT_CLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_EXIT_CW)
          .put(
              Maneuver.ROUNDABOUT_EXIT_COUNTERCLOCKWISE,
              androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_EXIT_CCW)
          .put(Maneuver.FERRY_BOAT, androidx.car.app.navigation.model.Maneuver.TYPE_FERRY_BOAT)
          .put(Maneuver.FERRY_TRAIN, androidx.car.app.navigation.model.Maneuver.TYPE_FERRY_TRAIN)
          .put(Maneuver.NAME_CHANGE, androidx.car.app.navigation.model.Maneuver.TYPE_NAME_CHANGE)
          .buildOrThrow();

  /** Represents the roundabout turn angle for a slight turn in either right or left directions. */
  private static final int ROUNDABOUT_ANGLE_SLIGHT = 10;

  /** Represents the roundabout turn angle for a normal turn in either right or left directions. */
  private static final int ROUNDABOUT_ANGLE_NORMAL = 45;

  /** Represents the roundabout turn angle for a sharp turn in either right or left directions. */
  private static final int ROUNDABOUT_ANGLE_SHARP = 135;

  /** Represents the roundabout turn angle for a u-turn in either right or left directions. */
  private static final int ROUNDABOUT_ANGLE_U_TURN = 180;

  /**
   * Returns the corresponding {@link androidx.car.app.navigation.model.Maneuver.Type} for the given
   * direction {@link Maneuver}
   *
   * @throws {@link IllegalArgumentException} if the given maneuver does not have a corresponding
   *     Android Auto Maneuver type.
   */
  public static int getAndroidAutoManeuverType(@Maneuver int maneuver) {
    if (MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE.containsKey(maneuver)) {
      return MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE.get(maneuver);
    }
    throw new IllegalArgumentException(
        String.format(
            "Given turn-by-turn Maneuver %d cannot be converted to an Android Auto equivalent.",
            maneuver));
  }

  /**
   * Returns the corresponding Android Auto roundabout angle for the given turn {@link Maneuver}.
   * Returns {@code null} if given maneuver does not involve a roundabout with a turn.
   */
  @Nullable
  public static Integer getAndroidAutoRoundaboutAngle(@Maneuver int maneuver) {
    if (maneuver == Maneuver.ROUNDABOUT_LEFT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_RIGHT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_LEFT_COUNTERCLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_RIGHT_COUNTERCLOCKWISE) {
      return ROUNDABOUT_ANGLE_NORMAL;
    }
    if (maneuver == Maneuver.ROUNDABOUT_SHARP_LEFT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SHARP_RIGHT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SHARP_LEFT_COUNTERCLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SHARP_RIGHT_COUNTERCLOCKWISE) {
      return ROUNDABOUT_ANGLE_SHARP;
    }
    if (maneuver == Maneuver.ROUNDABOUT_SLIGHT_LEFT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SLIGHT_RIGHT_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SLIGHT_LEFT_COUNTERCLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_SLIGHT_RIGHT_COUNTERCLOCKWISE) {
      return ROUNDABOUT_ANGLE_SLIGHT;
    }
    if (maneuver == Maneuver.ROUNDABOUT_U_TURN_CLOCKWISE
        || maneuver == Maneuver.ROUNDABOUT_U_TURN_COUNTERCLOCKWISE) {
      return ROUNDABOUT_ANGLE_U_TURN;
    }
    return null;
  }
}