FileDocCategorySizeDatePackage
WindowInsets.javaAPI DocAndroid 5.1 API17901Thu Mar 12 22:22:10 GMT 2015android.view

WindowInsets

public final class WindowInsets extends Object
Describes a set of insets for window content.

WindowInsets are immutable and may be expanded to include more inset types in the future. To adjust insets, use one of the supplied clone methods to obtain a new WindowInsets instance with the adjusted properties.

see
View.OnApplyWindowInsetsListener
see
View#onApplyWindowInsets(WindowInsets)

Fields Summary
private android.graphics.Rect
mSystemWindowInsets
private android.graphics.Rect
mWindowDecorInsets
private android.graphics.Rect
mStableInsets
private android.graphics.Rect
mTempRect
private boolean
mIsRound
private boolean
mSystemWindowInsetsConsumed
private boolean
mWindowDecorInsetsConsumed
private boolean
mStableInsetsConsumed
private static final android.graphics.Rect
EMPTY_RECT
public static final WindowInsets
CONSUMED
Since new insets may be added in the future that existing apps couldn't know about, this fully empty constant shouldn't be made available to apps since it would allow them to inadvertently consume unknown insets by returning it.
Constructors Summary
public WindowInsets(android.graphics.Rect systemWindowInsets, android.graphics.Rect windowDecorInsets, android.graphics.Rect stableInsets, boolean isRound)

hide


     
        CONSUMED = new WindowInsets(null, null, null, false);
    
        mSystemWindowInsetsConsumed = systemWindowInsets == null;
        mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets;

        mWindowDecorInsetsConsumed = windowDecorInsets == null;
        mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets;

        mStableInsetsConsumed = stableInsets == null;
        mStableInsets = mStableInsetsConsumed ? EMPTY_RECT : stableInsets;

        mIsRound = isRound;
    
public WindowInsets(WindowInsets src)
Construct a new WindowInsets, copying all values from a source WindowInsets.

param
src Source to copy insets from

        mSystemWindowInsets = src.mSystemWindowInsets;
        mWindowDecorInsets = src.mWindowDecorInsets;
        mStableInsets = src.mStableInsets;
        mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed;
        mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed;
        mStableInsetsConsumed = src.mStableInsetsConsumed;
        mIsRound = src.mIsRound;
    
public WindowInsets(android.graphics.Rect systemWindowInsets)

hide

        this(systemWindowInsets, null, null, false);
    
Methods Summary
public android.view.WindowInsetsconsumeStableInsets()
Returns a copy of this WindowInsets with the stable insets fully consumed.

return
A modified copy of this WindowInsets

        final WindowInsets result = new WindowInsets(this);
        result.mStableInsets = EMPTY_RECT;
        result.mStableInsetsConsumed = true;
        return result;
    
public android.view.WindowInsetsconsumeSystemWindowInsets()
Returns a copy of this WindowInsets with the system window insets fully consumed.

return
A modified copy of this WindowInsets

        final WindowInsets result = new WindowInsets(this);
        result.mSystemWindowInsets = EMPTY_RECT;
        result.mSystemWindowInsetsConsumed = true;
        return result;
    
public android.view.WindowInsetsconsumeSystemWindowInsets(boolean left, boolean top, boolean right, boolean bottom)
Returns a copy of this WindowInsets with selected system window insets fully consumed.

param
left true to consume the left system window inset
param
top true to consume the top system window inset
param
right true to consume the right system window inset
param
bottom true to consume the bottom system window inset
return
A modified copy of this WindowInsets
hide
pending API

        if (left || top || right || bottom) {
            final WindowInsets result = new WindowInsets(this);
            result.mSystemWindowInsets = new Rect(
                    left ? 0 : mSystemWindowInsets.left,
                    top ? 0 : mSystemWindowInsets.top,
                    right ? 0 : mSystemWindowInsets.right,
                    bottom ? 0 : mSystemWindowInsets.bottom);
            return result;
        }
        return this;
    
public android.view.WindowInsetsconsumeWindowDecorInsets()

hide

        final WindowInsets result = new WindowInsets(this);
        result.mWindowDecorInsets.set(0, 0, 0, 0);
        result.mWindowDecorInsetsConsumed = true;
        return result;
    
public android.view.WindowInsetsconsumeWindowDecorInsets(boolean left, boolean top, boolean right, boolean bottom)

hide

        if (left || top || right || bottom) {
            final WindowInsets result = new WindowInsets(this);
            result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left,
                    top ? 0 : mWindowDecorInsets.top,
                    right ? 0 : mWindowDecorInsets.right,
                    bottom ? 0 : mWindowDecorInsets.bottom);
            return result;
        }
        return this;
    
public intgetStableInsetBottom()
Returns the bottom stable inset in pixels.

The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.

return
The bottom stable inset

        return mStableInsets.bottom;
    
public intgetStableInsetLeft()
Returns the left stable inset in pixels.

The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.

return
The left stable inset

        return mStableInsets.left;
    
public intgetStableInsetRight()
Returns the right stable inset in pixels.

The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.

return
The right stable inset

        return mStableInsets.right;
    
public intgetStableInsetTop()
Returns the top stable inset in pixels.

The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.

return
The top stable inset

        return mStableInsets.top;
    
public intgetSystemWindowInsetBottom()
Returns the bottom system window inset in pixels.

The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.

return
The bottom system window inset

        return mSystemWindowInsets.bottom;
    
