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

  1. createOverlayView — called once during MapView creation. Return your View or null.

  2. getLayoutParams — called once to position the overlay in the FrameLayout.

  3. onScreenStateChanged — called when the AA screen state changes (NAVIGATION, MAP_VIEW, etc.). Use this to show/hide the overlay based on context.

  4. onVisibleAreaChanged — called when the visible (unobscured) area changes. Use this to reposition the overlay so it doesn't get hidden behind template chrome.

  5. 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

Link copied to clipboard
abstract fun createOverlayView(context: Context): View?

Creates the overlay View to be added on top of the MapView.

Link copied to clipboard

Returns the FrameLayout.LayoutParams for positioning the overlay.

Link copied to clipboard
open fun onGuidanceStateChanged(guidanceState: AAGuidanceState)

Called on each guidance state update during navigation.

Link copied to clipboard

Called when the AA screen state changes.

Link copied to clipboard
open fun onVisibleAreaChanged(visibleArea: Rect, context: Context)

Called when the visible (unobscured) area of the map surface changes.

Link copied to clipboard
open fun shouldShowOverlay(guidanceState: AAGuidanceState?, settingsState: AASettingsState?, screenState: AndroidAutoScreenState): Boolean

Determines whether the overlay should be visible given the current state.