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

Callback

abstract class Callback
kotlin.Any
   ↳ androidx.core.view.WindowInsetsAnimationCompat.Callback

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

Summary

Constants
static Int

Return value for getDispatchMode(): Dispatching of animation events should continue in the view hierarchy.

static Int

Return value for 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
<init>(dispatchMode: Int)

Creates a new WindowInsetsAnimationCompat callback with the given dispatch mode.

Public methods
Int

Retrieves the dispatch mode of this listener.

open Unit
onEnd(@NonNull animation: WindowInsetsAnimationCompat)

Called when an insets animation has ended.

open Unit

Called when an insets animation is about to start and before the views have been re-laid out due to an animation.

abstract WindowInsetsCompat
onProgress(@NonNull insets: WindowInsetsCompat, @NonNull runningAnimations: MutableList<WindowInsetsAnimationCompat!>)

Called when the insets change as part of running an animation.

open WindowInsetsAnimationCompat.BoundsCompat

Called when an insets animation gets started.

Constants

DISPATCH_MODE_CONTINUE_ON_SUBTREE

static val DISPATCH_MODE_CONTINUE_ON_SUBTREE: Int

Return value for getDispatchMode(): Dispatching of animation events should continue in the view hierarchy.

Value: 1

DISPATCH_MODE_STOP

static val DISPATCH_MODE_STOP: Int

Return value for 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

<init>

Callback(dispatchMode: Int)

Creates a new WindowInsetsAnimationCompat callback with the given dispatch mode.

Parameters
dispatchMode Int: The dispatch mode for this callback. See getDispatchMode().

Public methods

getDispatchMode

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 View that is being traversed. The method may return either DISPATCH_MODE_CONTINUE_ON_SUBTREE to indicate that animation events should be propagated to the subtree of the view hierarchy, or DISPATCH_MODE_STOP 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 DISPATCH_MODE_STOP behaves the same way as returning WindowInsetsCompat#CONSUMED during the regular insets dispatch in View#onApplyWindowInsets.

Return
Int Either DISPATCH_MODE_CONTINUE_ON_SUBTREE to indicate that dispatching of animation events will continue to the subtree of the view hierarchy, or DISPATCH_MODE_STOP to indicate that animation events will stop dispatching.

onEnd

open fun onEnd(@NonNull animation: WindowInsetsAnimationCompat): Unit

Called when an insets animation has ended.

Parameters
animation WindowInsetsAnimationCompat: The animation that has ended. This will be the same instance as passed into onStart

onPrepare

open fun onPrepare(@NonNull animation: WindowInsetsAnimationCompat): Unit

Called when an insets animation is about to start and before the views have been re-laid out due to an animation.

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 onProgress callback by using post-layout view properties like View#setX and related methods.

The ordering of events during an insets animation is the following:

Note: If the animation is application controlled by using WindowInsetsControllerCompat#controlWindowInsetsAnimation, 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 WindowInsetsAnimationControllerCompat#finish. 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 WindowInsetsControllerCompat#controlWindowInsetsAnimation and the input method is currently showing, View#onApplyWindowInsets will receive a WindowInsetsCompat instance for which WindowInsetsCompat#isVisible will return false for WindowInsetsCompat.Type#ime.

Parameters
animation WindowInsetsAnimationCompat: The animation that is about to start.