Skip to content

Commit 4fc2429

Browse files
committed
docs: make android auto and carplay documentation part of the dart docs
1 parent 7ed6692 commit 4fc2429

12 files changed

+190
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ await mapViewController.setMapColorScheme(MapColorScheme.dark);
348348
## Support for Android Auto and Apple CarPlay
349349
This plugin is compatible with both Android Auto and Apple CarPlay infotainment systems. For more details, please refer to the respective platform documentation:
350350

351-
- [Android Auto documentation](./ANDROIDAUTO.md)
352-
- [CarPlay documentation](./CARPLAY.md)
351+
- [Android Auto documentation](./doc/android-auto.md)
352+
- [CarPlay documentation](./doc/carplay.md)
353353

354354
## Known issues
355355

dartdoc_options.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ dartdoc:
2626
"Image Registry":
2727
markdown: doc/image-registry.md
2828
name: Image Registry
29-
categoryOrder: ["Navigation", "Navigation View", "Map View", "Image Registry"]
29+
"Android Auto":
30+
markdown: doc/android-auto.md
31+
name: Android Auto
32+
"Carplay":
33+
markdown: doc/carplay.md
34+
name: Carplay
35+
categoryOrder:
36+
[
37+
"Navigation",
38+
"Navigation View",
39+
"Map View",
40+
"Image Registry",
41+
"Android Auto",
42+
"Carplay",
43+
]
3044
showUndocumentedCategories: true
31-
nodoc: ['**/*.g.dart']
32-
45+
nodoc: ["**/*.g.dart"]

doc/android-auto.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Navigation for Android Auto
2+
3+
This guide explains how to enable and integrate Android Auto with the Flutter Navigation SDK.
4+
5+
## Requirements
6+
7+
- Android device
8+
- Android Auto test device or Android Automotive OS emulator
9+
10+
## Setup
11+
12+
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:
13+
14+
- Installing Android for Cars App Library.
15+
- Configuring your app's manifest file to include Android Auto.
16+
- Declaring a minimum car-app level in your manifest.
17+
- Creating 'CarAppService' and session
18+
19+
For all the steps above, you can refer to the Android example application for guidance.
20+
21+
### Screen for Android Auto
22+
23+
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.
24+
25+
Please refer to the `SampleAndroidAutoScreen.kt` file in the Android example app for guidance.
26+
27+
To customize the Android Auto experience, override the `onGetTemplate` method in your custom AndroidAutoScreen class, providing your own `Template`:
28+
29+
```kotlin
30+
override fun onGetTemplate(): Template {
31+
/** ... */
32+
@SuppressLint("MissingPermission")
33+
val navigationTemplateBuilder =
34+
NavigationTemplate.Builder()
35+
.setActionStrip(
36+
ActionStrip.Builder()
37+
.addAction(
38+
Action.Builder()
39+
.setTitle("Re-center")
40+
.setOnClickListener {
41+
if (mGoogleMap == null) return@setOnClickListener
42+
mGoogleMap!!.followMyLocation(GoogleMap.CameraPerspective.TILTED)
43+
}
44+
.build())
45+
.addAction(
46+
Action.Builder()
47+
.setTitle("Custom event")
48+
.setOnClickListener {
49+
sendCustomNavigationAutoEvent("CustomAndroidAutoEvent", mapOf("sampleDataKey" to "sampleDataContent"))
50+
}
51+
.build())
52+
.build())
53+
.setMapActionStrip(ActionStrip.Builder().addAction(Action.PAN).build())
54+
/** ... */
55+
}
56+
```
57+
58+
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.
59+
60+
### Flutter Setup
61+
62+
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.
63+
64+
```dart
65+
final GoogleMapsAutoViewController _autoViewController =
66+
GoogleMapsAutoViewController();
67+
68+
_autoViewController.listenForCustomNavigationAutoEvents((event) {
69+
showMessage("Received event: ${event.event}");
70+
});
71+
72+
Future<void> _setMapTypeForAutoToSatellite() async {
73+
await _autoViewController.setMapType(mapType: MapType.satellite);
74+
}
75+
```
76+
77+
For a more detailed example, refer to the `lib/pages/navigation.dart` file in the Flutter example application.
78+
79+
## Example Project
80+
81+
For a fully functional Android Auto implementation, check out the [Android Studio example app](./example/android/).

