Class CarContext
The live handle to a connected head unit. Created by the framework when a car connects and handed
to CarApplication#onCreateRootScreen(CarContext) and to every CarActionListener. Use it to
drive the head-unit back stack (pushScreen(CarScreen), popScreen()), surface transient
messages (showToast(String)) and query driver-distraction limits.
The context delegates rendering to a platform com.codename1.car.spi.CarBridge. On the simulator
and on ports without in-car projection the bridge is absent, so every method here is a harmless
no-op and isConnected() returns false -- application code never needs platform ifs.
-
Method Summary
Modifier and TypeMethodDescriptionvoidfinish()Tears down the in-car experience and dismisses the app from the head unit.intReturns the maximum items the head unit will show in aCarGridTemplate, or 0 if unknown.intReturns the maximum rows the head unit will show in aCarListTemplate, or 0 if unknown.Returns the screen currently at the top of the in-car back stack, or null if none.booleanReturns true while a head unit is connected and rendering.voidPops the top screen, returning to the one beneath it.voidpushScreen(CarScreen screen) Pushes a screen onto the head-unit back stack and renders it.voidShows a short transient message on the head unit.voidShows a transient message on the head unit for a requested duration.
-
Method Details
-
isConnected
public boolean isConnected()Returns true while a head unit is connected and rendering. -
getTopScreen
Returns the screen currently at the top of the in-car back stack, or null if none. -
pushScreen
Pushes a screen onto the head-unit back stack and renders it. The previous screen is paused.
Parameters
screen: the screen to show
-
popScreen
public void popScreen()Pops the top screen, returning to the one beneath it. No effect when only the root remains. -
finish
public void finish()Tears down the in-car experience and dismisses the app from the head unit. -
showToast
Shows a short transient message on the head unit.
Parameters
message: the text to display
-
showToast
Shows a transient message on the head unit for a requested duration.
Parameters
-
message: the text to display -
durationSeconds: requested duration in seconds (the head unit may clamp it)
-
-
getListRowLimit
public int getListRowLimit()Returns the maximum rows the head unit will show in a
CarListTemplate, or 0 if unknown. Honour this when populating lists -- rows beyond the limit are dropped by the platform.Returns
the row limit, or 0 if unknown
-
getGridItemLimit
public int getGridItemLimit()Returns the maximum items the head unit will show in a
CarGridTemplate, or 0 if unknown.Returns
the grid item limit, or 0 if unknown
-