Skip to content

Commit

Permalink
docs: add aa and carplay docs
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminati1911 committed Nov 7, 2024
1 parent 2a27eff commit b657006
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 3 deletions.
80 changes: 80 additions & 0 deletions ANDROIDAUTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Navigation for Android Auto

This guide explains how to enable and integrate Android Auto with the Flutter Navigation SDK.

## Requirements

- Android device
- Android Auto test device or Android Automotive OS emulator

## Setup

Refer to the [Android for Cars developer documentation](https://developer.android.com/training/cars) to understand how the Android Auto works and to complete the initial setup. Key steps include:

- Installing Android for Cars App Library.
- Configuring your app's manifest file to include Android Auto.
- Declaring a minimum car-app level in your manifest.
- Creating 'CarAppService' and session

For all the steps above, you can refer to the Android example application for guidance.

### Screen for Android Auto

Once your project is configured accordingly, and you are ready to build the screen for Android Auto, you can leverage the `AndroidAutoBaseScreen` provided by the SDK. This base class simplifies the setup by handling initialization, teardown, and rendering the map on the Android Auto display.

Please refer to the `SampleAndroidAutoScreen.kt` file in the Android example app for guidance.

To customize the Android Auto experience, override the `onGetTemplate` method in your custom AndroidAutoScreen class, providing your own `Template`:

```kotlin
override fun onGetTemplate(): Template {
/** ... */
@SuppressLint("MissingPermission") val navigationTemplateBuilder =
NavigationTemplate.Builder()
.setActionStrip(
ActionStrip.Builder()
.addAction(
Action.Builder()
.setTitle("Re-center")
.setOnClickListener {
if (mGoogleMap == null) return@setOnClickListener
mGoogleMap!!.followMyLocation(GoogleMap.CameraPerspective.TILTED)
}
.build())
.addAction(
Action.Builder()
.setTitle("Custom event")
.setOnClickListener {
sendCustomNavigationAutoEvent("CustomAndroidAutoEvent", mapOf("sampleDataKey" to "sampleDataContent"))
}
.build())
.build())
.setMapActionStrip(ActionStrip.Builder().addAction(Action.PAN).build())
/** ... */
}
```

For advanced customization, you can bypass the base class and implement your own screen by inheriting `Screen`. You can use the provided `AndroidAutoBaseScreen` base class as a reference on how to do that.

### Flutter Setup

On the Flutter side, you can use the `GoogleMapsAutoViewController` to interface with the CarPlay instance. The `GoogleMapsAutoViewController` allows you to call map functions on the CarPlay map view, and you can manage listeners using the provided functions.

```dart
final GoogleMapsAutoViewController _autoViewController =
GoogleMapsAutoViewController();
_autoViewController.listenForCustomNavigationAutoEvents((event) {
showMessage("Received event: ${event.event}");
});
Future<void> _setMapTypeForAutoToSatellite() async {
await _autoViewController.setMapType(mapType: MapType.satellite);
}
```

For a more detailed example, refer to the `lib/pages/navigation.dart` file in the Flutter example application.

## Example Project

For a fully functional Android Auto implementation, check out the [Android Studio example app](./example/android/).
63 changes: 63 additions & 0 deletions CARPLAY.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Navigation for Apple CarPlay

This guide explains how to enable and integrate Apple CarPlay with the Flutter SDK.

## Requirements

- iOS device or iOS simulator
- CarPlay Simulator
- CarPlay entitlement for your application (provided by Apple)

## Setup

Refer to the [Apple CarPlay Developer Guide](https://developer.apple.com/carplay/) to understand how CarPlay works and to complete the initial setup. Key steps include:

- Adding the CarPlay entitlement to your Xcode project.
- Creating a separate scene for the CarPlay map and enabling support for multiple scenes.

### SceneDelegate for CarPlay

Once your project is configured to support multiple scenes, and you are setting up a dedicated scene for CarPlay, you can leverage the `BaseCarSceneDelegate` provided by the SDK. This base class simplifies the setup by handling initialization, teardown, and rendering the map on the CarPlay display.

Please refer to the `CarSceneDelegate.swift` file in the iOS example app for guidance.

To customize the CarPlay experience, override the `getTemplate` method in your custom `CarSceneDelegate` class, providing your own `CPMapTemplate`:

```swift
override func getTemplate() -> CPMapTemplate {
let template = CPMapTemplate()
template.showPanningInterface(animated: true)

let button = CPBarButton(title: "Custom Event") { [weak self] _ in
let data = ["sampleDataKey": "sampleDataContent"]
self?.sendCustomNavigationAutoEvent(event: "CustomCarPlayEvent", data: data)
}
template.leadingNavigationBarButtons = [button]
return template
}
```

For advanced customization, you can bypass the base class and implement your own delegate inheriting `CPTemplateApplicationSceneDelegate`. You can use the provided `BaseCarSceneDelegate` base class as a reference on how to do that.

### Flutter Setup

On the Flutter side, you can use the `GoogleMapsAutoViewController` to interface with the CarPlay instance. The `GoogleMapsAutoViewController` allows you to call map functions on the CarPlay map view, and you can manage listeners using the provided functions.

```dart
final GoogleMapsAutoViewController _autoViewController =
GoogleMapsAutoViewController();
_autoViewController.listenForCustomNavigationAutoEvents((event) {
showMessage("Received event: ${event.event}");
});
Future<void> _setMapTypeForAutoToSatellite() async {
await _autoViewController.setMapType(mapType: MapType.satellite);
}
```

For a more detailed example, refer to the `lib/pages/navigation.dart` file in the Flutter example application.

## Example Project

For a fully functional CarPlay implementation, check out the [Runner](./example/ios/) Xcode project, which includes the `RunnerCarPlay` build target. The sample already contains test entitlement so you don't need to request one from Apple to run it.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ Widget build(BuildContext context) {
}
```

## Support for Android Auto and Apple CarPlay
This plugin is compatible with both Android Auto and Apple CarPlay infotainment systems. For more details, please refer to the respective platform documentation:

- [Android Auto documentation](./ANDROIDAUTO.md)
- [CarPlay documentation](./CARPLAY.md)

## Contributing

See the [Contributing guide](https://github.com/googlemaps/flutter-navigation-sdk/blob/main/CONTRIBUTING.md).
Expand Down
6 changes: 3 additions & 3 deletions example/lib/pages/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
setState(() {});
}

Future<void> _setMapTypeForAuto() async {
Future<void> _setMapTypeForAutoToSatellite() async {
await _autoViewController.setMapType(mapType: MapType.satellite);
}

Expand Down Expand Up @@ -1459,8 +1459,8 @@ class _NavigationPageState extends ExamplePageState<NavigationPage> {
!_navigatorInitialized || _navigationViewController == null),
children: <Widget>[
ElevatedButton(
onPressed: () => _setMapTypeForAuto(),
child: const Text('Set map type'),
onPressed: () => _setMapTypeForAutoToSatellite(),
child: const Text('Set map type to satellite'),
),
ElevatedButton(
onPressed: () => _moveCameraForAuto(),
Expand Down

0 comments on commit b657006

Please sign in to comment.