WindowInsetsAnimationControllerCompat

Added in 1.5.0

public final 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 methods

void
finish(boolean shown)

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

@NonNull Insets

Retrieves the current insets.

@NonNull Insets

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

@NonNull 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.

void
setInsetsAndAlpha(
    @Nullable Insets insets,
    @FloatRange(from = 0.0, to = 1.0) float alpha,
    @FloatRange(from = 0.0, to = 1.0) float fraction
)

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 1.5.0
public void finish(boolean shown)

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
boolean shown

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

getCurrentAlpha

Added in 1.5.0
public float getCurrentAlpha()

Current alpha value of the window.

Returns
float

float value between 0 and 1.

getCurrentFraction

Added in 1.5.0
public @FloatRange(from = 0.0, to = 1.0) float getCurrentFraction()

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
public @NonNull Insets getCurrentInsets()

Retrieves the current insets.

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

Returns
@NonNull 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
public @NonNull Insets getHiddenStateInsets()

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
@NonNull Insets

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

See also
getLowerBound

getShownStateInsets

Added in 1.5.0
public @NonNull Insets getShownStateInsets()

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
@NonNull Insets

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

See also
getUpperBound

getTypes

Added in 1.5.0
public int getTypes()
Returns
int

The Types this object is currently controlling.

isCancelled

Added in 1.5.0
public boolean isCancelled()

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
public boolean isFinished()

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
public boolean isReady()

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
public void setInsetsAndAlpha(
    @Nullable Insets insets,
    @FloatRange(from = 0.0, to = 1.0) float alpha,
    @FloatRange(from = 0.0, to = 1.0) float fraction
)

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
@Nullable 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.

@FloatRange(from = 0.0, to = 1.0) float alpha

The new alpha to apply to the inset side.

@FloatRange(from = 0.0, to = 1.0) float fraction

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