public interface CarSurfaceCallback

The drawing surface callback for a CarNavigationTemplate. Navigation is the one in-car category that grants a pixel surface (for the moving map): on Android Auto an androidx.car.app.SurfaceCallback backed Surface, on CarPlay the CPMapTemplate’s window. Codename One adapts that native surface to a com.codename1.ui.Graphics so the map can be drawn with the normal CN1 drawing primitives.

Only navigation apps holding the platform navigation entitlement (ios.carplay.navigation build hint on iOS; the androidx.car.app.category.NAVIGATION intent filter the builder injects on Android) receive these callbacks.

Methods

public abstract void surfaceAvailable(int width, int height)Invoked when the map surface becomes available or is resized.
public abstract void renderSurface(Graphics g, int width, int height)Invoked when the surface should be (re)drawn.
public abstract void visibleAreaChanged(int x, int y, int width, int height)Invoked when the visible (non-occluded) region of the surface changes, e.g. when the head unit overlays panels.
public abstract void surfaceDestroyed()Invoked when the surface is torn down (head unit disconnect, navigation ended).

Method details

surfaceAvailable

public abstract void surfaceAvailable(int width, int height)
Invoked when the map surface becomes available or is resized. Cache the dimensions; the next renderSurface(Graphics, int, int) reflects them.

Parameters

width int
the surface width in pixels
height int
the surface height in pixels

renderSurface

public abstract void renderSurface(Graphics g, int width, int height)
Invoked when the surface should be (re)drawn. Draw the map into the supplied graphics; the bridge blits the result to the native head-unit surface. Keep drawing cheap – this is the car display refresh path.

Parameters

g Graphics
graphics targeting an off-screen buffer the size of the surface
width int
the surface width in pixels
height int
the surface height in pixels

visibleAreaChanged

public abstract void visibleAreaChanged(int x, int y, int width, int height)
Invoked when the visible (non-occluded) region of the surface changes, e.g. when the head unit overlays panels. Centre critical map content (current position, next manoeuvre) within this rectangle.

Parameters

x int
left edge of the visible area, in pixels
y int
top edge of the visible area, in pixels
width int
width of the visible area, in pixels
height int
height of the visible area, in pixels

surfaceDestroyed

public abstract void surfaceDestroyed()
Invoked when the surface is torn down (head unit disconnect, navigation ended). Release any cached buffers.