150d7bfd8224f9da170dac668888bcf0831373051Adam Powell/*
250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Copyright (C) 2014 The Android Open Source Project
350d7bfd8224f9da170dac668888bcf0831373051Adam Powell *
450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * you may not use this file except in compliance with the License.
650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * You may obtain a copy of the License at
750d7bfd8224f9da170dac668888bcf0831373051Adam Powell *
850d7bfd8224f9da170dac668888bcf0831373051Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
950d7bfd8224f9da170dac668888bcf0831373051Adam Powell *
1050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Unless required by applicable law or agreed to in writing, software
1150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
1250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * See the License for the specific language governing permissions and
1450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * limitations under the License.
1550d7bfd8224f9da170dac668888bcf0831373051Adam Powell */
1650d7bfd8224f9da170dac668888bcf0831373051Adam Powell
1750d7bfd8224f9da170dac668888bcf0831373051Adam Powell
1850d7bfd8224f9da170dac668888bcf0831373051Adam Powellpackage android.view;
1950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
2050d7bfd8224f9da170dac668888bcf0831373051Adam Powellimport android.graphics.Rect;
2150d7bfd8224f9da170dac668888bcf0831373051Adam Powell
2250d7bfd8224f9da170dac668888bcf0831373051Adam Powell/**
2350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Describes a set of insets for window content.
2450d7bfd8224f9da170dac668888bcf0831373051Adam Powell *
2550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>WindowInsets are immutable and may be expanded to include more inset types in the future.
2650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * To adjust insets, use one of the supplied clone methods to obtain a new WindowInsets instance
2750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * with the adjusted properties.</p>
2850d7bfd8224f9da170dac668888bcf0831373051Adam Powell *
2950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @see View.OnApplyWindowInsetsListener
3050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @see View#onApplyWindowInsets(WindowInsets)
3150d7bfd8224f9da170dac668888bcf0831373051Adam Powell */
32f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powellpublic final class WindowInsets {
33fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
3450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mSystemWindowInsets;
3550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mWindowDecorInsets;
36fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    private Rect mStableInsets;
3750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mTempRect;
38973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    private boolean mIsRound;
3950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
400ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi    /**
410ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     * In multi-window we force show the navigation bar. Because we don't want that the surface size
420ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     * changes in this mode, we instead have a flag whether the navigation bar size should always
430ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     * be consumed, so the app is treated like there is no virtual navigation bar at all.
440ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     */
450ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi    private boolean mAlwaysConsumeNavBar;
460ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi
470d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell    private boolean mSystemWindowInsetsConsumed = false;
480d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell    private boolean mWindowDecorInsetsConsumed = false;
49fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    private boolean mStableInsetsConsumed = false;
500d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell
5150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0);
5250d7bfd8224f9da170dac668888bcf0831373051Adam Powell
5350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
5450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Since new insets may be added in the future that existing apps couldn't
5550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * know about, this fully empty constant shouldn't be made available to apps
5650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * since it would allow them to inadvertently consume unknown insets by returning it.
5750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @hide
5850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
59720924b6a9770f03355999102a11d98c5954407cAdam Powell    public static final WindowInsets CONSUMED;
60720924b6a9770f03355999102a11d98c5954407cAdam Powell
61720924b6a9770f03355999102a11d98c5954407cAdam Powell    static {
620ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi        CONSUMED = new WindowInsets(null, null, null, false, false);
636642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb    }
646642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb
656642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb    /** @hide */
66fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, Rect stableInsets,
670ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi            boolean isRound, boolean alwaysConsumeNavBar) {
680d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mSystemWindowInsetsConsumed = systemWindowInsets == null;
690d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets;
700d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell
710d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mWindowDecorInsetsConsumed = windowDecorInsets == null;
720d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets;
730d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell
74fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        mStableInsetsConsumed = stableInsets == null;
75fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        mStableInsets = mStableInsetsConsumed ? EMPTY_RECT : stableInsets;
76fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
77973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        mIsRound = isRound;
780ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi        mAlwaysConsumeNavBar = alwaysConsumeNavBar;
7950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
8050d7bfd8224f9da170dac668888bcf0831373051Adam Powell
8150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
8250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Construct a new WindowInsets, copying all values from a source WindowInsets.
8350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
8450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @param src Source to copy insets from
8550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
8650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public WindowInsets(WindowInsets src) {
8750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mSystemWindowInsets = src.mSystemWindowInsets;
8850d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mWindowDecorInsets = src.mWindowDecorInsets;
89fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        mStableInsets = src.mStableInsets;
900d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed;
910d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed;
92fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        mStableInsetsConsumed = src.mStableInsetsConsumed;
93973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        mIsRound = src.mIsRound;
94e5638a6f75472127493422a68954aa3fd2109658Jorim Jaggi        mAlwaysConsumeNavBar = src.mAlwaysConsumeNavBar;
9550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
9650d7bfd8224f9da170dac668888bcf0831373051Adam Powell
9750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /** @hide */
9850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public WindowInsets(Rect systemWindowInsets) {
990ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi        this(systemWindowInsets, null, null, false, false);
10050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
10150d7bfd8224f9da170dac668888bcf0831373051Adam Powell
10250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
10350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Used to provide a safe copy of the system window insets to pass through
10450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * to the existing fitSystemWindows method and other similar internals.
10550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @hide
10650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
10750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public Rect getSystemWindowInsets() {
10850d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (mTempRect == null) {
10950d7bfd8224f9da170dac668888bcf0831373051Adam Powell            mTempRect = new Rect();
11050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
111eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        if (mSystemWindowInsets != null) {
112eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            mTempRect.set(mSystemWindowInsets);
113eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        } else {
114eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            // If there were no system window insets, this is just empty.
115eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            mTempRect.setEmpty();
116eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        }
11750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mTempRect;
11850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
11950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
12050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
12150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the left system window inset in pixels.
12250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
12350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
12450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
12550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
12650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
12750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The left system window inset
12850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
12950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetLeft() {
13050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.left;
13150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
13250d7bfd8224f9da170dac668888bcf0831373051Adam Powell
13350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
13450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the top system window inset in pixels.
13550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
13650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
13750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
13850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
13950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
14050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The top system window inset
14150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
14250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetTop() {
14350d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.top;
14450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
14550d7bfd8224f9da170dac668888bcf0831373051Adam Powell
14650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
14750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the right system window inset in pixels.
14850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
14950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
15050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
15150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
15250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
15350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The right system window inset
15450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
15550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetRight() {
15650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.right;
15750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
15850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
15950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
16050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the bottom system window inset in pixels.
16150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
16250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
16350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
16450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
16550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
16650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The bottom system window inset
16750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
16850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetBottom() {
16950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.bottom;
17050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
17150d7bfd8224f9da170dac668888bcf0831373051Adam Powell
17250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
17350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the left window decor inset in pixels.
17450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
17550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
17650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
17750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
17850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
17950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The left window decor inset
180f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
18150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
18250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetLeft() {
18350d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.left;
18450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
18550d7bfd8224f9da170dac668888bcf0831373051Adam Powell
18650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
18750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the top window decor inset in pixels.
18850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
18950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
19050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
19150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
19250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
19350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The top window decor inset
194f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
19550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
19650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetTop() {
19750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.top;
19850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
19950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
20050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
20150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the right window decor inset in pixels.
20250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
20350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
20450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
20550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
20650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
20750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The right window decor inset
208f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
20950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
21050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetRight() {
21150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.right;
21250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
21350d7bfd8224f9da170dac668888bcf0831373051Adam Powell
21450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
21550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the bottom window decor inset in pixels.
21650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
21750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
21850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
21950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
22050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
22150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The bottom window decor inset
222f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
22350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
22450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetBottom() {
22550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.bottom;
22650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
22750d7bfd8224f9da170dac668888bcf0831373051Adam Powell
22850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
22950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has nonzero system window insets.
23050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
23150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
23250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
23350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
23450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
23550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any of the system window inset values are nonzero
23650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
23750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasSystemWindowInsets() {
23850d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 ||
23950d7bfd8224f9da170dac668888bcf0831373051Adam Powell                mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0;
24050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
24150d7bfd8224f9da170dac668888bcf0831373051Adam Powell
24250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
24350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has nonzero window decor insets.
24450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
24550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
24650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
24750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
24850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
24950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any of the window decor inset values are nonzero
250f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
25150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
25250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasWindowDecorInsets() {
25350d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 ||
25450d7bfd8224f9da170dac668888bcf0831373051Adam Powell                mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0;
25550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
25650d7bfd8224f9da170dac668888bcf0831373051Adam Powell
25750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
25850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has any nonzero insets.
25950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
26050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any inset values are nonzero
26150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
26250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasInsets() {
26305e967820dc71286b743294af0e80e2939ff9738Adam Powell        return hasSystemWindowInsets() || hasWindowDecorInsets() || hasStableInsets();
26450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
26550d7bfd8224f9da170dac668888bcf0831373051Adam Powell
266973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    /**
2670d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * Check if these insets have been fully consumed.
2680d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     *
2690d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * <p>Insets are considered "consumed" if the applicable <code>consume*</code> methods
2700d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * have been called such that all insets have been set to zero. This affects propagation of
2710d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * insets through the view hierarchy; insets that have not been fully consumed will continue
2720d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * to propagate down to child views.</p>
2730d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     *
2740d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * <p>The result of this method is equivalent to the return value of
2750d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * {@link View#fitSystemWindows(android.graphics.Rect)}.</p>
2760d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     *
2770d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     * @return true if the insets have been fully consumed.
2780d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell     */
2790d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell    public boolean isConsumed() {
280fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed && mStableInsetsConsumed;
2810d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell    }
2820d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell
2830d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell    /**
284973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * Returns true if the associated window has a round shape.
285973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     *
286973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * <p>A round window's left, top, right and bottom edges reach all the way to the
287973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * associated edges of the window but the corners may not be visible. Views responding
288973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * to round insets should take care to not lay out critical elements within the corners
289973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * where they may not be accessible.</p>
290973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     *
291973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * @return True if the window is round
292973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     */
293973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    public boolean isRound() {
294973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        return mIsRound;
295973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    }
296973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell
297f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
298f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with the system window insets fully consumed.
299f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
300f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
301f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
302f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeSystemWindowInsets() {
30350d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
3040d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        result.mSystemWindowInsets = EMPTY_RECT;
3050d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        result.mSystemWindowInsetsConsumed = true;
30650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
30750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
30850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
309f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
310f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with selected system window insets fully consumed.
311f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
312f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param left true to consume the left system window inset
313f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param top true to consume the top system window inset
314f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param right true to consume the right system window inset
315f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param bottom true to consume the bottom system window inset
316f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
317f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
318f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
319f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeSystemWindowInsets(boolean left, boolean top,
32050d7bfd8224f9da170dac668888bcf0831373051Adam Powell            boolean right, boolean bottom) {
32150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (left || top || right || bottom) {
32250d7bfd8224f9da170dac668888bcf0831373051Adam Powell            final WindowInsets result = new WindowInsets(this);
3230d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell            result.mSystemWindowInsets = new Rect(
3240d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell                    left ? 0 : mSystemWindowInsets.left,
32550d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    top ? 0 : mSystemWindowInsets.top,
32650d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    right ? 0 : mSystemWindowInsets.right,
32750d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    bottom ? 0 : mSystemWindowInsets.bottom);
32850d7bfd8224f9da170dac668888bcf0831373051Adam Powell            return result;
32950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
33050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return this;
33150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
33250d7bfd8224f9da170dac668888bcf0831373051Adam Powell
333f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
334f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with selected system window insets replaced
335f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * with new values.
336f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
337f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param left New left inset in pixels
338f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param top New top inset in pixels
339f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param right New right inset in pixels
340f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param bottom New bottom inset in pixels
341f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
342f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
343f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets replaceSystemWindowInsets(int left, int top,
344f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell            int right, int bottom) {
34550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
34650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mSystemWindowInsets = new Rect(left, top, right, bottom);
34750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
34850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
34950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
350f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
351d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     * Returns a copy of this WindowInsets with selected system window insets replaced
352d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     * with new values.
353d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     *
354d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     * @param systemWindowInsets New system window insets. Each field is the inset in pixels
355d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     *                           for that edge
356d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     * @return A modified copy of this WindowInsets
357d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell     */
358d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell    public WindowInsets replaceSystemWindowInsets(Rect systemWindowInsets) {
359d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell        final WindowInsets result = new WindowInsets(this);
360d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell        result.mSystemWindowInsets = new Rect(systemWindowInsets);
361d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell        return result;
362d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell    }
363d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell
364d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell    /**
365f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
366f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
367f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeWindowDecorInsets() {
36850d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
36950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mWindowDecorInsets.set(0, 0, 0, 0);
3700d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell        result.mWindowDecorInsetsConsumed = true;
37150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
37250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
37350d7bfd8224f9da170dac668888bcf0831373051Adam Powell
374f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
375f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
376f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
377f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeWindowDecorInsets(boolean left, boolean top,
37850d7bfd8224f9da170dac668888bcf0831373051Adam Powell            boolean right, boolean bottom) {
37950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (left || top || right || bottom) {
38050d7bfd8224f9da170dac668888bcf0831373051Adam Powell            final WindowInsets result = new WindowInsets(this);
38150d7bfd8224f9da170dac668888bcf0831373051Adam Powell            result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left,
38250d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    top ? 0 : mWindowDecorInsets.top,
38350d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    right ? 0 : mWindowDecorInsets.right,
38450d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    bottom ? 0 : mWindowDecorInsets.bottom);
38550d7bfd8224f9da170dac668888bcf0831373051Adam Powell            return result;
38650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
38750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return this;
38850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
38950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
390f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
391f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
392f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
393f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) {
39450d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
39550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mWindowDecorInsets = new Rect(left, top, right, bottom);
39650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
39750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
39850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
399fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
400067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns the top stable inset in pixels.
401067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
402067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
403067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * partially or fully obscured by the system UI elements.  This value does not change
404067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * based on the visibility state of those elements; for example, if the status bar is
405067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * normally shown, but temporarily hidden, the stable inset will still provide the inset
406067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * associated with the status bar being shown.</p>
407067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
408067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return The top stable inset
409fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
410fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public int getStableInsetTop() {
411fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mStableInsets.top;
412fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
413fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
414fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
415067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns the left stable inset in pixels.
416067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
417067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
418067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * partially or fully obscured by the system UI elements.  This value does not change
419067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * based on the visibility state of those elements; for example, if the status bar is
420067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * normally shown, but temporarily hidden, the stable inset will still provide the inset
421067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * associated with the status bar being shown.</p>
422067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
423067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return The left stable inset
424fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
425fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public int getStableInsetLeft() {
426fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mStableInsets.left;
427fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
428fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
429fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
430067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns the right stable inset in pixels.
431067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
432067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
433067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * partially or fully obscured by the system UI elements.  This value does not change
434067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * based on the visibility state of those elements; for example, if the status bar is
435067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * normally shown, but temporarily hidden, the stable inset will still provide the inset
436067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * associated with the status bar being shown.</p>
437067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
438067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return The right stable inset
439fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
440fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public int getStableInsetRight() {
441fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mStableInsets.right;
442fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
443fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
444fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
445067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns the bottom stable inset in pixels.
446067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
447067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
448067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * partially or fully obscured by the system UI elements.  This value does not change
449067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * based on the visibility state of those elements; for example, if the status bar is
450067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * normally shown, but temporarily hidden, the stable inset will still provide the inset
451067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * associated with the status bar being shown.</p>
452067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
453067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return The bottom stable inset
454fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
455fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public int getStableInsetBottom() {
456fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mStableInsets.bottom;
457fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
458fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
459fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
460067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns true if this WindowInsets has nonzero stable insets.
461067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
462067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
463067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * partially or fully obscured by the system UI elements.  This value does not change
464067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * based on the visibility state of those elements; for example, if the status bar is
465067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * normally shown, but temporarily hidden, the stable inset will still provide the inset
466067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * associated with the status bar being shown.</p>
467067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
468067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return true if any of the stable inset values are nonzero
469fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
470fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public boolean hasStableInsets() {
471fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return mStableInsets.top != 0 || mStableInsets.left != 0 || mStableInsets.right != 0
472fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos                || mStableInsets.bottom != 0;
473fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
474fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
475fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    /**
476067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * Returns a copy of this WindowInsets with the stable insets fully consumed.
477067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     *
478067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn     * @return A modified copy of this WindowInsets
479fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos     */
480fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    public WindowInsets consumeStableInsets() {
481fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        final WindowInsets result = new WindowInsets(this);
482fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        result.mStableInsets = EMPTY_RECT;
483fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        result.mStableInsetsConsumed = true;
484fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return result;
485fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos    }
486fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos
4870ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi    /**
4880ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     * @hide
4890ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi     */
4900ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi    public boolean shouldAlwaysConsumeNavBar() {
4910ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi        return mAlwaysConsumeNavBar;
4920ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi    }
4930ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi
49450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    @Override
49550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public String toString() {
496fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos        return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets
497fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos                + " windowDecorInsets=" + mWindowDecorInsets
498fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos                + " stableInsets=" + mStableInsets +
499fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos                (isRound() ? " round}" : "}");
50050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
50150d7bfd8224f9da170dac668888bcf0831373051Adam Powell}
502