public intgetSystemWindowInsetLeft()
Returns the left system window inset in pixels.

The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.

return
The left system window inset

        return mSystemWindowInsets.left;
    
public intgetSystemWindowInsetRight()
Returns the right system window inset in pixels.

The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.

return
The right system window inset

        return mSystemWindowInsets.right;
    
public intgetSystemWindowInsetTop()
Returns the top system window inset in pixels.

The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.

return
The top system window inset

        return mSystemWindowInsets.top;
    
public android.graphics.RectgetSystemWindowInsets()
Used to provide a safe copy of the system window insets to pass through to the existing fitSystemWindows method and other similar internals.

hide

        if (mTempRect == null) {
            mTempRect = new Rect();
        }
        if (mSystemWindowInsets != null) {
            mTempRect.set(mSystemWindowInsets);
        } else {
            // If there were no system window insets, this is just empty.
            mTempRect.setEmpty();
        }
        return mTempRect;
    
public intgetWindowDecorInsetBottom()
Returns the bottom window decor inset in pixels.

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework. This can include action bars, title bars, toolbars, etc.

return
The bottom window decor inset
hide
pending API

        return mWindowDecorInsets.bottom;
    
public intgetWindowDecorInsetLeft()
Returns the left window decor inset in pixels.

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework. This can include action bars, title bars, toolbars, etc.

return
The left window decor inset
hide
pending API

        return mWindowDecorInsets.left;
    
public intgetWindowDecorInsetRight()
Returns the right window decor inset in pixels.

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework. This can include action bars, title bars, toolbars, etc.

return
The right window decor inset
hide
pending API

        return mWindowDecorInsets.right;
    
public intgetWindowDecorInsetTop()
Returns the top window decor inset in pixels.

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework. This can include action bars, title bars, toolbars, etc.

return
The top window decor inset
hide
pending API

        return mWindowDecorInsets.top;
    
public booleanhasInsets()
Returns true if this WindowInsets has any nonzero insets.

return
true if any inset values are nonzero

        return hasSystemWindowInsets() || hasWindowDecorInsets();
    
public booleanhasStableInsets()
Returns true if this WindowInsets has nonzero stable insets.

The stable inset represents the area of a full-screen window that may be partially or fully obscured by the system UI elements. This value does not change based on the visibility state of those elements; for example, if the status bar is normally shown, but temporarily hidden, the stable inset will still provide the inset associated with the status bar being shown.

return
true if any of the stable inset values are nonzero

        return mStableInsets.top != 0 || mStableInsets.left != 0 || mStableInsets.right != 0
                || mStableInsets.bottom != 0;
    
public booleanhasSystemWindowInsets()
Returns true if this WindowInsets has nonzero system window insets.

The system window inset represents the area of a full-screen window that is partially or fully obscured by the status bar, navigation bar, IME or other system windows.

return
true if any of the system window inset values are nonzero

        return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 ||
                mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0;
    
public booleanhasWindowDecorInsets()
Returns true if this WindowInsets has nonzero window decor insets.

The window decor inset represents the area of the window content area that is partially or fully obscured by decorations within the window provided by the framework. This can include action bars, title bars, toolbars, etc.

return
true if any of the window decor inset values are nonzero
hide
pending API

        return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 ||
                mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0;
    
public booleanisConsumed()
Check if these insets have been fully consumed.

Insets are considered "consumed" if the applicable consume* methods have been called such that all insets have been set to zero. This affects propagation of insets through the view hierarchy; insets that have not been fully consumed will continue to propagate down to child views.

The result of this method is equivalent to the return value of {@link View#fitSystemWindows(android.graphics.Rect)}.

return
true if the insets have been fully consumed.

        return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed && mStableInsetsConsumed;
    
public booleanisRound()
Returns true if the associated window has a round shape.

A round window's left, top, right and bottom edges reach all the way to the associated edges of the window but the corners may not be visible. Views responding to round insets should take care to not lay out critical elements within the corners where they may not be accessible.

return
True if the window is round

        return mIsRound;
    
public android.view.WindowInsetsreplaceSystemWindowInsets(int left, int top, int right, int bottom)
Returns a copy of this WindowInsets with selected system window insets replaced with new values.

param
left New left inset in pixels
param
top New top inset in pixels
param
right New right inset in pixels
param
bottom New bottom inset in pixels
return
A modified copy of this WindowInsets

        final WindowInsets result = new WindowInsets(this);
        result.mSystemWindowInsets = new Rect(left, top, right, bottom);
        return result;
    
public android.view.WindowInsetsreplaceSystemWindowInsets(android.graphics.Rect systemWindowInsets)
Returns a copy of this WindowInsets with selected system window insets replaced with new values.

param
systemWindowInsets New system window insets. Each field is the inset in pixels for that edge
return
A modified copy of this WindowInsets

        final WindowInsets result = new WindowInsets(this);
        result.mSystemWindowInsets = new Rect(systemWindowInsets);
        return result;
    
public android.view.WindowInsetsreplaceWindowDecorInsets(int left, int top, int right, int bottom)

hide

        final WindowInsets result = new WindowInsets(this);
        result.mWindowDecorInsets = new Rect(left, top, right, bottom);
        return result;
    
public java.lang.StringtoString()

        return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets
                + " windowDecorInsets=" + mWindowDecorInsets
                + " stableInsets=" + mStableInsets +
                (isRound() ? " round}" : "}");