Added in API level 30

WindowInsetsAnimationController

interface WindowInsetsAnimationController
android.view.WindowInsetsAnimationController

Controller for app-driven animation of system windows.

WindowInsetsAnimationController lets apps animate system windows such as the IME. The animation is synchronized, such that changes the system windows and the app's current frame are rendered at the same time.

Control is obtained through WindowInsetsController#controlWindowInsetsAnimation.

Summary

Public methods
abstract Unit
finish(shown: Boolean)

Finishes the animation, and leaves the windows shown or hidden.

abstract Float

Current alpha value of the window.

abstract Float

Returns the progress as previously set by fraction in setInsetsAndAlpha

abstract Insets

Retrieves the current insets.

abstract Insets

Retrieves the Insets when the windows this animation is controlling are fully hidden.

abstract Insets

Retrieves the Insets when the windows this animation is controlling are fully shown.

abstract Int

abstract Boolean

Returns whether this instance has been cancelled by the system, or by invoking the android.os.CancellationSignal passed into WindowInsetsController#controlWindowInsetsAnimation.

abstract Boolean

Returns whether this instance has been finished by a call to finish.

open Boolean

Returns whether this instance is ready to be used to control window insets.

abstract Unit
setInsetsAndAlpha(insets: Insets?, alpha: Float, fraction: Float)

Modifies the insets for the frame being drawn by indirectly moving the windows around in the system that are causing window insets.

Public methods

finish

Added in API level 30
abstract fun finish(shown: Boolean): Unit

Finishes the animation, and leaves the windows shown or hidden.

After invoking finish, this instance is no longer ready.

Note: Finishing an animation implicitly sets insets and alpha according to the requested end state without any further animation.

Parameters
shown Boolean: if true, the windows will be shown after finishing the animation. Otherwise they will be hidden.

getCurrentAlpha

Added in API level 30
abstract fun getCurrentAlpha(): Float

Current alpha value of the window.

Return
Float float value between 0 and 1.

getCurrentFraction

Added in API level 30
abstract fun getCurrentFraction(): Float

Returns the progress as previously set by fraction in setInsetsAndAlpha

Return
Float the progress of the animation, where 0 is fully hidden and 1 is fully shown.

Note: this value represents raw overall progress of the animation i.e. the combined progress of insets and alpha.

Value is between 0f and 1f inclusive

getCurrentInsets

Added in API level 30
abstract fun getCurrentInsets(): Insets

Retrieves the current insets.

Note that these insets are always relative to the window, which is the same as being relative to View#getRootView

Return
Insets The current insets on the currently showing frame. These insets will change as the animation progresses to reflect the current insets provided by the controlled window. This value cannot be null.

getHiddenStateInsets

Added in API level 30
abstract fun getHiddenStateInsets(): Insets

Retrieves the Insets when the windows this animation is controlling are fully hidden.

Note that these insets are always relative to the window, which is the same as being relative to View#getRootView

If there are any animation listeners registered, this value is the same as Bounds#getLowerBound() that is being be passed into the root view of the hierarchy.

Return
Insets Insets when the windows this animation is controlling are fully hidden. This value cannot be null.

getShownStateInsets

Added in API level 30
abstract fun getShownStateInsets(): Insets

Retrieves the Insets when the windows this animation is controlling are fully shown.

Note that these insets are always relative to the window, which is the same as being relative to View#getRootView

If there are any animation listeners registered, this value is the same as Bounds#getUpperBound() that is being passed into the root view of hierarchy.

Return
Insets Insets when the windows this animation is controlling are fully shown. This value cannot be null.

getTypes

Added in API level 30
abstract fun getTypes(): Int
Return
Int The WindowInsets.Types this object is currently controlling. Value is either 0 or a combination of android.view.WindowInsets.Type.STATUS_BARS, android.view.WindowInsets.Type.NAVIGATION_BARS, android.view.WindowInsets.Type.CAPTION_BAR, android.view.WindowInsets.Type.IME, android.view.WindowInsets.Type.WINDOW_DECOR, android.view.WindowInsets.Type.SYSTEM_GESTURES, android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES, android.view.WindowInsets.Type.TAPPABLE_ELEMENT, android.view.WindowInsets.Type.DISPLAY_CUTOUT, and android.view.WindowInsets.Type.SYSTEM_OVERLAYS

isCancelled

Added in API level 30
abstract fun isCancelled(): Boolean

Returns whether this instance has been cancelled by the system, or by invoking the android.os.CancellationSignal passed into WindowInsetsController#controlWindowInsetsAnimation.

Return
Boolean true if the instance is cancelled, false otherwise.

isFinished

Added in API level 30
abstract fun isFinished(): Boolean

Returns whether this instance has been finished by a call to finish.

Return
Boolean true if the instance is finished, false otherwise.

isReady

Added in API level 30
open fun isReady(): Boolean

Returns whether this instance is ready to be used to control window insets.

Instances are ready when passed in WindowInsetsAnimationControlListener#onReady and stop being ready when it is either finished or cancelled.

Return
Boolean true if the instance is ready, false otherwise.

setInsetsAndAlpha

Added in API level 30
abstract fun setInsetsAndAlpha(
    insets: Insets?,
    alpha: Float,
    fraction: Float
): Unit

Modifies the insets for the frame being drawn by indirectly moving the windows around in the system that are causing window insets.

Note that these insets are always relative to the window, which is the same as being relative to View#getRootView

Also note that this will not inform the view system of a full inset change via View#dispatchApplyWindowInsets in order to avoid a full layout pass during the animation. If you'd like to animate views during a window inset animation, register a WindowInsetsAnimation.Callback by calling View#setWindowInsetsAnimationCallback(WindowInsetsAnimation.Callback) that will be notified about any insets change via WindowInsetsAnimation.Callback#onProgress during the animation.

View#dispatchApplyWindowInsets will instead be called once the animation has finished, i.e. once finish has been called. Note: If there are no insets, alpha animation is still applied.

Parameters
insets Insets?: The new insets to apply. Based on the requested insets, the system will calculate the positions of the windows in the system causing insets such that the resulting insets of that configuration will match the passed in parameter. Note that these insets are being clamped to the range from getHiddenStateInsets to getShownStateInsets. If you intend on changing alpha only, pass null or getCurrentInsets().
alpha Float: The new alpha to apply to the inset side. Value is between 0f and 1f inclusive
fraction Float: instantaneous animation progress. This value is dispatched to WindowInsetsAnimation.Callback. Value is between 0f and 1f inclusive