WindowInsets.java revision 0ffd49cbe0ab4c13fd5528abacade898a8cff481
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; 9450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 9550d7bfd8224f9da170dac668888bcf0831373051Adam Powell 9650d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** @hide */ 9750d7bfd8224f9da170dac668888bcf0831373051Adam Powell public WindowInsets(Rect systemWindowInsets) { 980ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi this(systemWindowInsets, null, null, false, false); 9950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 10050d7bfd8224f9da170dac668888bcf0831373051Adam Powell 10150d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 10250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Used to provide a safe copy of the system window insets to pass through 10350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * to the existing fitSystemWindows method and other similar internals. 10450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @hide 10550d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 10650d7bfd8224f9da170dac668888bcf0831373051Adam Powell public Rect getSystemWindowInsets() { 10750d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (mTempRect == null) { 10850d7bfd8224f9da170dac668888bcf0831373051Adam Powell mTempRect = new Rect(); 10950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 110eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh if (mSystemWindowInsets != null) { 111eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh mTempRect.set(mSystemWindowInsets); 112eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh } else { 113eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh // If there were no system window insets, this is just empty. 114eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh mTempRect.setEmpty(); 115eba8782a1f8412a3510fc78a71b843ef6e89bdbbJustin Koh } 11650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mTempRect; 11750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 11850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 11950d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 12050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the left system window inset in pixels. 12150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 12250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 12350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 12450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 12550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 12650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The left system window inset 12750d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 12850d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetLeft() { 12950d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.left; 13050d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 13150d7bfd8224f9da170dac668888bcf0831373051Adam Powell 13250d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 13350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the top system window inset in pixels. 13450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 13550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 13650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 13750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 13850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 13950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The top system window inset 14050d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 14150d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetTop() { 14250d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.top; 14350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 14450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 14550d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 14650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the right system window inset in pixels. 14750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 14850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 14950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 15050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 15150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 15250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The right system window inset 15350d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 15450d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetRight() { 15550d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.right; 15650d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 15750d7bfd8224f9da170dac668888bcf0831373051Adam Powell 15850d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 15950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the bottom system window inset in pixels. 16050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 16150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 16250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 16350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 16450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 16550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The bottom system window inset 16650d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 16750d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getSystemWindowInsetBottom() { 16850d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.bottom; 16950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 17050d7bfd8224f9da170dac668888bcf0831373051Adam Powell 17150d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 17250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the left window decor inset in pixels. 17350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 17450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 17550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 17650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 17750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 17850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The left window decor inset 179f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 18050d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 18150d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetLeft() { 18250d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.left; 18350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 18450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 18550d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 18650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the top window decor inset in pixels. 18750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 18850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 18950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 19050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 19150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 19250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The top window decor inset 193f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 19450d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 19550d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetTop() { 19650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.top; 19750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 19850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 19950d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 20050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the right window decor inset in pixels. 20150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 20250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 20350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 20450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 20550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 20650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The right window decor inset 207f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 20850d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 20950d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetRight() { 21050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.right; 21150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 21250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 21350d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 21450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns the bottom window decor inset in pixels. 21550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 21650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 21750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 21850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 21950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 22050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return The bottom window decor inset 221f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 22250d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 22350d7bfd8224f9da170dac668888bcf0831373051Adam Powell public int getWindowDecorInsetBottom() { 22450d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.bottom; 22550d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 22650d7bfd8224f9da170dac668888bcf0831373051Adam Powell 22750d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 22850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has nonzero system window insets. 22950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 23050d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The system window inset represents the area of a full-screen window that is 23150d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by the status bar, navigation bar, IME or other system windows. 23250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * </p> 23350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 23450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any of the system window inset values are nonzero 23550d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 23650d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasSystemWindowInsets() { 23750d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 || 23850d7bfd8224f9da170dac668888bcf0831373051Adam Powell mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0; 23950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 24050d7bfd8224f9da170dac668888bcf0831373051Adam Powell 24150d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 24250d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has nonzero window decor insets. 24350d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 24450d7bfd8224f9da170dac668888bcf0831373051Adam Powell * <p>The window decor inset represents the area of the window content area that is 24550d7bfd8224f9da170dac668888bcf0831373051Adam Powell * partially or fully obscured by decorations within the window provided by the framework. 24650d7bfd8224f9da170dac668888bcf0831373051Adam Powell * This can include action bars, title bars, toolbars, etc.</p> 24750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 24850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any of the window decor inset values are nonzero 249f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 25050d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 25150d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasWindowDecorInsets() { 25250d7bfd8224f9da170dac668888bcf0831373051Adam Powell return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 || 25350d7bfd8224f9da170dac668888bcf0831373051Adam Powell mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0; 25450d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 25550d7bfd8224f9da170dac668888bcf0831373051Adam Powell 25650d7bfd8224f9da170dac668888bcf0831373051Adam Powell /** 25750d7bfd8224f9da170dac668888bcf0831373051Adam Powell * Returns true if this WindowInsets has any nonzero insets. 25850d7bfd8224f9da170dac668888bcf0831373051Adam Powell * 25950d7bfd8224f9da170dac668888bcf0831373051Adam Powell * @return true if any inset values are nonzero 26050d7bfd8224f9da170dac668888bcf0831373051Adam Powell */ 26150d7bfd8224f9da170dac668888bcf0831373051Adam Powell public boolean hasInsets() { 26205e967820dc71286b743294af0e80e2939ff9738Adam Powell return hasSystemWindowInsets() || hasWindowDecorInsets() || hasStableInsets(); 26350d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 26450d7bfd8224f9da170dac668888bcf0831373051Adam Powell 265973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell /** 2660d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * Check if these insets have been fully consumed. 2670d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2680d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * <p>Insets are considered "consumed" if the applicable <code>consume*</code> methods 2690d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * have been called such that all insets have been set to zero. This affects propagation of 2700d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * insets through the view hierarchy; insets that have not been fully consumed will continue 2710d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * to propagate down to child views.</p> 2720d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2730d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * <p>The result of this method is equivalent to the return value of 2740d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * {@link View#fitSystemWindows(android.graphics.Rect)}.</p> 2750d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * 2760d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell * @return true if the insets have been fully consumed. 2770d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell */ 2780d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell public boolean isConsumed() { 279fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed && mStableInsetsConsumed; 2800d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell } 2810d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell 2820d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell /** 283973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * Returns true if the associated window has a round shape. 284973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * 285973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * <p>A round window's left, top, right and bottom edges reach all the way to the 286973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * associated edges of the window but the corners may not be visible. Views responding 287973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * to round insets should take care to not lay out critical elements within the corners 288973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * where they may not be accessible.</p> 289973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * 290973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell * @return True if the window is round 291973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell */ 292973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell public boolean isRound() { 293973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell return mIsRound; 294973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell } 295973ddaacaef255b8659d35cfe4151dd5b7436138Adam Powell 296f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 297f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with the system window insets fully consumed. 298f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 299f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 300f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 301f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeSystemWindowInsets() { 30250d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 3030d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsets = EMPTY_RECT; 3040d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsetsConsumed = true; 30550d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 30650d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 30750d7bfd8224f9da170dac668888bcf0831373051Adam Powell 308f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 309f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with selected system window insets fully consumed. 310f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 311f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param left true to consume the left system window inset 312f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param top true to consume the top system window inset 313f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param right true to consume the right system window inset 314f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param bottom true to consume the bottom system window inset 315f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 316f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide pending API 317f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 318f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeSystemWindowInsets(boolean left, boolean top, 31950d7bfd8224f9da170dac668888bcf0831373051Adam Powell boolean right, boolean bottom) { 32050d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (left || top || right || bottom) { 32150d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 3220d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mSystemWindowInsets = new Rect( 3230d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell left ? 0 : mSystemWindowInsets.left, 32450d7bfd8224f9da170dac668888bcf0831373051Adam Powell top ? 0 : mSystemWindowInsets.top, 32550d7bfd8224f9da170dac668888bcf0831373051Adam Powell right ? 0 : mSystemWindowInsets.right, 32650d7bfd8224f9da170dac668888bcf0831373051Adam Powell bottom ? 0 : mSystemWindowInsets.bottom); 32750d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 32850d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 32950d7bfd8224f9da170dac668888bcf0831373051Adam Powell return this; 33050d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 33150d7bfd8224f9da170dac668888bcf0831373051Adam Powell 332f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 333f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * Returns a copy of this WindowInsets with selected system window insets replaced 334f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * with new values. 335f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * 336f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param left New left inset in pixels 337f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param top New top inset in pixels 338f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param right New right inset in pixels 339f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @param bottom New bottom inset in pixels 340f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @return A modified copy of this WindowInsets 341f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 342f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets replaceSystemWindowInsets(int left, int top, 343f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell int right, int bottom) { 34450d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 34550d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mSystemWindowInsets = new Rect(left, top, right, bottom); 34650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 34750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 34850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 349f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 350d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * Returns a copy of this WindowInsets with selected system window insets replaced 351d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * with new values. 352d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * 353d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * @param systemWindowInsets New system window insets. Each field is the inset in pixels 354d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * for that edge 355d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell * @return A modified copy of this WindowInsets 356d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell */ 357d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell public WindowInsets replaceSystemWindowInsets(Rect systemWindowInsets) { 358d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell final WindowInsets result = new WindowInsets(this); 359d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell result.mSystemWindowInsets = new Rect(systemWindowInsets); 360d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell return result; 361d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell } 362d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell 363d72068b38ec4e5732dde6093e39b2602babc27a3Adam Powell /** 364f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 365f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 366f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeWindowDecorInsets() { 36750d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 36850d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets.set(0, 0, 0, 0); 3690d9fdbad751318b1e9a7a2789bf0e9240252e15fAdam Powell result.mWindowDecorInsetsConsumed = true; 37050d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 37150d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 37250d7bfd8224f9da170dac668888bcf0831373051Adam Powell 373f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 374f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 375f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 376f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets consumeWindowDecorInsets(boolean left, boolean top, 37750d7bfd8224f9da170dac668888bcf0831373051Adam Powell boolean right, boolean bottom) { 37850d7bfd8224f9da170dac668888bcf0831373051Adam Powell if (left || top || right || bottom) { 37950d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 38050d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left, 38150d7bfd8224f9da170dac668888bcf0831373051Adam Powell top ? 0 : mWindowDecorInsets.top, 38250d7bfd8224f9da170dac668888bcf0831373051Adam Powell right ? 0 : mWindowDecorInsets.right, 38350d7bfd8224f9da170dac668888bcf0831373051Adam Powell bottom ? 0 : mWindowDecorInsets.bottom); 38450d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 38550d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 38650d7bfd8224f9da170dac668888bcf0831373051Adam Powell return this; 38750d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 38850d7bfd8224f9da170dac668888bcf0831373051Adam Powell 389f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell /** 390f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell * @hide 391f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell */ 392f4a3941ebe0dab5eeded96059a6a5f7c1d075e64Adam Powell public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) { 39350d7bfd8224f9da170dac668888bcf0831373051Adam Powell final WindowInsets result = new WindowInsets(this); 39450d7bfd8224f9da170dac668888bcf0831373051Adam Powell result.mWindowDecorInsets = new Rect(left, top, right, bottom); 39550d7bfd8224f9da170dac668888bcf0831373051Adam Powell return result; 39650d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 39750d7bfd8224f9da170dac668888bcf0831373051Adam Powell 398fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 399067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns the top stable inset in pixels. 400067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 401067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * <p>The stable inset represents the area of a full-screen window that <b>may</b> be 402067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * partially or fully obscured by the system UI elements. This value does not change 403067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * based on the visibility state of those elements; for example, if the status bar is 404067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * normally shown, but temporarily hidden, the stable inset will still provide the inset 405067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * associated with the status bar being shown.</p> 406067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 407067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return The top stable inset 408fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 409fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public int getStableInsetTop() { 410fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mStableInsets.top; 411fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 412fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 413fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 414067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns the left stable inset in pixels. 415067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 416067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * <p>The stable inset represents the area of a full-screen window that <b>may</b> be 417067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * partially or fully obscured by the system UI elements. This value does not change 418067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * based on the visibility state of those elements; for example, if the status bar is 419067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * normally shown, but temporarily hidden, the stable inset will still provide the inset 420067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * associated with the status bar being shown.</p> 421067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 422067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return The left stable inset 423fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 424fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public int getStableInsetLeft() { 425fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mStableInsets.left; 426fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 427fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 428fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 429067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns the right stable inset in pixels. 430067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 431067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * <p>The stable inset represents the area of a full-screen window that <b>may</b> be 432067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * partially or fully obscured by the system UI elements. This value does not change 433067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * based on the visibility state of those elements; for example, if the status bar is 434067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * normally shown, but temporarily hidden, the stable inset will still provide the inset 435067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * associated with the status bar being shown.</p> 436067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 437067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return The right stable inset 438fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 439fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public int getStableInsetRight() { 440fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mStableInsets.right; 441fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 442fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 443fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 444067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns the bottom stable inset in pixels. 445067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 446067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * <p>The stable inset represents the area of a full-screen window that <b>may</b> be 447067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * partially or fully obscured by the system UI elements. This value does not change 448067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * based on the visibility state of those elements; for example, if the status bar is 449067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * normally shown, but temporarily hidden, the stable inset will still provide the inset 450067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * associated with the status bar being shown.</p> 451067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 452067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return The bottom stable inset 453fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 454fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public int getStableInsetBottom() { 455fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mStableInsets.bottom; 456fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 457fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 458fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 459067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns true if this WindowInsets has nonzero stable insets. 460067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 461067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * <p>The stable inset represents the area of a full-screen window that <b>may</b> be 462067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * partially or fully obscured by the system UI elements. This value does not change 463067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * based on the visibility state of those elements; for example, if the status bar is 464067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * normally shown, but temporarily hidden, the stable inset will still provide the inset 465067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * associated with the status bar being shown.</p> 466067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 467067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return true if any of the stable inset values are nonzero 468fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 469fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public boolean hasStableInsets() { 470fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return mStableInsets.top != 0 || mStableInsets.left != 0 || mStableInsets.right != 0 471fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos || mStableInsets.bottom != 0; 472fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 473fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 474fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos /** 475067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * Returns a copy of this WindowInsets with the stable insets fully consumed. 476067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * 477067e5f68b9216b233df1c6529db182ff9b2887abDianne Hackborn * @return A modified copy of this WindowInsets 478fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos */ 479fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos public WindowInsets consumeStableInsets() { 480fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos final WindowInsets result = new WindowInsets(this); 481fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos result.mStableInsets = EMPTY_RECT; 482fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos result.mStableInsetsConsumed = true; 483fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return result; 484fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos } 485fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos 4860ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi /** 4870ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi * @hide 4880ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi */ 4890ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi public boolean shouldAlwaysConsumeNavBar() { 4900ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi return mAlwaysConsumeNavBar; 4910ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi } 4920ffd49cbe0ab4c13fd5528abacade898a8cff481Jorim Jaggi 49350d7bfd8224f9da170dac668888bcf0831373051Adam Powell @Override 49450d7bfd8224f9da170dac668888bcf0831373051Adam Powell public String toString() { 495fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets 496fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos + " windowDecorInsets=" + mWindowDecorInsets 497fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos + " stableInsets=" + mStableInsets + 498fa10423fa00f3495e451016acba9b6848eb995c9Adrian Roos (isRound() ? " round}" : "}"); 49950d7bfd8224f9da170dac668888bcf0831373051Adam Powell } 50050d7bfd8224f9da170dac668888bcf0831373051Adam Powell} 501