WindowInsets.java revision 0d9fdbad751318b1e9a7a2789bf0e9240252e15f
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 380d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell private boolean mSystemWindowInsetsConsumed = false; 390d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell private boolean mWindowDecorInsetsConsumed = false; 400d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell 4150d7bfd8224f9da170dac668888bcf0831373051Adam Powell private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0); 4250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 4350d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 4450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Since new insets may be added in the future that existing apps couldn't 4550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * know about, this fully empty constant shouldn't be made available to apps 4650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * since it would allow them to inadvertently consume unknown insets by returning it. 4750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @hide 4850d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 4950d7bfd8224f9da170dac668888bcf0831373051Adam Powell public static final WindowInsets EMPTY = new WindowInsets(EMPTY_RECT, EMPTY_RECT); 5050d7bfd8224f9da170dac668888bcf0831373051Adam Powell 5150d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** @hide */ 5250d7bfd8224f9da170dac668888bcf0831373051Adam Powell public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets) { 53973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell this(systemWindowInsets, windowDecorInsets, false); 54973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell } 55973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell 56973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell /** @hide */ 576642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb public WindowInsets(Rect systemWindowInsets, boolean isRound) { 580d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell this(systemWindowInsets, null, isRound); 596642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb } 606642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb 616642e51ac5d0351f02fc929817603d7371e08e10Michael Kolb /** @hide */ 62973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, boolean isRound) { 630d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mSystemWindowInsetsConsumed = systemWindowInsets == null; 640d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets; 650d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell 660d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mWindowDecorInsetsConsumed = windowDecorInsets == null; 670d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets; 680d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell 69973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell mIsRound = isRound; 7050d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 7150d7bfd8224f9da170dac668888bcf0831373051Adam Powell 7250d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 7350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Construct a new WindowInsets, copying all values from a source WindowInsets. 7450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 7550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @param src Source to copy insets from 7650d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 7750d7bfd8224f9da170dac668888bcf0831373051Adam Powell public WindowInsets(WindowInsets src) { 7850d7bfd8224f9da170dac668888bcf0831373051Adam Powell mSystemWindowInsets = src.mSystemWindowInsets; 7950d7bfd8224f9da170dac668888bcf0831373051Adam Powell mWindowDecorInsets = src.mWindowDecorInsets; 800d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed; 810d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed; 82973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell mIsRound = src.mIsRound; 8350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 8450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 8550d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** @hide */ 8650d7bfd8224f9da170dac668888bcf0831373051Adam Powell public WindowInsets(Rect systemWindowInsets) { 870d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell this(systemWindowInsets, null); 8850d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 8950d7bfd8224f9da170dac668888bcf0831373051Adam Powell 9050d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 9150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Used to provide a safe copy of the system window insets to pass through 9250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * to the existing fitSystemWindows method and other similar internals. 9350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @hide 9450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 9550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public Rect getSystemWindowInsets() { 9650d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (mTempRect == null) { 9750d7bfd8224f9da170dac668888bcf0831373051Adam Powell mTempRect = new Rect(); 9850d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 9950d7bfd8224f9da170dac668888bcf0831373051Adam Powell mTempRect.set(mSystemWindowInsets); 10050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mTempRect; 10150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 10250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 10350d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 10450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the left system window inset in pixels. 10550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 10650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 10750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 10850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 10950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 11050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The left system window inset 11150d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 11250d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetLeft() { 11350d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.left; 11450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 11550d7bfd8224f9da170dac668888bcf0831373051Adam Powell 11650d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 11750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the top system window inset in pixels. 11850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 11950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 12050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 12150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 12250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 12350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The top system window inset 12450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 12550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetTop() { 12650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.top; 12750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 12850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 12950d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 13050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the right system window inset in pixels. 13150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 13250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 13350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 13450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 13550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 13650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The right system window inset 13750d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 13850d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetRight() { 13950d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.right; 14050d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 14150d7bfd8224f9da170dac668888bcf0831373051Adam Powell 14250d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 14350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the bottom system window inset in pixels. 14450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 14550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 14650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 14750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 14850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 14950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The bottom system window inset 15050d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 15150d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetBottom() { 15250d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.bottom; 15350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 15450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 15550d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 15650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the left window decor inset in pixels. 15750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 15850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 15950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 16050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 16150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 16250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The left window decor inset 163f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 16450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 16550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetLeft() { 16650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.left; 16750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 16850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 16950d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 17050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the top window decor inset in pixels. 17150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 17250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 17350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 17450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 17550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 17650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The top window decor inset 177f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 17850d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 17950d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetTop() { 18050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.top; 18150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 18250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 18350d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 18450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the right window decor inset in pixels. 18550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 18650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 18750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 18850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 18950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 19050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The right window decor inset 191f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 19250d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 19350d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetRight() { 19450d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.right; 19550d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 19650d7bfd8224f9da170dac668888bcf0831373051Adam Powell 19750d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 19850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the bottom window decor inset in pixels. 19950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 20050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 20150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 20250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 20350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 20450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The bottom window decor inset 205f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 20650d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 20750d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetBottom() { 20850d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.bottom; 20950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 21050d7bfd8224f9da170dac668888bcf0831373051Adam Powell 21150d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 21250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has nonzero system window insets. 21350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 21450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 21550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 21650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 21750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 21850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any of the system window inset values are nonzero 21950d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 22050d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasSystemWindowInsets() { 22150d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 || 22250d7bfd8224f9da170dac668888bcf0831373051Adam Powell mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0; 22350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 22450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 22550d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 22650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has nonzero window decor insets. 22750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 22850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 22950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 23050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 23150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 23250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any of the window decor inset values are nonzero 233f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 23450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 23550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasWindowDecorInsets() { 23650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 || 23750d7bfd8224f9da170dac668888bcf0831373051Adam Powell mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0; 23850d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 23950d7bfd8224f9da170dac668888bcf0831373051Adam Powell 24050d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 24150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has any nonzero insets. 24250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 24350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any inset values are nonzero 24450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 24550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasInsets() { 24650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return hasSystemWindowInsets() || hasWindowDecorInsets(); 24750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 24850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 249973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell /** 2500d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * Check if these insets have been fully consumed. 2510d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2520d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * <p>Insets are considered "consumed" if the applicable <code>consume*</code> methods 2530d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * have been called such that all insets have been set to zero. This affects propagation of 2540d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * insets through the view hierarchy; insets that have not been fully consumed will continue 2550d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * to propagate down to child views.</p> 2560d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2570d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * <p>The result of this method is equivalent to the return value of 2580d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * {@link View#fitSystemWindows(android.graphics.Rect)}.</p> 2590d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2600d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * @return true if the insets have been fully consumed. 2610d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * @hide Pending API 2620d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell */ 2630d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell public boolean isConsumed() { 2640d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed; 2650d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell } 2660d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell 2670d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell /** 268973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * Returns true if the associated window has a round shape. 269973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * 270973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * <p>A round window's left, top, right and bottom edges reach all the way to the 271973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * associated edges of the window but the corners may not be visible. Views responding 272973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * to round insets should take care to not lay out critical elements within the corners 273973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * where they may not be accessible.</p> 274973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * 275973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * @return True if the window is round 276973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell */ 277973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell public boolean isRound() { 278973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell return mIsRound; 279973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell } 280973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell 281f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 282f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with the system window insets fully consumed. 283f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 284f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 285f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 286f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeSystemWindowInsets() { 28750d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 2880d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsets = EMPTY_RECT; 2890d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsetsConsumed = true; 29050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 29150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 29250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 293f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 294f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with selected system window insets fully consumed. 295f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 296f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param left true to consume the left system window inset 297f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param top true to consume the top system window inset 298f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param right true to consume the right system window inset 299f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param bottom true to consume the bottom system window inset 300f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 301f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 302f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 303f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeSystemWindowInsets(boolean left, boolean top, 30450d7bfd8224f9da170dac668888bcf0831373051Adam Powell boolean right, boolean bottom) { 30550d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (left || top || right || bottom) { 30650d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 3070d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsets = new Rect( 3080d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell left ? 0 : mSystemWindowInsets.left, 30950d7bfd8224f9da170dac668888bcf0831373051Adam Powell top ? 0 : mSystemWindowInsets.top, 31050d7bfd8224f9da170dac668888bcf0831373051Adam Powell right ? 0 : mSystemWindowInsets.right, 31150d7bfd8224f9da170dac668888bcf0831373051Adam Powell bottom ? 0 : mSystemWindowInsets.bottom); 3120d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsetsConsumed = !hasSystemWindowInsets(); 31350d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 31450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 31550d7bfd8224f9da170dac668888bcf0831373051Adam Powell return this; 31650d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 31750d7bfd8224f9da170dac668888bcf0831373051Adam Powell 318f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 319f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with selected system window insets replaced 320f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * with new values. 321f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 322f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param left New left inset in pixels 323f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param top New top inset in pixels 324f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param right New right inset in pixels 325f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param bottom New bottom inset in pixels 326f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 327f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 328f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets replaceSystemWindowInsets(int left, int top, 329f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell int right, int bottom) { 33050d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 33150d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mSystemWindowInsets = new Rect(left, top, right, bottom); 3320d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsetsConsumed = !hasSystemWindowInsets(); 33350d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 33450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 33550d7bfd8224f9da170dac668888bcf0831373051Adam Powell 336f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 337f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 338f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 339f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeWindowDecorInsets() { 34050d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 34150d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets.set(0, 0, 0, 0); 3420d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mWindowDecorInsetsConsumed = true; 34350d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 34450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 34550d7bfd8224f9da170dac668888bcf0831373051Adam Powell 346f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 347f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 348f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 349f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeWindowDecorInsets(boolean left, boolean top, 35050d7bfd8224f9da170dac668888bcf0831373051Adam Powell boolean right, boolean bottom) { 35150d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (left || top || right || bottom) { 35250d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 35350d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left, 35450d7bfd8224f9da170dac668888bcf0831373051Adam Powell top ? 0 : mWindowDecorInsets.top, 35550d7bfd8224f9da170dac668888bcf0831373051Adam Powell right ? 0 : mWindowDecorInsets.right, 35650d7bfd8224f9da170dac668888bcf0831373051Adam Powell bottom ? 0 : mWindowDecorInsets.bottom); 3570d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mWindowDecorInsetsConsumed = !hasWindowDecorInsets(); 35850d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 35950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 36050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return this; 36150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 36250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 363f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 364f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 365f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 366f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) { 36750d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 36850d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets = new Rect(left, top, right, bottom); 3690d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mWindowDecorInsetsConsumed = !hasWindowDecorInsets(); 37050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 37150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 37250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 37350d7bfd8224f9da170dac668888bcf0831373051Adam Powell @Override 37450d7bfd8224f9da170dac668888bcf0831373051Adam Powell public String toString() { 37550d7bfd8224f9da170dac668888bcf0831373051Adam Powell return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + " windowDecorInsets=" + 376973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell mWindowDecorInsets + (isRound() ? "round}" : "}"); 37750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 37850d7bfd8224f9da170dac668888bcf0831373051Adam Powell} 379