doc/carplay.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Navigation for Apple CarPlay
2+
3+
This guide explains how to enable and integrate Apple CarPlay with the Flutter SDK.
4+
5+
## Requirements
6+
7+
- iOS device or iOS simulator
8+
- CarPlay Simulator
9+
- CarPlay entitlement for your application (provided by Apple)
10+
11+
## Setup
12+
13+
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:
14+
15+
- Adding the CarPlay entitlement to your Xcode project.
16+
- Creating a separate scene for the CarPlay map and enabling support for multiple scenes.
17+
18+
### SceneDelegate for CarPlay
19+
20+
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.
21+
22+
Please refer to the `CarSceneDelegate.swift` file in the iOS example app for guidance.
23+
24+
To customize the CarPlay experience, override the `getTemplate` method in your custom `CarSceneDelegate` class, providing your own `CPMapTemplate`:
25+
26+
```swift
27+
override func getTemplate() -> CPMapTemplate {
28+
let template = CPMapTemplate()
29+
template.showPanningInterface(animated: true)
30+
31+
let button = CPBarButton(title: "Custom Event") { [weak self] _ in
32+
let data = ["sampleDataKey": "sampleDataContent"]
33+
self?.sendCustomNavigationAutoEvent(event: "CustomCarPlayEvent", data: data)
34+
}
35+
template.leadingNavigationBarButtons = [button]
36+
return template
37+
}
38+
```
39+
40+
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.
41+
42+
### Flutter Setup
43+
44+
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.
45+
46+
```dart
47+
final GoogleMapsAutoViewController _autoViewController =
48+
GoogleMapsAutoViewController();
49+
50+
_autoViewController.listenForCustomNavigationAutoEvents((event) {
51+
showMessage("Received event: ${event.event}");
52+
});
53+
54+
Future<void> _setMapTypeForAutoToSatellite() async {
55+
await _autoViewController.setMapType(mapType: MapType.satellite);
56+
}
57+
```
58+
59+
For a more detailed example, refer to the `lib/pages/navigation.dart` file in the Flutter example application.
60+
61+
## Example Project
62+
63+
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.

lib/src/google_maps_auto_view_controller.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import 'package:flutter/widgets.dart';
1717
import '../google_navigation_flutter.dart';
1818
import 'google_navigation_flutter_platform_interface.dart';
1919

20+
/// {@category Android Auto}
21+
/// {@category Carplay}
2022
class GoogleMapsAutoViewController {
2123
GoogleMapsAutoViewController() {
2224
GoogleMapsNavigationPlatform.instance.autoAPI.ensureAutoViewApiSetUp();

lib/src/types/circles.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import '../utils/color.dart';
2121
/// Circle that has beed added to map.
2222
/// {@category Navigation View}
2323
/// {@category Map View}
24+
/// {@category Android Auto}
25+
/// {@category Carplay}
2426
@immutable
2527
class Circle {
2628
/// Construct [Circle].

lib/src/types/lat_lng.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import 'package:flutter/foundation.dart';
1818
/// {@category Navigation}
1919
/// {@category Navigation View}
2020
/// {@category Map View}
21+
/// {@category Android Auto}
22+
/// {@category Carplay}
2123
@immutable
2224
class LatLng {
2325
/// Initializes a [LatLng] with the provided latitude and longitude values.

lib/src/types/lat_lng_bounds.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import '../../google_navigation_flutter.dart';
1919
/// LatLngBounds bounds object.
2020
/// {@category Navigation View}
2121
/// {@category Map View}
22+
/// {@category Android Auto}
23+
/// {@category Carplay}
2224
@immutable
2325
class LatLngBounds {
2426
/// Initialize LatLngBounds with the given southwest and northeast points.

lib/src/types/markers.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import '../../google_navigation_flutter.dart';
1919
/// Marker that has beed added to the map.
2020
/// {@category Navigation View}
2121
/// {@category Map View}
22+
/// {@category Android Auto}
23+
/// {@category Carplay}
2224
@immutable
2325
class Marker {
2426
/// Construct [Marker]

lib/src/types/navigation_view_types.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class NavigationViewRecenterButtonClickedEvent {}
2323
/// Map type.
2424
/// {@category Navigation View}
2525
/// {@category Map View}
26+
/// {@category Android Auto}
27+
/// {@category Carplay}
2628
enum MapType {
2729
/// No type set.
2830
none,
@@ -76,6 +78,8 @@ enum NavigationForceNightMode {
7678
/// Represents the camera position in a Google Maps view.
7779
/// {@category Navigation View}
7880
/// {@category Map View}
81+
/// {@category Android Auto}
82+
/// {@category Carplay}
7983
class CameraPosition {
8084
/// Creates a [CameraPosition] object with map centered
8185
/// to the [target] with the given [bearing], [tilt] and [zoom] level.
@@ -123,6 +127,8 @@ class CameraPosition {
123127
/// to specify the orientation of the camera.
124128
/// {@category Navigation View}
125129
/// {@category Map View}
130+
/// {@category Android Auto}
131+
/// {@category Carplay}
126132
enum CameraPerspective {
127133
/// A tilted perspective facing in the same direction as the user.
128134
tilted,
@@ -134,6 +140,9 @@ enum CameraPerspective {
134140
topDownNorthUp,
135141
}
136142

143+
/// {@category Navigation}
144+
/// {@category Android Auto}
145+
/// {@category Carplay}
137146
class CustomNavigationAutoEvent {
138147
final String? event;
139148
final Object? data;
@@ -144,6 +153,9 @@ class CustomNavigationAutoEvent {
144153
String toString() => 'CustomNavigationAutoEvent(event: $event, data: $data)';
145154
}
146155

156+
/// {@category Navigation}
157+
/// {@category Android Auto}
158+
/// {@category Carplay}
147159
class AutoScreenAvailabilityChangedEvent {
148160
final bool isAvailable;
149161

@@ -347,6 +359,8 @@ enum CameraUpdateType {
347359
/// the current position.
348360
/// {@category Navigation View}
349361
/// {@category Map View}
362+
/// {@category Android Auto}
363+
/// {@category Carplay}
350364
class CameraUpdate {
351365
CameraUpdate._(this.type);
352366

0 commit comments

Comments
 (0)