WindowInsets.java revision eba8782a1f8412a3510fc78a71b843ef6e89bdbb
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 {
3350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mSystemWindowInsets;
3450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mWindowDecorInsets;
3550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private Rect mTempRect;
36973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    private boolean mIsRound;
3750d7bfd8224f9da170dac668888bcf0831373051Adam Powell
3850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0);
3950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
4050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
4150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Since new insets may be added in the future that existing apps couldn't
4250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * know about, this fully empty constant shouldn't be made available to apps
4350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * since it would allow them to inadvertently consume unknown insets by returning it.
4450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @hide
4550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
4650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public static final WindowInsets EMPTY = new WindowInsets(EMPTY_RECT, EMPTY_RECT);
4750d7bfd8224f9da170dac668888bcf0831373051Adam Powell
4850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /** @hide */
4950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets) {
50973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        this(systemWindowInsets, windowDecorInsets, false);
51973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    }
52973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell
53973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    /** @hide */
546642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb    public WindowInsets(Rect systemWindowInsets, boolean isRound) {
556642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb        this(systemWindowInsets, EMPTY_RECT, isRound);
566642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb    }
576642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb
586642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb    /** @hide */
59973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, boolean isRound) {
6050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mSystemWindowInsets = systemWindowInsets;
6150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mWindowDecorInsets = windowDecorInsets;
62973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        mIsRound = isRound;
6350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
6450d7bfd8224f9da170dac668888bcf0831373051Adam Powell
6550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
6650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Construct a new WindowInsets, copying all values from a source WindowInsets.
6750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
6850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @param src Source to copy insets from
6950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
7050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public WindowInsets(WindowInsets src) {
7150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mSystemWindowInsets = src.mSystemWindowInsets;
7250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        mWindowDecorInsets = src.mWindowDecorInsets;
73973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        mIsRound = src.mIsRound;
7450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
7550d7bfd8224f9da170dac668888bcf0831373051Adam Powell
7650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /** @hide */
7750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public WindowInsets(Rect systemWindowInsets) {
78973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        this(systemWindowInsets, EMPTY_RECT);
7950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
8050d7bfd8224f9da170dac668888bcf0831373051Adam Powell
8150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
8250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Used to provide a safe copy of the system window insets to pass through
8350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * to the existing fitSystemWindows method and other similar internals.
8450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @hide
8550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
8650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public Rect getSystemWindowInsets() {
8750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (mTempRect == null) {
8850d7bfd8224f9da170dac668888bcf0831373051Adam Powell            mTempRect = new Rect();
8950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
90eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        if (mSystemWindowInsets != null) {
91eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            mTempRect.set(mSystemWindowInsets);
92eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        } else {
93eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            // If there were no system window insets, this is just empty.
94eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh            mTempRect.setEmpty();
95eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh        }
9650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mTempRect;
9750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
9850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
9950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
10050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the left system window inset in pixels.
10150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
10250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
10350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
10450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
10550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
10650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The left system window inset
10750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
10850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetLeft() {
10950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.left;
11050d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
11150d7bfd8224f9da170dac668888bcf0831373051Adam Powell
11250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
11350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the top system window inset in pixels.
11450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
11550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
11650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
11750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
11850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
11950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The top system window inset
12050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
12150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetTop() {
12250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.top;
12350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
12450d7bfd8224f9da170dac668888bcf0831373051Adam Powell
12550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
12650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the right system window inset in pixels.
12750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
12850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
12950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
13050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
13150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
13250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The right system window inset
13350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
13450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetRight() {
13550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.right;
13650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
13750d7bfd8224f9da170dac668888bcf0831373051Adam Powell
13850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
13950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the bottom system window inset in pixels.
14050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
14150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
14250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
14350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
14450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
14550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The bottom system window inset
14650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
14750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getSystemWindowInsetBottom() {
14850d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.bottom;
14950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
15050d7bfd8224f9da170dac668888bcf0831373051Adam Powell
15150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
15250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the left window decor inset in pixels.
15350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
15450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
15550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
15650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
15750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
15850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The left window decor inset
159f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
16050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
16150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetLeft() {
16250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.left;
16350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
16450d7bfd8224f9da170dac668888bcf0831373051Adam Powell
16550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
16650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the top window decor inset in pixels.
16750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
16850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
16950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
17050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
17150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
17250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The top window decor inset
173f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
17450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
17550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetTop() {
17650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.top;
17750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
17850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
17950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
18050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the right window decor inset in pixels.
18150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
18250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
18350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
18450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
18550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
18650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The right window decor inset
187f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
18850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
18950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetRight() {
19050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.right;
19150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
19250d7bfd8224f9da170dac668888bcf0831373051Adam Powell
19350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
19450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns the bottom window decor inset in pixels.
19550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
19650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
19750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
19850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
19950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
20050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return The bottom window decor inset
201f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
20250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
20350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public int getWindowDecorInsetBottom() {
20450d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.bottom;
20550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
20650d7bfd8224f9da170dac668888bcf0831373051Adam Powell
20750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
20850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has nonzero system window insets.
20950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
21050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The system window inset represents the area of a full-screen window that is
21150d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
21250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * </p>
21350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
21450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any of the system window inset values are nonzero
21550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
21650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasSystemWindowInsets() {
21750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 ||
21850d7bfd8224f9da170dac668888bcf0831373051Adam Powell                mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0;
21950d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
22050d7bfd8224f9da170dac668888bcf0831373051Adam Powell
22150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
22250d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has nonzero window decor insets.
22350d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
22450d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * <p>The window decor inset represents the area of the window content area that is
22550d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * partially or fully obscured by decorations within the window provided by the framework.
22650d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * This can include action bars, title bars, toolbars, etc.</p>
22750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
22850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any of the window decor inset values are nonzero
229f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
23050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
23150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasWindowDecorInsets() {
23250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 ||
23350d7bfd8224f9da170dac668888bcf0831373051Adam Powell                mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0;
23450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
23550d7bfd8224f9da170dac668888bcf0831373051Adam Powell
23650d7bfd8224f9da170dac668888bcf0831373051Adam Powell    /**
23750d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * Returns true if this WindowInsets has any nonzero insets.
23850d7bfd8224f9da170dac668888bcf0831373051Adam Powell     *
23950d7bfd8224f9da170dac668888bcf0831373051Adam Powell     * @return true if any inset values are nonzero
24050d7bfd8224f9da170dac668888bcf0831373051Adam Powell     */
24150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public boolean hasInsets() {
24250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return hasSystemWindowInsets() || hasWindowDecorInsets();
24350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
24450d7bfd8224f9da170dac668888bcf0831373051Adam Powell
245973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    /**
246973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * Returns true if the associated window has a round shape.
247973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     *
248973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * <p>A round window's left, top, right and bottom edges reach all the way to the
249973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * associated edges of the window but the corners may not be visible. Views responding
250973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * to round insets should take care to not lay out critical elements within the corners
251973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * where they may not be accessible.</p>
252973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     *
253973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     * @return True if the window is round
254973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell     */
255973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    public boolean isRound() {
256973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell        return mIsRound;
257973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell    }
258973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell
259f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
260f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with the system window insets fully consumed.
261f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
262f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
263f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
264f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeSystemWindowInsets() {
26550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
26650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mSystemWindowInsets = new Rect(0, 0, 0, 0);
26750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
26850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
26950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
270f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
271f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with selected system window insets fully consumed.
272f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
273f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param left true to consume the left system window inset
274f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param top true to consume the top system window inset
275f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param right true to consume the right system window inset
276f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param bottom true to consume the bottom system window inset
277f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
278f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide pending API
279f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
280f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeSystemWindowInsets(boolean left, boolean top,
28150d7bfd8224f9da170dac668888bcf0831373051Adam Powell            boolean right, boolean bottom) {
28250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (left || top || right || bottom) {
28350d7bfd8224f9da170dac668888bcf0831373051Adam Powell            final WindowInsets result = new WindowInsets(this);
28450d7bfd8224f9da170dac668888bcf0831373051Adam Powell            result.mSystemWindowInsets = new Rect(left ? 0 : mSystemWindowInsets.left,
28550d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    top ? 0 : mSystemWindowInsets.top,
28650d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    right ? 0 : mSystemWindowInsets.right,
28750d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    bottom ? 0 : mSystemWindowInsets.bottom);
28850d7bfd8224f9da170dac668888bcf0831373051Adam Powell            return result;
28950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
29050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return this;
29150d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
29250d7bfd8224f9da170dac668888bcf0831373051Adam Powell
293f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
294f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * Returns a copy of this WindowInsets with selected system window insets replaced
295f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * with new values.
296f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     *
297f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param left New left inset in pixels
298f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param top New top inset in pixels
299f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param right New right inset in pixels
300f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @param bottom New bottom inset in pixels
301f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @return A modified copy of this WindowInsets
302f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
303f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets replaceSystemWindowInsets(int left, int top,
304f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell            int right, int bottom) {
30550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
30650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mSystemWindowInsets = new Rect(left, top, right, bottom);
30750d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
30850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
30950d7bfd8224f9da170dac668888bcf0831373051Adam Powell
310f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
311f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
312f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
313f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeWindowDecorInsets() {
31450d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
31550d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mWindowDecorInsets.set(0, 0, 0, 0);
31650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
31750d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
31850d7bfd8224f9da170dac668888bcf0831373051Adam Powell
319f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
320f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
321f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
322f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets consumeWindowDecorInsets(boolean left, boolean top,
32350d7bfd8224f9da170dac668888bcf0831373051Adam Powell            boolean right, boolean bottom) {
32450d7bfd8224f9da170dac668888bcf0831373051Adam Powell        if (left || top || right || bottom) {
32550d7bfd8224f9da170dac668888bcf0831373051Adam Powell            final WindowInsets result = new WindowInsets(this);
32650d7bfd8224f9da170dac668888bcf0831373051Adam Powell            result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left,
32750d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    top ? 0 : mWindowDecorInsets.top,
32850d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    right ? 0 : mWindowDecorInsets.right,
32950d7bfd8224f9da170dac668888bcf0831373051Adam Powell                    bottom ? 0 : mWindowDecorInsets.bottom);
33050d7bfd8224f9da170dac668888bcf0831373051Adam Powell            return result;
33150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        }
33250d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return this;
33350d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
33450d7bfd8224f9da170dac668888bcf0831373051Adam Powell
335f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    /**
336f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     * @hide
337f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell     */
338f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell    public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) {
33950d7bfd8224f9da170dac668888bcf0831373051Adam Powell        final WindowInsets result = new WindowInsets(this);
34050d7bfd8224f9da170dac668888bcf0831373051Adam Powell        result.mWindowDecorInsets = new Rect(left, top, right, bottom);
34150d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return result;
34250d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
34350d7bfd8224f9da170dac668888bcf0831373051Adam Powell
34450d7bfd8224f9da170dac668888bcf0831373051Adam Powell    @Override
34550d7bfd8224f9da170dac668888bcf0831373051Adam Powell    public String toString() {
34650d7bfd8224f9da170dac668888bcf0831373051Adam Powell        return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + " windowDecorInsets=" +
347973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell                mWindowDecorInsets + (isRound() ? "round}" : "}");
34850d7bfd8224f9da170dac668888bcf0831373051Adam Powell    }
34950d7bfd8224f9da170dac668888bcf0831373051Adam Powell}
350