OverlayViewProvider
Interface for injecting custom overlay views on top of the MSDK MapView in the Android Auto surface.
The SDK's SurfaceCallback renders the MapView inside a FrameLayout. This interface allows clients to add app-specific UI elements on top of the map (speed limit display, ADAS info, compass, custom speed view, etc.).
Lifecycle
createOverlayView — called once during MapView creation. Return your View or null.
getLayoutParams — called once to position the overlay in the FrameLayout.
onScreenStateChanged — called when the AA screen state changes (NAVIGATION, MAP_VIEW, etc.). Use this to show/hide the overlay based on context.
onVisibleAreaChanged — called when the visible (unobscured) area changes. Use this to reposition the overlay so it doesn't get hidden behind template chrome.
onGuidanceStateChanged — called on each guidance state update during NAVIGATION. Use this to update overlay content (speed limit value, alert state, etc.).
Usage
class SpeedLimitOverlayProvider : OverlayViewProvider {
private var overlayView: SpeedLimitView? = null
override fun createOverlayView(context: Context): View {
return SpeedLimitView(context).also { overlayView = it }
}
override fun getLayoutParams(context: Context): FrameLayout.LayoutParams {
val size = (60 * context.resources.displayMetrics.density).toInt()
return FrameLayout.LayoutParams(size, size).apply {
gravity = android.view.Gravity.BOTTOM or android.view.Gravity.START
marginStart = (16 * context.resources.displayMetrics.density).toInt()
bottomMargin = (16 * context.resources.displayMetrics.density).toInt()
}
}
override fun onGuidanceStateChanged(guidanceState: AAGuidanceState) {
overlayView?.update(guidanceState.currentSpeedLimit)
}
}See also
Functions
Creates the overlay View to be added on top of the MapView.
Returns the FrameLayout.LayoutParams for positioning the overlay.
Called on each guidance state update during navigation.
Called when the AA screen state changes.
Called when the visible (unobscured) area of the map surface changes.
Determines whether the overlay should be visible given the current state.