WindowInsetsAnimationControllerCompat

Added in 1.5.0

class WindowInsetsAnimationControllerCompat


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 controlWindowInsetsAnimation.

Summary

Public functions

Unit
finish(shown: Boolean)

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

Float

Current alpha value of the window.

@FloatRange(from = 0.0, to = 1.0) Float

Returns the progress as previously set by fraction in setInsetsAndAlpha

Insets

Retrieves the current insets.

Insets

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

Insets

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

Int
Boolean

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

Boolean

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

Boolean

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

Unit
setInsetsAndAlpha(
    insets: Insets?,
    alpha: @FloatRange(from = 0.0, to = 1.0) Float,
    fraction: @FloatRange(from = 0.0, to = 1.0) Float
)

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

Public functions

finish

Added in 1.5.0
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 1.5.0
fun getCurrentAlpha(): Float

Current alpha value of the window.

Returns
Float

float value between 0 and 1.

getCurrentFraction

Added in 1.5.0
fun getCurrentFraction(): @FloatRange(from = 0.0, to = 1.0) Float

Returns the progress as previously set by fraction in setInsetsAndAlpha

Returns
@FloatRange(from = 0.0, to = 1.0) 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.

getCurrentInsets

Added in 1.5.0
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 getRootView

Returns
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.

getHiddenStateInsets

Added in 1.5.0
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 getRootView

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

Returns
Insets

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

See also
getLowerBound

getShownStateInsets

Added in 1.5.0
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 getRootView

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

Returns
Insets

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

See also
getUpperBound

getTypes

Added in 1.5.0
fun getTypes(): Int
Returns
Int

The Types this object is currently controlling.

isCancelled

Added in 1.5.0
fun isCancelled(): Boolean

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

Returns
Boolean

true if the instance is cancelled, false otherwise.

See also
onCancelled

isFinished

Added in 1.5.0
fun isFinished(): Boolean

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

Returns
Boolean

true if the instance is finished, false otherwise.

See also
onFinished

isReady

Added in 1.5.0
fun isReady(): Boolean

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

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

Returns
Boolean

true if the instance is ready, false otherwise.

setInsetsAndAlpha

Added in 1.5.0
fun setInsetsAndAlpha(
    insets: Insets?,
    alpha: @FloatRange(from = 0.0, to = 1.0) Float,
    fraction: @FloatRange(from = 0.0, to = 1.0) 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 getRootView

Also note that this will not inform the view system of a full inset change via 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 WindowInsetsAnimationCompat.Callback by calling setWindowInsetsAnimationCallback that will be notified about any insets change via onProgress during the animation.

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: @FloatRange(from = 0.0, to = 1.0) Float

The new alpha to apply to the inset side.

fraction: @FloatRange(from = 0.0, to = 1.0) Float

instantaneous animation progress. This value is dispatched to WindowInsetsAnimationCompat.Callback.