# 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)

*** ** * ** ***


```
@CarProtocol
public final class TemplateWrapper
```

<br />

*** ** * ** ***

A wrapper for mapping a `https://developer.android.com/reference/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 methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#copyOf(androidx.car.app.model.TemplateWrapper)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper source)` Creates a copy of the given `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper`. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#getCurrentTaskStep()()` Retrieves the current task step that the template is in. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#getId()()` Returns the ID associated with the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Template` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#getTemplate()()` Returns the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/car/app/model/TemplateInfo>` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#getTemplateInfosForScreenStack()()` Returns a `https://developer.android.com/reference/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://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#isRefresh()()` Returns `true` if the template is a refresh for the previous template. |
| `void` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#setCurrentTaskStep(int)(int currentTaskStep)` Sets the current task step that the template is in. |
| `void` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#setId(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id)` Updates the ID associated with the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`. |
| `void` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#setRefresh(boolean)(boolean isRefresh)` Sets whether the template is a refresh of the current template. |
| `void` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#setTemplate(androidx.car.app.model.Template)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Template template)` Updates the `https://developer.android.com/reference/androidx/car/app/model/Template` this `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance wraps. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#toString()()` |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#wrap(androidx.car.app.model.Template)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Template template)` Creates a `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance with the given `https://developer.android.com/reference/androidx/car/app/model/Template`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` | `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper#wrap(androidx.car.app.model.Template,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Template template, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id)` Creates a `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance with the given `https://developer.android.com/reference/androidx/car/app/model/Template` and ID. |

## Public methods

### copyOf

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

```
public static @NonNull TemplateWrapper copyOf(@NonNull TemplateWrapper source)
```

Creates a copy of the given `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper`.

### getCurrentTaskStep

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

```
public int getCurrentTaskStep()
```

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)

```
public @NonNull String getId()
```

Returns the ID associated with the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`.

### getTemplate

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

```
public @NonNull Template getTemplate()
```

Returns the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`.

### getTemplateInfosForScreenStack

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

```
public @NonNull List<TemplateInfo> getTemplateInfosForScreenStack()
```

Returns a `https://developer.android.com/reference/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)

```
public boolean isRefresh()
```

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)

```
public void setCurrentTaskStep(int currentTaskStep)
```

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)

```
public void setId(@NonNull String id)
```

Updates the ID associated with the wrapped `https://developer.android.com/reference/androidx/car/app/model/Template`.

### setRefresh

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

```
public void setRefresh(boolean isRefresh)
```

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)

```
public void setTemplate(@NonNull Template template)
```

Updates the `https://developer.android.com/reference/androidx/car/app/model/Template` this `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance wraps.

### toString

```
public @NonNull String toString()
```

### wrap

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

```
public static @NonNull TemplateWrapper wrap(@NonNull Template template)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance with the given `https://developer.android.com/reference/androidx/car/app/model/Template`.

The host will treat the `https://developer.android.com/reference/androidx/car/app/model/Template` as a new task step, unless it determines through its internal logic that the `https://developer.android.com/reference/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)

```
public static @NonNull TemplateWrapper wrap(@NonNull Template template, @NonNull String id)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/TemplateWrapper` instance with the given `https://developer.android.com/reference/androidx/car/app/model/Template` and ID.

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