public interface CarBridge
Internal service-provider interface implemented by each platform port to render the portable
com.codename1.car template tree onto the native in-car UI (Apple CarPlay’s CPTemplate
hierarchy or Google Android Auto’s androidx.car.app templates).
Application code never touches this interface – it is obtained by the com.codename1.car
framework classes from com.codename1.ui.Display#getCarBridge() and driven through the public
com.codename1.car.CarContext / com.codename1.car.CarScreen API. The base implementation
returns null, which is why the public API degrades to a harmless no-op on the simulator and on
ports without an in-car projection (so application code needs no platform if statements).
A bridge renders a screen by pulling its template through CarScreen.createTemplate() (the
framework calls CarScreen#dispatchCreateTemplate() on its behalf) and is responsible for
invoking the relevant com.codename1.car.CarActionListener when the user activates a row,
grid item or action – the bridge identifies the activated element by the indices it assigned
while rendering.
Methods
public abstract void pushScreen(CarScreen screen) | Pushes a screen onto the in-car back stack and renders its template. |
public abstract void popScreen() | Pops the top screen off the in-car back stack, returning to the previous screen. |
public abstract void invalidate(CarScreen screen) | Re-pulls and re-renders the template for the supplied screen (call after mutating the model behind a screen, mirroring androidx.car.app.Screen#invalidate()). |
public abstract void finish() | Tears down the in-car experience, dismissing the app from the head unit. |
public abstract boolean isConnected() | Returns true while a head unit (CarPlay / Android Auto) is currently connected and the projected UI is live. |
public abstract void showToast(String message, int durationSeconds) | Shows a short transient message on the head unit (CarPlay banner / Android Auto toast). |
public abstract int getListRowLimit() | Returns the maximum number of rows the head unit will display in a single list, or 0 when the limit is unknown. |
public abstract int getGridItemLimit() | Returns the maximum number of items the head unit will display in a single grid, or 0 when the limit is unknown. |
Method details
pushScreen
public abstract void pushScreen(CarScreen screen)Parameters
screenCarScreen- the screen to push and render
popScreen
public abstract void popScreen()invalidate
public abstract void invalidate(CarScreen screen)androidx.car.app.Screen#invalidate()). No effect if the screen
is not currently on the stack.Parameters
screenCarScreen- the screen whose template should be rebuilt
finish
public abstract void finish()isConnected
public abstract boolean isConnected()Returns
showToast
public abstract void showToast(String message, int durationSeconds)Parameters
messageString- the text to display
durationSecondsint- requested display duration in seconds; the head unit may clamp it
getListRowLimit
public abstract int getListRowLimit()0 when
the limit is unknown. Driver-distraction rules cap this aggressively (often 6-12); honour it
when populating a com.codename1.car.CarListTemplate.Returns
getGridItemLimit
public abstract int getGridItemLimit()0 when
the limit is unknown.