Skip to content

Commit 7ea29d8

Browse files
committed
Allow for downstream upgrades
1 parent c015c41 commit 7ea29d8

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

extension-androidauto/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone.
88
* Add `MapboxCarMapSessionInstaller` and `MapboxCarMapScreenInstaller` for simpler setup. ([#1603](https://github.com/mapbox/mapbox-maps-android/pull/1603))
99
* Add `Session.mapboxMapInstaller` and `Screen.mapboxMapInstaller` extension functions to create the installers. ([#1603](https://github.com/mapbox/mapbox-maps-android/pull/1603))
1010
* Change `MapboxCarMapGestureHandler` to an java interface so default methods can be added without breaking java backwards compatibility. ([#1670](https://github.com/mapbox/mapbox-maps-android/pull/1670))
11+
* Add support for intercepting the `SurfaceCallback#onClick` with an experimental method `MapboxCarMap.setupWithCustomCallback`.
1112

1213
## Bug fixes 🐞
1314

extension-androidauto/src/main/java/com/mapbox/maps/extension/androidauto/CarMapSurfaceOwner.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.util.concurrent.CopyOnWriteArraySet
1717
* Maintains the surface state for [MapboxCarMap].
1818
*/
1919
@MapboxExperimental
20-
internal class CarMapSurfaceOwner(
20+
class CarMapSurfaceOwner(
2121
var gestureHandler: MapboxCarMapGestureHandler? = DefaultMapboxCarMapGestureHandler()
2222
) : SurfaceCallback {
2323

@@ -35,14 +35,14 @@ internal class CarMapSurfaceOwner(
3535

3636
private val carMapObservers = CopyOnWriteArraySet<MapboxCarMapObserver>()
3737

38-
fun setup(carContext: CarContext, mapInitOptions: MapInitOptions) = apply {
38+
internal fun setup(carContext: CarContext, mapInitOptions: MapInitOptions) = apply {
3939
this.carContext = carContext
4040
this.mapInitOptions = mapInitOptions
4141
}
4242

43-
fun isSetup(): Boolean = this::carContext.isInitialized && this::mapInitOptions.isInitialized
43+
internal fun isSetup(): Boolean = this::carContext.isInitialized && this::mapInitOptions.isInitialized
4444

45-
fun registerObserver(mapboxCarMapObserver: MapboxCarMapObserver) {
45+
internal fun registerObserver(mapboxCarMapObserver: MapboxCarMapObserver) {
4646
carMapObservers.add(mapboxCarMapObserver)
4747
logI(TAG, "registerObserver + 1 = ${carMapObservers.size}")
4848

@@ -55,13 +55,13 @@ internal class CarMapSurfaceOwner(
5555
}
5656
}
5757

58-
fun unregisterObserver(mapboxCarMapObserver: MapboxCarMapObserver) {
58+
internal fun unregisterObserver(mapboxCarMapObserver: MapboxCarMapObserver) {
5959
carMapObservers.remove(mapboxCarMapObserver)
6060
mapboxCarMapSurface?.let { mapboxCarMapObserver.onDetached(it) }
6161
logI(TAG, "unregisterObserver - 1 = ${carMapObservers.size}")
6262
}
6363

64-
fun clearObservers() {
64+
internal fun clearObservers() {
6565
this.mapboxCarMapSurface?.let { surface -> carMapObservers.forEach { it.onDetached(surface) } }
6666
carMapObservers.clear()
6767
}

extension-androidauto/src/main/java/com/mapbox/maps/extension/androidauto/MapboxCarMap.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.graphics.Rect
44
import androidx.car.app.AppManager
55
import androidx.car.app.CarContext
66
import androidx.car.app.Session
7+
import androidx.car.app.SurfaceCallback
78
import androidx.lifecycle.Lifecycle
89
import com.mapbox.maps.EdgeInsets
910
import com.mapbox.maps.MapInitOptions
@@ -72,12 +73,33 @@ class MapboxCarMap {
7273
mapInitOptions: MapInitOptions,
7374
) = apply {
7475
check(mapInitOptions.context is CarContext) {
75-
"You must setup the MapboxCarMap MapInitOptions with a CarContext"
76+
"You must set up the MapboxCarMap MapInitOptions with a CarContext"
7677
}
7778
carMapSurfaceOwner.setup(carContext, mapInitOptions)
7879
carContext.getCarService(AppManager::class.java).setSurfaceCallback(carMapSurfaceOwner)
7980
}
8081

82+
/**
83+
* Instead of using [setup], this function allows you to create your own [SurfaceCallback] and
84+
* forward the calls to the [CarMapSurfaceOwner]. This makes it possible for you to adopt new
85+
* api versions and continue to use the [MapboxCarMap] as designed.
86+
*
87+
* This is a temporary solution, while androidx.car.app:app:1.3.0 is rolling out
88+
* [SurfaceCallback.onClick]. If there is no use for this function in the future, it will be
89+
* removed.
90+
*/
91+
@MapboxExperimental
92+
fun setupWithCustomCallback(
93+
carContext: CarContext,
94+
mapInitOptions: MapInitOptions
95+
): CarMapSurfaceOwner {
96+
check(mapInitOptions.context is CarContext) {
97+
"You must set up the MapboxCarMap MapInitOptions with a CarContext"
98+
}
99+
carMapSurfaceOwner.setup(carContext, mapInitOptions)
100+
return carMapSurfaceOwner
101+
}
102+
81103
/**
82104
* Returns the current [MapboxCarMapSurface]. It is recommended to use [registerObserver] and
83105
* [MapboxCarMapObserver] to attach and detach your customizations.

0 commit comments

Comments
 (0)