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

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

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

Android for Cars ऐप्लिकेशन लाइब्रेरी, 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 ऐप्लिकेशन लाइब्रेरी इंस्टॉल करें.
  3. Android Auto को शामिल करने के लिए, अपने ऐप्लिकेशन की मेनिफ़ेस्ट फ़ाइल को कॉन्फ़िगर करें.
  4. अपने मेनिफ़ेस्ट में कार-ऐप्लिकेशन लेवल का कम से कम एक लेवल एलान करें.
  5. अपना CarAppService और सेशन बनाएं.

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

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

  1. अगर आपने अपने ऐप्लिकेशन में नेविगेशन SDK टूल को पहले से इंटिग्रेट नहीं किया है, तो अपना प्रोजेक्ट सेट अप करें.
  2. अपने ऐप्लिकेशन के लिए, Turnbyturn दिशा-निर्देश फ़ीड चालू करें.
  3. ज़रूरी नहीं. नेविगेशन SDK से जनरेट किए गए आइकॉन इस्तेमाल करें.
  4. Screen क्लास में दिए गए Android Auto Surface पर NavigationViewForAuto क्लास का इस्तेमाल करके, मैप ड्रॉ करें.
  5. TurnbyTurn लाइब्रेरी के डेटा की मदद से 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 Car की लाइब्रेरी में जिस तरह की कलाएं इस्तेमाल की जाती हैं वे TurnByTurn लाइब्रेरी के ज़रिए उपलब्ध कराई जाती हैं. हालांकि, आपको नेविगेशन SDK टूल में, ऐसी जानकारी को Android Auto कार लाइब्रेरी में मान्य जानकारी में बदलना होगा. नीचे दी गई टेबल में कुछ फ़ील्ड से जुड़े संपर्क दिखाए गए हैं. इसके बाद, आपकी सुविधा के लिए कन्वर्टर यूटिलिटी का एक सैंपल दिया गया है.

बारी-बारी से लाइब्रेरी की कला 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;
  }
}