# ConfirmationOverlay

Artifact: [androidx.wear:wear](https://developer.android.com/jetpack/androidx/releases/wear.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/wear/widget/ConfirmationOverlay.java+class:androidx.wear.widget.ConfirmationOverlay) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

*** ** * ** ***


```
class ConfirmationOverlay
```

<br />

*** ** * ** ***

Displays a full-screen confirmation animation with optional text and then hides it.

This is a lighter-weight version of `ConfirmationActivity` and should be preferred when constructed from an `Activity`.

Sample usage:

```kotlin
  // Defaults to SUCCESS_ANIMATION
  new ConfirmationOverlay().showOn(myActivity);

  new ConfirmationOverlay()
     .setType(ConfirmationOverlay.OPEN_ON_PHONE_ANIMATION)
     .setDuration(3000)
     .setMessage("Opening...")
     .setOnAnimationFinishedListener(new ConfirmationOverlay.OnAnimationFinishedListener() {
         @Override
         public void onAnimationFinished() {
             // Finished animating and the content view has been removed from myActivity.
         }
     }).showOn(myActivity);

  // Default du`ration is DEFAULT_ANIMATION_D`URATION_MS
  new ConfirmationOverlay()
     .setType(ConfirmationOverlay.FAILURE_ANIMATION)
     .setMessage("Failed")
     .setOnAnimationFinishedListener(new ConfirmationOverlay.OnAnimationFinishedListener() {
         @Override
         public void onAnimationFinished() {
             // Finished animating and the view has been removed from myView.getRootView().
         }
     }).showAbove(myView);
```

## Summary

| ### Nested types |
|---|
| `interface ConfirmationOverlay.OnAnimationFinishedListener` Interface for listeners to be notified when the `ConfirmationOverlay` animation has finished and its `View` has been removed. |
| `@Retention(value = RetentionPolicy.SOURCE) @IntDef(value = ) annotation ConfirmationOverlay.OverlayType` Types of animations to display in the overlay. |

| ### Constants |
|---|---|
| `const Int` | `DEFAULT_ANIMATION_DURATION_MS = 1000` Default animation duration in ms. |
| `const Int` | `FAILURE_ANIMATION = 1` `OverlayType` indicating the failure overlay should be shown. |
| `const Int` | `OPEN_ON_PHONE_ANIMATION = 2` `OverlayType` indicating the "Open on Phone" animation overlay should be displayed. |
| `const Int` | `SUCCESS_ANIMATION = 0` `OverlayType` indicating the success animation overlay should be displayed. |

| ### Public constructors |
|---|
| `ConfirmationOverlay()` |

| ### Public functions |
|---|---|
| `ConfirmationOverlay` | `setDuration(millis: Int)` Sets the duration in milliseconds which controls how long the animation will be displayed. |
| `ConfirmationOverlay` | `[setFinishedAnimationListener](https://developer.android.com/reference/kotlin/androidx/wear/widget/ConfirmationOverlay#setFinishedAnimationListener(androidx.wear.widget.ConfirmationOverlay.OnAnimationFinishedListener))( listener: ConfirmationOverlay.OnAnimationFinishedListener? )` **This function is deprecated.** Use `setOnAnimationFinishedListener` instead. <br /> |
| `ConfirmationOverlay` | `setMessage(message: CharSequence)` Sets a message which will be displayed at the same time as the animation. |
| `ConfirmationOverlay` | `[setMessage](https://developer.android.com/reference/kotlin/androidx/wear/widget/ConfirmationOverlay#setMessage(java.lang.String))(message: String)` **This function is deprecated.** Use `setMessage` instead. <br /> |
| `ConfirmationOverlay` | `setOnAnimationFinishedListener( listener: ConfirmationOverlay.OnAnimationFinishedListener? )` Sets the `OnAnimationFinishedListener` which will be invoked once the overlay is no longer visible. |
| `ConfirmationOverlay` | `setType(@ConfirmationOverlay.OverlayType type: Int)` Sets the `OverlayType` which controls which animation is displayed. |
| `Unit` | `@MainThread showAbove(view: View)` Adds the overlay as a child of `view.getRootView()`, removing it when complete. |
| `Unit` | `@MainThread showOn(activity: Activity)` Adds the overlay as a content view to the `activity`, removing it when complete. |

## Constants

### DEFAULT_ANIMATION_DURATION_MS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
const val DEFAULT_ANIMATION_DURATION_MS = 1000: Int
```

Default animation duration in ms.

### FAILURE_ANIMATION

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
const val FAILURE_ANIMATION = 1: Int
```

`OverlayType` indicating the failure overlay should be shown. The icon associated with this type, unlike the others, does not animate.

### OPEN_ON_PHONE_ANIMATION

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
const val OPEN_ON_PHONE_ANIMATION = 2: Int
```

`OverlayType` indicating the "Open on Phone" animation overlay should be displayed.

### SUCCESS_ANIMATION

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
const val SUCCESS_ANIMATION = 0: Int
```

`OverlayType` indicating the success animation overlay should be displayed.

## Public constructors

### ConfirmationOverlay

Added in 1.1.0

```
ConfirmationOverlay()
```

## Public functions

### setDuration

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun setDuration(millis: Int): ConfirmationOverlay
```

Sets the duration in milliseconds which controls how long the animation will be displayed. Default duration is `DEFAULT_ANIMATION_DURATION_MS`.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### setFinishedAnimationListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun [setFinishedAnimationListener](https://developer.android.com/reference/kotlin/androidx/wear/widget/ConfirmationOverlay#setFinishedAnimationListener(androidx.wear.widget.ConfirmationOverlay.OnAnimationFinishedListener))(
    listener: ConfirmationOverlay.OnAnimationFinishedListener?
): ConfirmationOverlay
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `setOnAnimationFinishedListener` instead.

Sets the `OnAnimationFinishedListener` which will be invoked once the overlay is no longer visible.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### setMessage

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun setMessage(message: CharSequence): ConfirmationOverlay
```

Sets a message which will be displayed at the same time as the animation.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### setMessage

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun [setMessage](https://developer.android.com/reference/kotlin/androidx/wear/widget/ConfirmationOverlay#setMessage(java.lang.String))(message: String): ConfirmationOverlay
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `setMessage` instead.

Sets a message which will be displayed at the same time as the animation.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### setOnAnimationFinishedListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun setOnAnimationFinishedListener(
    listener: ConfirmationOverlay.OnAnimationFinishedListener?
): ConfirmationOverlay
```

Sets the `OnAnimationFinishedListener` which will be invoked once the overlay is no longer visible.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### setType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
fun setType(@ConfirmationOverlay.OverlayType type: Int): ConfirmationOverlay
```

Sets the `OverlayType` which controls which animation is displayed.

| Returns |
|---|---|
| `ConfirmationOverlay` | `this` object for method chaining. |

### showAbove

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
@MainThread
fun showAbove(view: View): Unit
```

Adds the overlay as a child of `view.getRootView()`, removing it when complete. While it is shown, all touches will be intercepted to prevent accidental taps on obscured views.

### showOn

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear.md.txt#1.1.0)

```
@MainThread
fun showOn(activity: Activity): Unit
```

Adds the overlay as a content view to the `activity`, removing it when complete. While it is shown, all touches will be intercepted to prevent accidental taps on obscured views.