Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Callback

*** ** * ** ***

```
abstract class Callback
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.view.WindowInsetsAnimation.Callback](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#) |

Interface that allows the application to listen to animation events for windows that cause insets.

Note: Applications that want to observe the lifecycle of window insets animations but do not need to synchronize view layouts or draw frames with the animation on every frame should prefer `https://developer.android.com/reference/kotlin/android/view/ViewTreeObserver.WindowInsetsAnimationListener` to allow the system to optimize the animation e.g. by moving it to a different thread.

## Summary

| Constants ||
|---|---|
| static [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_CONTINUE_ON_SUBTREE:kotlin.Int` Return value for `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`: Dispatching of animation events should continue in the view hierarchy. |
| static [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` Return value for `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`: Dispatching of animation events should stop at this level in the view hierarchy, and no animation events should be dispatch to the subtree of the view hierarchy. |

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#Callback(kotlin.Int)(dispatchMode: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Creates a new `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation` callback with the given `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`. |

| Public methods ||
|---|---|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()()` Retrieves the dispatch mode of this listener. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onEnd(android.view.WindowInsetsAnimation)(animation: https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation)` Called when an insets animation has ended. |
| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onPrepare(android.view.WindowInsetsAnimation)(animation: https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation)` Called when an insets animation is about to start and before the views have been laid out in the end state of the animation. |
| abstract [WindowInsets](https://developer.android.com/reference/kotlin/android/view/WindowInsets) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onProgress(android.view.WindowInsets,%20kotlin.collections.MutableList)(insets: https://developer.android.com/reference/kotlin/android/view/WindowInsets, runningAnimations: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html<https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation!>)` Called when the insets change as part of running an animation. |
| open [WindowInsetsAnimation.Bounds](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Bounds) | `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onStart(android.view.WindowInsetsAnimation,%20android.view.WindowInsetsAnimation.Bounds)(animation: https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation, bounds: https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Bounds)` Called when an insets animation gets started. |

## Constants

### DISPATCH_MODE_CONTINUE_ON_SUBTREE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
static val DISPATCH_MODE_CONTINUE_ON_SUBTREE: Int
```

Return value for `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`: Dispatching of animation events should continue in the view hierarchy.

    Value: 1

### DISPATCH_MODE_STOP

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
static val DISPATCH_MODE_STOP: Int
```

Return value for `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`: Dispatching of animation events should stop at this level in the view hierarchy, and no animation events should be dispatch to the subtree of the view hierarchy.

    Value: 0

## Public constructors

### Callback

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Callback(dispatchMode: Int)
```

Creates a new `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation` callback with the given `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`.

| Parameters ||
|---|---|
| `dispatchMode` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): The dispatch mode for this callback. See `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()`. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_CONTINUE_ON_SUBTREE:kotlin.Int` |

## Public methods

### getDispatchMode

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
fun getDispatchMode(): Int
```

Retrieves the dispatch mode of this listener. Dispatch of the all animation events is hierarchical: It will starts at the root of the view hierarchy and then traverse it and invoke the callback of the specific `https://developer.android.com/reference/kotlin/android/view/View` that is being traversed. The method may return either `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_CONTINUE_ON_SUBTREE:kotlin.Int` to indicate that animation events should be propagated to the subtree of the view hierarchy, or `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` to stop dispatching. In that case, all animation callbacks related to the animation passed in will be stopped from propagating to the subtree of the hierarchy.

Also note that `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` behaves the same way as returning `https://developer.android.com/reference/kotlin/android/view/WindowInsets#CONSUMED:android.view.WindowInsets` during the regular insets dispatch in `https://developer.android.com/reference/kotlin/android/view/View#onApplyWindowInsets(android.view.WindowInsets)`.

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | Either `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_CONTINUE_ON_SUBTREE:kotlin.Int` to indicate that dispatching of animation events will continue to the subtree of the view hierarchy, or `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` to indicate that animation events will stop dispatching. Value is one of the following: - `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int` - `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_CONTINUE_ON_SUBTREE:kotlin.Int` |

### onEnd

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onEnd(animation: WindowInsetsAnimation): Unit
```

Called when an insets animation has ended.

| Parameters ||
|---|---|
| `animation` | [WindowInsetsAnimation](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation): The animation that has ended. This will be the same instance as passed into `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onStart(android.view.WindowInsetsAnimation,%20android.view.WindowInsetsAnimation.Bounds)` This value cannot be `null`. |

### onPrepare

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onPrepare(animation: WindowInsetsAnimation): Unit
```

Called when an insets animation is about to start and before the views have been laid out in the end state of the animation. The ordering of events during an insets animation is the following:

- Application calls `https://developer.android.com/reference/kotlin/android/view/WindowInsetsController#hide(kotlin.Int)`, `https://developer.android.com/reference/kotlin/android/view/WindowInsetsController#show(kotlin.Int)`, `https://developer.android.com/reference/kotlin/android/view/WindowInsetsController#controlWindowInsetsAnimation(kotlin.Int,%20kotlin.Long,%20android.view.animation.Interpolator,%20android.os.CancellationSignal,%20android.view.WindowInsetsAnimationControlListener)`
- onPrepare is called on the view hierarchy listeners
- `https://developer.android.com/reference/kotlin/android/view/View#onApplyWindowInsets(android.view.WindowInsets)` will be called with the end state of the animation
- View hierarchy gets laid out according to the changes the application has requested due to the new insets being dispatched
- `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onStart(android.view.WindowInsetsAnimation,%20android.view.WindowInsetsAnimation.Bounds)` is called *before* the view hierarchy gets drawn in the new laid out state
- `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onProgress(android.view.WindowInsets,%20kotlin.collections.MutableList)` is called immediately after with the animation start state
- The frame gets drawn.

This ordering allows the application to inspect the end state after the animation has finished, and then revert to the starting state of the animation in the first `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onProgress(android.view.WindowInsets,%20kotlin.collections.MutableList)` callback by using post-layout view properties like `https://developer.android.com/reference/kotlin/android/view/View#setX(kotlin.Float)` and related methods.

Note that the animation might be cancelled before `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onStart(android.view.WindowInsetsAnimation,%20android.view.WindowInsetsAnimation.Bounds)` is dispatched. On `https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#S:kotlin.Int` and later, `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onEnd(android.view.WindowInsetsAnimation)` is immediately dispatched without an `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onStart(android.view.WindowInsetsAnimation,%20android.view.WindowInsetsAnimation.Bounds)` in that case. On `https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#R:kotlin.Int`, no callbacks are dispatched after `onPrepare` for such an animation.

Note: If the animation is application controlled by using `https://developer.android.com/reference/kotlin/android/view/WindowInsetsController#controlWindowInsetsAnimation(kotlin.Int,%20kotlin.Long,%20android.view.animation.Interpolator,%20android.os.CancellationSignal,%20android.view.WindowInsetsAnimationControlListener)`, the end state of the animation is undefined as the application may decide on the end state only by passing in `shown` parameter when calling `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimationController#finish(kotlin.Boolean)`. In this situation, the system will dispatch the insets in the opposite visibility state before the animation starts. Example: When controlling the input method with `https://developer.android.com/reference/kotlin/android/view/WindowInsetsController#controlWindowInsetsAnimation(kotlin.Int,%20kotlin.Long,%20android.view.animation.Interpolator,%20android.os.CancellationSignal,%20android.view.WindowInsetsAnimationControlListener)` and the input method is currently showing, `https://developer.android.com/reference/kotlin/android/view/View#onApplyWindowInsets(android.view.WindowInsets)` will receive a `https://developer.android.com/reference/kotlin/android/view/WindowInsets` instance for which `https://developer.android.com/reference/kotlin/android/view/WindowInsets#isVisible(kotlin.Int)` will return `false` for `https://developer.android.com/reference/kotlin/android/view/WindowInsets.Type#ime()`.

| Parameters ||
|---|---|
| `animation` | [WindowInsetsAnimation](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation): The animation that is about to start. This value cannot be `null`. |

### onProgress

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
abstract fun onProgress(
    insets: WindowInsets, 
    runningAnimations: MutableList<WindowInsetsAnimation!>
): WindowInsets
```

Called when the insets change as part of running an animation. Note that even if multiple animations for different types are running, there will only be one progress callback per frame. The `insets` passed as an argument represents the overall state and will include all types, regardless of whether they are animating or not.

Note that insets dispatch is hierarchical: It will start at the root of the view hierarchy, and then traverse it and invoke the callback of the specific `https://developer.android.com/reference/kotlin/android/view/View` being traversed. The method may return a modified instance by calling `https://developer.android.com/reference/kotlin/android/view/WindowInsets#inset(kotlin.Int,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int)` to indicate that a part of the insets have been used to offset or clip its children, and the children shouldn't worry about that part anymore. Furthermore, if `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()` returns `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int`, children of this view will not receive the callback anymore.

| Parameters ||
|---|---|
| `insets` | [WindowInsets](https://developer.android.com/reference/kotlin/android/view/WindowInsets): The current insets. This value cannot be `null`. |
| `runningAnimations` | [MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\<[WindowInsetsAnimation](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation)!\>: The currently running animations. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/view/WindowInsets` | The insets to dispatch to the subtree of the hierarchy. This value cannot be `null`. |

### onStart

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun onStart(
    animation: WindowInsetsAnimation, 
    bounds: WindowInsetsAnimation.Bounds
): WindowInsetsAnimation.Bounds
```

Called when an insets animation gets started.

Note that, like `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#onProgress(android.view.WindowInsets,%20kotlin.collections.MutableList)`, dispatch of the animation start event is hierarchical: It will starts at the root of the view hierarchy and then traverse it and invoke the callback of the specific `https://developer.android.com/reference/kotlin/android/view/View` that is being traversed. The method may return a modified instance of the bounds by calling `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Bounds#inset(android.graphics.Insets)` to indicate that a part of the insets have been used to offset or clip its children, and the children shouldn't worry about that part anymore. Furthermore, if `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#getDispatchMode()` returns `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Callback#DISPATCH_MODE_STOP:kotlin.Int`, children of this view will not receive the callback anymore.

| Parameters ||
|---|---|
| `animation` | [WindowInsetsAnimation](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation): The animation that is about to start. This value cannot be `null`. |
| `bounds` | [WindowInsetsAnimation.Bounds](https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Bounds): The bounds in which animation happens. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/view/WindowInsetsAnimation.Bounds` | The animation representing the part of the insets that should be dispatched to the subtree of the hierarchy. This value cannot be `null`. |