Class CarScreen
java.lang.Object
com.codename1.car.CarScreen
One screen of the in-car experience -- the unit of the head-unit back stack. A screen produces a
single CarTemplate from onCreateTemplate(); the framework pulls it when the screen is pushed
or invalidated. Conceptually equivalent to androidx.car.app.Screen; on CarPlay a screen
corresponds to one pushed CPTemplate.
class AlbumsScreen extends CarScreen {
protected CarTemplate onCreateTemplate() {
CarListTemplate t = new CarListTemplate().setTitle("Albums");
for (Album a : albums) {
t.addRow(new CarRow(a.name).setImage(a.art)
.setBrowsable(true)
.setOnAction(ctx -> ctx.pushScreen(new TracksScreen(a))));
}
return t;
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidFramework entry point -- dispatches theonCreatelifecycle callback.final CarTemplateFramework entry point -- pulls the template, used by the platformCarBridge.final voidFramework entry point -- dispatches theonDestroylifecycle callback.final voidFramework entry point -- dispatches theonPauselifecycle callback.final voidFramework entry point -- dispatches theonResumelifecycle callback.final voidfinish()Pops this screen off the stack (equivalent togetContext().popScreen()when this is the top screen).final CarContextReturns the context this screen is attached to, or null if it has not been pushed yet.final voidRebuilds and re-renders this screen's template (after the model behind it changed).protected voidonCreate()Lifecycle hook invoked once, when the screen is first pushed onto the stack, before its template is built.protected abstract CarTemplateBuilds the template to display for this screen.protected voidLifecycle hook invoked when the screen is popped and discarded.protected voidonPause()Lifecycle hook invoked when the screen is covered by a pushed screen.protected voidonResume()Lifecycle hook invoked when the screen becomes the visible top of stack.
-
Constructor Details
-
CarScreen
public CarScreen()
-
-
Method Details
-
onCreateTemplate
Builds the template to display for this screen. Called by the framework when the screen is pushed and again after
invalidate(). Must return a non-nullCarTemplate.Returns
the template to render on the head unit
-
onCreate
protected void onCreate()Lifecycle hook invoked once, when the screen is first pushed onto the stack, before its template is built. Default is a no-op. -
onResume
protected void onResume()Lifecycle hook invoked when the screen becomes the visible top of stack. Default is a no-op. -
onPause
protected void onPause()Lifecycle hook invoked when the screen is covered by a pushed screen. Default is a no-op. -
onDestroy
protected void onDestroy()Lifecycle hook invoked when the screen is popped and discarded. Default is a no-op. -
getContext
Returns the context this screen is attached to, or null if it has not been pushed yet.
Returns
the car context, or null
-
invalidate
public final void invalidate()Rebuilds and re-renders this screen's template (after the model behind it changed). No-op when the screen is not currently attached or no head unit is connected. -
finish
public final void finish()Pops this screen off the stack (equivalent togetContext().popScreen()when this is the top screen). No-op when not attached. -
dispatchCreateTemplate
Framework entry point -- pulls the template, used by the platformCarBridge. -
dispatchCreate
public final void dispatchCreate()Framework entry point -- dispatches theonCreatelifecycle callback. -
dispatchResume
public final void dispatchResume()Framework entry point -- dispatches theonResumelifecycle callback. -
dispatchPause
public final void dispatchPause()Framework entry point -- dispatches theonPauselifecycle callback. -
dispatchDestroy
public final void dispatchDestroy()Framework entry point -- dispatches theonDestroylifecycle callback.
-