# TemplateWrapper

# TemplateWrapper

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/model/TemplateWrapper.java+class:androidx.car.app.model.TemplateWrapper)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper "View this page in Java")

<br />

```
@CarProtocol
class TemplateWrapper
```

<br />

*** ** * ** ***

A wrapper for mapping a[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/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 functions                                                                                                                                             |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)                                                                                                                                                                                       | [copyOf](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#copyOf(androidx.car.app.model.TemplateWrapper))`(source: `[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)`)` Creates a copy of the given[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper).                                                                                                                                                                                         |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                                                                  | [getCurrentTaskStep](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#getCurrentTaskStep())`()` Retrieves the current task step that the template is in.                                                                                                                                                                                                                                                                                                                                                                                                     |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                                                                                            | [getId](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#getId())`()` Returns the ID associated with the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).                                                                                                                                                                                                                                                                                                                                                  |
| [Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)                                                                                                                                                                                                                   | [getTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#getTemplate())`()` Returns the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).                                                                                                                                                                                                                                                                                                                                                             |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[TemplateInfo](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateInfo)`!>` | [getTemplateInfosForScreenStack](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#getTemplateInfosForScreenStack())`()` Returns a[TemplateInfo](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateInfo)for the last returned template for each of the screens in the screen stack managed by the screen manager.                                                                                                                                                                                                                 |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                                                                                                                          | [isRefresh](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#isRefresh())`()` Returns`true`if the template is a refresh for the previous template.                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                | [setCurrentTaskStep](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#setCurrentTaskStep(int))`(currentTaskStep: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Sets the current task step that the template is in.                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                | [setId](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#setId(java.lang.String))`(id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Updates the ID associated with the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                | [setRefresh](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#setRefresh(boolean))`(isRefresh: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether the template is a refresh of the current template.                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                | [setTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#setTemplate(androidx.car.app.model.Template))`(template: `[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)`)` Updates the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)this[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance wraps.                                                                                                      |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                                                                                            | [toString](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#toString())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `java-static `[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)                                                                                                                                                                                       | [wrap](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#wrap(androidx.car.app.model.Template))`(template: `[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)`)` Creates a[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance with the given[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).                                                                                                                 |
| `java-static `[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)                                                                                                                                                                                       | [wrap](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper#wrap(androidx.car.app.model.Template,java.lang.String))`(template: `[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)`, id: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Creates a[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance with the given[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)and ID. |

## Public functions

### copyOf

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun copyOf(source: TemplateWrapper): TemplateWrapper
```

Creates a copy of the given[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper).  

### getCurrentTaskStep

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getCurrentTaskStep(): Int
```

Retrieves the current task step that the template is in.  

### getId

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getId(): String
```

Returns the ID associated with the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).  

### getTemplate

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getTemplate(): Template
```

Returns the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).  

### getTemplateInfosForScreenStack

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun getTemplateInfosForScreenStack(): (Mutable)List<TemplateInfo!>
```

Returns a[TemplateInfo](https://developer.android.com/reference/kotlin/androidx/car/app/model/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.  

### isRefresh

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun isRefresh(): Boolean
```

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

### setCurrentTaskStep

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun setCurrentTaskStep(currentTaskStep: Int): Unit
```

Sets the current task step that the template is in.  

### setId

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun setId(id: String): Unit
```

Updates the ID associated with the wrapped[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).  

### setRefresh

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun setRefresh(isRefresh: Boolean): Unit
```

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

### setTemplate

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun setTemplate(template: Template): Unit
```

Updates the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)this[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance wraps.  

### toString

```
fun toString(): String
```  

### wrap

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun wrap(template: Template): TemplateWrapper
```

Creates a[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance with the given[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template).

The host will treat the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)as a new task step, unless it determines through its internal logic that the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)is a refresh of the existing view, in which case the task step will remain the same.  

### wrap

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
java-static fun wrap(template: Template, id: String): TemplateWrapper
```

Creates a[TemplateWrapper](https://developer.android.com/reference/kotlin/androidx/car/app/model/TemplateWrapper)instance with the given[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)and ID.

The ID is primarily used to inform the host that the given[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)shares the same ID as a previously sent[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template), even though their contents differ. In such cases, the host will reset the task step to where the previous[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/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.