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

WindowInsetsAnimationControllerCompat

public final class WindowInsetsAnimationControllerCompat
extends Object

java.lang.Object
   ↳ androidx.core.view.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 WindowInsetsControllerCompat.controlWindowInsetsAnimation(int, long, Interpolator, CancellationSignal, WindowInsetsAnimationControlListenerCompat).

Summary

Public methods

void finish(boolean shown)

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

float getCurrentAlpha()

Current alpha value of the window.

float getCurrentFraction()

Returns the progress as previously set by fraction in setInsetsAndAlpha(Insets, float, float)

Insets getCurrentInsets()

Retrieves the current insets.

Insets getHiddenStateInsets()

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

Insets getShownStateInsets()

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

int getTypes()
boolean isCancelled()

Returns whether this instance has been cancelled by the system, or by invoking the CancellationSignal passed into WindowInsetsControllerCompat.controlWindowInsetsAnimation(int, long, Interpolator, CancellationSignal, WindowInsetsAnimationControlListenerCompat).

boolean isFinished()

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

boolean isReady()

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

void setInsetsAndAlpha(Insets insets, float alpha, float fraction)

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

Inherited methods

Public methods

finish

public void finish (boolean shown)

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

After invoking finish(boolean), 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

public float getCurrentAlpha ()

Current alpha value of the window.

Returns
float float value between 0 and 1.

getCurrentFraction

public float getCurrentFraction ()

Returns the progress as previously set by fraction in setInsetsAndAlpha(Insets, float, float)

Returns
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 0.0 and 1.0 inclusive.

getCurrentInsets

public Insets getCurrentInsets ()

Retrieves the current insets.

Note that these insets are always relative to the window, which is the same as being relative to View.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

public 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 View.getRootView()

If there are any animation listeners registered, this value is the same as WindowInsetsAnimationCompat.BoundsCompat.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.

getShownStateInsets

public 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 View.getRootView()

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

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

getTypes

public int getTypes ()

Returns
int The WindowInsetsCompat.Types this object is currently controlling.

isCancelled

public boolean isCancelled ()

Returns whether this instance has been cancelled by the system, or by invoking the CancellationSignal passed into WindowInsetsControllerCompat.controlWindowInsetsAnimation(int, long, Interpolator, CancellationSignal, WindowInsetsAnimationControlListenerCompat).

Returns
boolean true if the instance is cancelled, false otherwise.

isFinished

public boolean isFinished ()

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

Returns
boolean true if the instance is finished, false otherwise.

isReady

public boolean isReady ()

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

Instances are ready when passed in WindowInsetsAnimationControlListenerCompat.onReady(WindowInsetsAnimationControllerCompat, int) and stop being ready when it is either finished or cancelled.

Returns
boolean true if the instance is ready, false otherwise.

setInsetsAndAlpha

public void setInsetsAndAlpha (Insets insets, 
                float alpha, 
                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 View.getRootView()

Also note that this will not inform the view system of a full inset change via View.dispatchApplyWindowInsets(WindowInsets) 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 ViewCompat.setWindowInsetsAnimationCallback(View, WindowInsetsAnimationCompat.Callback) that will be notified about any insets change via WindowInsetsAnimationCompat.Callback.onProgress(WindowInsetsCompat, List) during the animation.

View.dispatchApplyWindowInsets(WindowInsets) will instead be called once the animation has finished, i.e. once finish(boolean) 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 0.0 and 1.0 inclusive.

fraction float: instantaneous animation progress. This value is dispatched to WindowInsetsAnimationCompat.Callback.

Value is between 0.0 and 1.0 inclusive.