Android 12 Developer Preview is here! Try it out, and give us your feedback!

TemplateWrapper

public final class TemplateWrapper
extends Object

java.lang.Object
   ↳ androidx.car.app.model.TemplateWrapper


A wrapper for mapping a Template with a unique ID used for implementing task flow restrictions.

This is what is sent to the host, so that the host can determine whether the template is a new template (e.g. a step counts toward the task limit), or an existing template update (e.g. a refresh that does not count towards the task limit), by checking whether the ID have changed.

This class is for use by host implementations and not by apps.

Summary

Public methods

static TemplateWrapper copyOf(TemplateWrapper source)

Creates a copy of the given TemplateWrapper.

int getCurrentTaskStep()

Retrieves the current task step that the template is in.

String getId()

Returns the ID associated with the wrapped Template.

Template getTemplate()

Returns the wrapped Template.

List<TemplateInfo> getTemplateInfosForScreenStack()

Returns a TemplateInfo for the last returned template for each of the screens in the screen stack managed by the screen manager.

boolean isRefresh()

Returns true if the template is a refresh for the previous template.

void setCurrentTaskStep(int currentTaskStep)

Sets the current task step that the template is in.

void setId(String id)

Updates the ID associated with the wrapped Template.

void setRefresh(boolean isRefresh)

Sets whether the template is a refresh of the current template.

void setTemplate(Template template)

Updates the Template this TemplateWrapper instance wraps.

String toString()
static TemplateWrapper wrap(Template template)

Creates a TemplateWrapper instance with the given Template.

static TemplateWrapper wrap(Template template, String id)

Creates a TemplateWrapper instance with the given Template and ID.

Inherited methods

Public methods

copyOf

public static TemplateWrapper copyOf (TemplateWrapper source)

Creates a copy of the given TemplateWrapper.

Parameters
source TemplateWrapper

Returns
TemplateWrapper

getCurrentTaskStep

public int getCurrentTaskStep ()

Retrieves the current task step that the template is in.

Returns
int

getId

public String getId ()

Returns the ID associated with the wrapped Template.

Returns
String

getTemplate

public Template getTemplate ()

Returns the wrapped Template.

Returns
Template

getTemplateInfosForScreenStack

public List<TemplateInfo> getTemplateInfosForScreenStack ()

Returns a TemplateInfo for the last returned template for each of the screens in the screen stack managed by the screen manager.

The return values are in order, where position 0 is the top of the stack, and position n is the bottom of the stack given n screens on the stack.

Returns
List<TemplateInfo>

isRefresh

public boolean isRefresh ()

Returns true if the template is a refresh for the previous template.

Returns
boolean

setCurrentTaskStep

public void setCurrentTaskStep (int currentTaskStep)

Sets the current task step that the template is in.

Parameters
currentTaskStep int

setId

public void setId (String id)

Updates the ID associated with the wrapped Template.

Parameters
id String

setRefresh

public void setRefresh (boolean isRefresh)

Sets whether the template is a refresh of the current template.

Parameters
isRefresh boolean

setTemplate

public void setTemplate (Template template)

Updates the Template this TemplateWrapper instance wraps.

Parameters
template Template

toString

public String toString ()

Returns
String

wrap

public static TemplateWrapper wrap (Template template)

Creates a TemplateWrapper instance with the given Template.

The host will treat the Template as a new task step, unless it determines through its internal logic that the Template is a refresh of the existing view, in which case the task step will remain the same.

Parameters
template Template

Returns
TemplateWrapper

wrap

public static TemplateWrapper wrap (Template template, 
                String id)

Creates a TemplateWrapper instance with the given Template and ID.

The ID is primarily used to inform the host that the given Template shares the same ID as a previously sent Template, even though their contents differ. In such cases, the host will reset the task step to where the previous Template was.

For example, the client sends template A (task step 1), then move forwards a screen and sends template B (task step 2). Now the client pops the screen and sends template C. By assigning the ID of template A to template C, the client library informs the host that it is a back operation and the task step should be set to 1 again.

Parameters
template Template

id String

Returns
TemplateWrapper