Skip to content

Commit 8b2a22e

Browse files
[Android Auto] Working on android auto docs (#6569)
* Working on android auto docs * simplify wording * Update libnavui-androidauto/src/main/java/com/mapbox/androidauto/screenmanager/MapboxScreen.kt Co-authored-by: Abhishek Kejriwal <abhishek.kejriwal@mapbox.com> Co-authored-by: Abhishek Kejriwal <abhishek.kejriwal@mapbox.com>
1 parent 37b8722 commit 8b2a22e

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

libnavui-androidauto/api/current.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ package com.mapbox.androidauto.screenmanager {
658658
field public static final String FREE_DRIVE = "MAPBOX_FREE_DRIVE";
659659
field public static final String FREE_DRIVE_FEEDBACK = "MAPBOX_FREE_DRIVE_FEEDBACK";
660660
field public static final String GEO_DEEPLINK = "MAPBOX_GEO_DEEPLINK";
661+
field public static final String GEO_DEEPLINK_FEEDBACK = "MAPBOX_GEO_DEEPLINK_FEEDBACK";
661662
field public static final com.mapbox.androidauto.screenmanager.MapboxScreen INSTANCE;
662663
field public static final String NEEDS_LOCATION_PERMISSION = "MAPBOX_NEEDS_LOCATION_PERMISSION";
663664
field public static final String ROUTE_PREVIEW = "MAPBOX_ROUTE_PREVIEW";
@@ -667,7 +668,7 @@ package com.mapbox.androidauto.screenmanager {
667668
field public static final String SETTINGS = "MAPBOX_SETTINGS";
668669
}
669670

670-
@StringDef({com.mapbox.androidauto.screenmanager.MapboxScreen.NEEDS_LOCATION_PERMISSION, com.mapbox.androidauto.screenmanager.MapboxScreen.SETTINGS, com.mapbox.androidauto.screenmanager.MapboxScreen.FREE_DRIVE, com.mapbox.androidauto.screenmanager.MapboxScreen.SEARCH, com.mapbox.androidauto.screenmanager.MapboxScreen.SEARCH_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.FAVORITES, com.mapbox.androidauto.screenmanager.MapboxScreen.FAVORITES_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.GEO_DEEPLINK, com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW, com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.ACTIVE_GUIDANCE, com.mapbox.androidauto.screenmanager.MapboxScreen.ACTIVE_GUIDANCE_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.ARRIVAL}) @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) public static @interface MapboxScreen.Key {
671+
@StringDef({com.mapbox.androidauto.screenmanager.MapboxScreen.NEEDS_LOCATION_PERMISSION, com.mapbox.androidauto.screenmanager.MapboxScreen.SETTINGS, com.mapbox.androidauto.screenmanager.MapboxScreen.FREE_DRIVE, com.mapbox.androidauto.screenmanager.MapboxScreen.SEARCH, com.mapbox.androidauto.screenmanager.MapboxScreen.SEARCH_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.FAVORITES, com.mapbox.androidauto.screenmanager.MapboxScreen.FAVORITES_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.GEO_DEEPLINK, com.mapbox.androidauto.screenmanager.MapboxScreen.GEO_DEEPLINK_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW, com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.ACTIVE_GUIDANCE, com.mapbox.androidauto.screenmanager.MapboxScreen.ACTIVE_GUIDANCE_FEEDBACK, com.mapbox.androidauto.screenmanager.MapboxScreen.ARRIVAL}) @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) public static @interface MapboxScreen.Key {
671672
}
672673

673674
public final class MapboxScreenEvent {
@@ -766,6 +767,12 @@ package com.mapbox.androidauto.screenmanager.factories {
766767
method public androidx.car.app.Screen create(androidx.car.app.CarContext carContext);
767768
}
768769

770+
public final class GeoDeeplinkPlacesFeedbackScreenFactory extends com.mapbox.androidauto.feedback.core.CarFeedbackScreenFactory {
771+
ctor public GeoDeeplinkPlacesFeedbackScreenFactory(com.mapbox.androidauto.MapboxCarContext mapboxCarContext);
772+
method public com.mapbox.androidauto.feedback.ui.CarFeedbackPoll getCarFeedbackPoll(androidx.car.app.CarContext carContext);
773+
method public String getSourceName();
774+
}
775+
769776
public final class NeedsLocationPermissionScreenFactory implements com.mapbox.androidauto.screenmanager.MapboxScreenFactory {
770777
ctor public NeedsLocationPermissionScreenFactory();
771778
method public androidx.car.app.Screen create(androidx.car.app.CarContext carContext);

libnavui-androidauto/src/main/java/com/mapbox/androidauto/screenmanager/MapboxScreen.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ object MapboxScreen {
6060
*/
6161
const val GEO_DEEPLINK = "MAPBOX_GEO_DEEPLINK"
6262

63+
/**
64+
* Gives the user an ability to search for a destination with their voice.
65+
*/
66+
const val GEO_DEEPLINK_FEEDBACK = "MAPBOX_GEO_DEEPLINK_FEEDBACK"
67+
6368
/**
6469
* Gives the user an ability to select a navigation route.
6570
*/
@@ -98,6 +103,7 @@ object MapboxScreen {
98103
FAVORITES,
99104
FAVORITES_FEEDBACK,
100105
GEO_DEEPLINK,
106+
GEO_DEEPLINK_FEEDBACK,
101107
ROUTE_PREVIEW,
102108
ROUTE_PREVIEW_FEEDBACK,
103109
ACTIVE_GUIDANCE,

libnavui-androidauto/src/main/java/com/mapbox/androidauto/screenmanager/MapboxScreenGraph.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.mapbox.androidauto.screenmanager.MapboxScreen.FAVORITES_FEEDBACK
1111
import com.mapbox.androidauto.screenmanager.MapboxScreen.FREE_DRIVE
1212
import com.mapbox.androidauto.screenmanager.MapboxScreen.FREE_DRIVE_FEEDBACK
1313
import com.mapbox.androidauto.screenmanager.MapboxScreen.GEO_DEEPLINK
14+
import com.mapbox.androidauto.screenmanager.MapboxScreen.GEO_DEEPLINK_FEEDBACK
1415
import com.mapbox.androidauto.screenmanager.MapboxScreen.NEEDS_LOCATION_PERMISSION
1516
import com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW
1617
import com.mapbox.androidauto.screenmanager.MapboxScreen.ROUTE_PREVIEW_FEEDBACK
@@ -25,6 +26,7 @@ import com.mapbox.androidauto.screenmanager.factories.FavoritesScreenFactory
2526
import com.mapbox.androidauto.screenmanager.factories.FreeDriveFeedbackScreenFactory
2627
import com.mapbox.androidauto.screenmanager.factories.FreeDriveScreenFactory
2728
import com.mapbox.androidauto.screenmanager.factories.GeoDeeplinkPlacesCarScreenFactory
29+
import com.mapbox.androidauto.screenmanager.factories.GeoDeeplinkPlacesFeedbackScreenFactory
2830
import com.mapbox.androidauto.screenmanager.factories.NeedsLocationPermissionScreenFactory
2931
import com.mapbox.androidauto.screenmanager.factories.RoutePreviewFeedbackScreenFactory
3032
import com.mapbox.androidauto.screenmanager.factories.RoutePreviewScreenFactory
@@ -58,6 +60,8 @@ fun MapboxCarContext.prepareScreens() = apply {
5860
to FavoritesFeedbackScreenFactory(mapboxCarContext),
5961
GEO_DEEPLINK
6062
to GeoDeeplinkPlacesCarScreenFactory(mapboxCarContext),
63+
GEO_DEEPLINK_FEEDBACK
64+
to GeoDeeplinkPlacesFeedbackScreenFactory(mapboxCarContext),
6165
ROUTE_PREVIEW
6266
to RoutePreviewScreenFactory(mapboxCarContext),
6367
ROUTE_PREVIEW_FEEDBACK

libnavui-androidauto/src/main/java/com/mapbox/androidauto/screenmanager/MapboxScreenManager.kt

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package com.mapbox.androidauto.screenmanager
22

33
import androidx.annotation.UiThread
44
import androidx.annotation.VisibleForTesting
5+
import androidx.car.app.CarContext
56
import androidx.car.app.Screen
67
import androidx.car.app.ScreenManager
78
import androidx.car.app.Session
89
import androidx.car.app.model.Template
910
import androidx.lifecycle.DefaultLifecycleObserver
1011
import androidx.lifecycle.LifecycleOwner
1112
import androidx.lifecycle.lifecycleScope
13+
import com.mapbox.androidauto.MapboxCarContext
1214
import com.mapbox.androidauto.internal.context.MapboxCarContextOwner
1315
import com.mapbox.navigation.utils.internal.logI
1416
import kotlinx.coroutines.channels.BufferOverflow
@@ -21,8 +23,48 @@ import java.util.ArrayDeque
2123
import java.util.Deque
2224

2325
/**
24-
* The Mapbox Navigation Android Auto SDK is prepared with a default experience. This object allows
25-
* you to customize the experience to meet your needs.
26+
* [MapboxScreenManager] allows you to prepare an experience that includes many screens with a
27+
* single function. Use the [MapboxCarContext.prepareScreens] to get started.
28+
*
29+
* ### How it works
30+
* Using [String] to [MapboxScreenFactory] pairing, the [MapboxScreenManager] will create a screen
31+
* based on a string provided. You can customize screens by setting the key value pair.
32+
*
33+
* [MapboxScreenManager] can be observed and controlled by the car or app. Observe the screen
34+
* changes with [MapboxScreenManager.screenEvent], change the screen with operations like
35+
* [MapboxScreenManager.replaceTop]. See the [MapboxScreenOperation] for all of the available
36+
* operations, each operation is applied through [MapboxScreenManager] functions.
37+
*
38+
* ### Set up
39+
* The [MapboxScreenManager] is provided to you through the [MapboxCarContext]. It is important
40+
* to keep the screen manager lifecycle close to [CarContext] to avoid memory leaks.
41+
* [MapboxScreenManager] does not work without the [ScreenManager] which is also bound to the
42+
* [CarContext].
43+
*
44+
* Example
45+
* ```
46+
* class MySession : Session() {
47+
* private val mapboxCarContext = MapboxCarContext(lifecycle, MapboxCarMap())
48+
* .prepareScreens()
49+
* --snip--
50+
* }
51+
* ```
52+
*
53+
* ### Customization
54+
*
55+
* At any point, you can change the mapping of the [MapboxScreenManager] with setters. The
56+
* [MapboxScreenFactory] instances are expected to have a lifecycle as long as the [Session], so
57+
* an instance of [MapboxScreenManager] is required. You can access this class through the
58+
*
59+
* [MapboxScreenFactory.create]
60+
* Example
61+
* ```
62+
* mapboxCarContext.screenManager["MY_SCREEN"] = MyScreenFactory()
63+
*
64+
* // When your app is showing on the Android Auto head unit, the MyScreenFactory will be shown
65+
* // on the top of the back stack.
66+
* MapboxScreenManager.replaceTop("MY_SCREEN")
67+
* ```
2668
*/
2769
class MapboxScreenManager internal constructor(
2870
private val carContextOwner: MapboxCarContextOwner

libnavui-androidauto/src/main/java/com/mapbox/androidauto/screenmanager/factories/GeoDeeplinkPlacesCarScreenFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GeoDeeplinkPlacesCarScreenFactory(
2323
return PlacesListOnMapScreen(
2424
SearchCarContext(mapboxCarContext),
2525
placesProvider,
26-
listOf(CarFeedbackAction(MapboxScreen.FAVORITES_FEEDBACK))
26+
listOf(CarFeedbackAction(MapboxScreen.GEO_DEEPLINK_FEEDBACK))
2727
)
2828
}
2929
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.mapbox.androidauto.screenmanager.factories
2+
3+
import androidx.car.app.CarContext
4+
import com.mapbox.androidauto.MapboxCarContext
5+
import com.mapbox.androidauto.feedback.core.CarFeedbackScreenFactory
6+
import com.mapbox.androidauto.feedback.ui.CarFeedbackPoll
7+
import com.mapbox.androidauto.screenmanager.MapboxScreen
8+
9+
/**
10+
* Default screen for [MapboxScreen.GEO_DEEPLINK_FEEDBACK].
11+
*/
12+
class GeoDeeplinkPlacesFeedbackScreenFactory(
13+
private val mapboxCarContext: MapboxCarContext
14+
) : CarFeedbackScreenFactory(mapboxCarContext) {
15+
override fun getSourceName(): String = MapboxScreen.GEO_DEEPLINK
16+
17+
override fun getCarFeedbackPoll(carContext: CarContext): CarFeedbackPoll {
18+
return mapboxCarContext.options.feedbackPollProvider
19+
.getSearchFeedbackPoll(carContext)
20+
}
21+
}

0 commit comments

Comments
 (0)