blob: e5cbe96b9173665e836d83492cf6bf28f3090074 [file] [log] [blame]
Adam Powell50d7bfd2014-02-03 10:16:49 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package android.view;
19
Adrian Roosd07bafd2017-12-11 17:30:56 +010020import android.annotation.Nullable;
Adam Powell50d7bfd2014-02-03 10:16:49 -080021import android.graphics.Rect;
22
23/**
24 * Describes a set of insets for window content.
25 *
26 * <p>WindowInsets are immutable and may be expanded to include more inset types in the future.
27 * To adjust insets, use one of the supplied clone methods to obtain a new WindowInsets instance
28 * with the adjusted properties.</p>
29 *
30 * @see View.OnApplyWindowInsetsListener
31 * @see View#onApplyWindowInsets(WindowInsets)
32 */
Adam Powellf4a39412014-05-05 17:29:17 -070033public final class WindowInsets {
Adrian Roosfa104232014-06-20 16:10:14 -070034
Adam Powell50d7bfd2014-02-03 10:16:49 -080035 private Rect mSystemWindowInsets;
36 private Rect mWindowDecorInsets;
Adrian Roosfa104232014-06-20 16:10:14 -070037 private Rect mStableInsets;
Adam Powell50d7bfd2014-02-03 10:16:49 -080038 private Rect mTempRect;
Adam Powell973ddaa2014-04-15 17:38:54 -070039 private boolean mIsRound;
Adrian Roosd4970af2017-11-10 15:48:01 +010040 private DisplayCutout mDisplayCutout;
Adam Powell50d7bfd2014-02-03 10:16:49 -080041
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -080042 /**
43 * In multi-window we force show the navigation bar. Because we don't want that the surface size
44 * changes in this mode, we instead have a flag whether the navigation bar size should always
45 * be consumed, so the app is treated like there is no virtual navigation bar at all.
46 */
47 private boolean mAlwaysConsumeNavBar;
48
Adam Powell0d9fdba2014-06-11 15:33:08 -070049 private boolean mSystemWindowInsetsConsumed = false;
50 private boolean mWindowDecorInsetsConsumed = false;
Adrian Roosfa104232014-06-20 16:10:14 -070051 private boolean mStableInsetsConsumed = false;
Adrian Roosd07bafd2017-12-11 17:30:56 +010052 private boolean mDisplayCutoutConsumed = false;
Adam Powell0d9fdba2014-06-11 15:33:08 -070053
Adam Powell50d7bfd2014-02-03 10:16:49 -080054 private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0);
55
56 /**
57 * Since new insets may be added in the future that existing apps couldn't
58 * know about, this fully empty constant shouldn't be made available to apps
59 * since it would allow them to inadvertently consume unknown insets by returning it.
60 * @hide
61 */
Adam Powell720924b2014-06-12 14:51:10 -070062 public static final WindowInsets CONSUMED;
63
64 static {
Adrian Roosd4970af2017-11-10 15:48:01 +010065 CONSUMED = new WindowInsets(null, null, null, false, false, null);
Adam Powell720924b2014-06-12 14:51:10 -070066 }
Adam Powell50d7bfd2014-02-03 10:16:49 -080067
68 /** @hide */
Adrian Roosfa104232014-06-20 16:10:14 -070069 public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, Rect stableInsets,
Adrian Roosd4970af2017-11-10 15:48:01 +010070 boolean isRound, boolean alwaysConsumeNavBar, DisplayCutout displayCutout) {
Adam Powell0d9fdba2014-06-11 15:33:08 -070071 mSystemWindowInsetsConsumed = systemWindowInsets == null;
72 mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets;
73
74 mWindowDecorInsetsConsumed = windowDecorInsets == null;
75 mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets;
76
Adrian Roosfa104232014-06-20 16:10:14 -070077 mStableInsetsConsumed = stableInsets == null;
78 mStableInsets = mStableInsetsConsumed ? EMPTY_RECT : stableInsets;
79
Adam Powell973ddaa2014-04-15 17:38:54 -070080 mIsRound = isRound;
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -080081 mAlwaysConsumeNavBar = alwaysConsumeNavBar;
Adrian Roosd4970af2017-11-10 15:48:01 +010082
Adrian Roosd07bafd2017-12-11 17:30:56 +010083 mDisplayCutoutConsumed = displayCutout == null;
84 mDisplayCutout = (mDisplayCutoutConsumed || displayCutout.isEmpty())
85 ? null : displayCutout;
Adam Powell50d7bfd2014-02-03 10:16:49 -080086 }
87
88 /**
89 * Construct a new WindowInsets, copying all values from a source WindowInsets.
90 *
91 * @param src Source to copy insets from
92 */
93 public WindowInsets(WindowInsets src) {
94 mSystemWindowInsets = src.mSystemWindowInsets;
95 mWindowDecorInsets = src.mWindowDecorInsets;
Adrian Roosfa104232014-06-20 16:10:14 -070096 mStableInsets = src.mStableInsets;
Adam Powell0d9fdba2014-06-11 15:33:08 -070097 mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed;
98 mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed;
Adrian Roosfa104232014-06-20 16:10:14 -070099 mStableInsetsConsumed = src.mStableInsetsConsumed;
Adam Powell973ddaa2014-04-15 17:38:54 -0700100 mIsRound = src.mIsRound;
Jorim Jaggie5638a62016-03-25 22:57:01 -0700101 mAlwaysConsumeNavBar = src.mAlwaysConsumeNavBar;
Adrian Roosd4970af2017-11-10 15:48:01 +0100102 mDisplayCutout = src.mDisplayCutout;
Adrian Roosd07bafd2017-12-11 17:30:56 +0100103 mDisplayCutoutConsumed = src.mDisplayCutoutConsumed;
Adam Powell50d7bfd2014-02-03 10:16:49 -0800104 }
105
106 /** @hide */
107 public WindowInsets(Rect systemWindowInsets) {
Adrian Roosd4970af2017-11-10 15:48:01 +0100108 this(systemWindowInsets, null, null, false, false, null);
Adam Powell50d7bfd2014-02-03 10:16:49 -0800109 }
110
111 /**
112 * Used to provide a safe copy of the system window insets to pass through
113 * to the existing fitSystemWindows method and other similar internals.
114 * @hide
115 */
116 public Rect getSystemWindowInsets() {
117 if (mTempRect == null) {
118 mTempRect = new Rect();
119 }
Justin Koheba87822014-06-06 12:13:16 -0700120 if (mSystemWindowInsets != null) {
121 mTempRect.set(mSystemWindowInsets);
122 } else {
123 // If there were no system window insets, this is just empty.
124 mTempRect.setEmpty();
125 }
Adam Powell50d7bfd2014-02-03 10:16:49 -0800126 return mTempRect;
127 }
128
129 /**
130 * Returns the left system window inset in pixels.
131 *
132 * <p>The system window inset represents the area of a full-screen window that is
133 * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
134 * </p>
135 *
136 * @return The left system window inset
137 */
138 public int getSystemWindowInsetLeft() {
139 return mSystemWindowInsets.left;
140 }
141
142 /**
143 * Returns the top system window inset in pixels.
144 *
145 * <p>The system window inset represents the area of a full-screen window that is
146 * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
147 * </p>
148 *
149 * @return The top system window inset
150 */
151 public int getSystemWindowInsetTop() {
152 return mSystemWindowInsets.top;
153 }
154
155 /**
156 * Returns the right system window inset in pixels.
157 *
158 * <p>The system window inset represents the area of a full-screen window that is
159 * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
160 * </p>
161 *
162 * @return The right system window inset
163 */
164 public int getSystemWindowInsetRight() {
165 return mSystemWindowInsets.right;
166 }
167
168 /**
169 * Returns the bottom system window inset in pixels.
170 *
171 * <p>The system window inset represents the area of a full-screen window that is
172 * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
173 * </p>
174 *
175 * @return The bottom system window inset
176 */
177 public int getSystemWindowInsetBottom() {
178 return mSystemWindowInsets.bottom;
179 }
180
181 /**
182 * Returns the left window decor inset in pixels.
183 *
184 * <p>The window decor inset represents the area of the window content area that is
185 * partially or fully obscured by decorations within the window provided by the framework.
186 * This can include action bars, title bars, toolbars, etc.</p>
187 *
188 * @return The left window decor inset
Adam Powellf4a39412014-05-05 17:29:17 -0700189 * @hide pending API
Adam Powell50d7bfd2014-02-03 10:16:49 -0800190 */
191 public int getWindowDecorInsetLeft() {
192 return mWindowDecorInsets.left;
193 }
194
195 /**
196 * Returns the top window decor inset in pixels.
197 *
198 * <p>The window decor inset represents the area of the window content area that is
199 * partially or fully obscured by decorations within the window provided by the framework.
200 * This can include action bars, title bars, toolbars, etc.</p>
201 *
202 * @return The top window decor inset
Adam Powellf4a39412014-05-05 17:29:17 -0700203 * @hide pending API
Adam Powell50d7bfd2014-02-03 10:16:49 -0800204 */
205 public int getWindowDecorInsetTop() {
206 return mWindowDecorInsets.top;
207 }
208
209 /**
210 * Returns the right window decor inset in pixels.
211 *
212 * <p>The window decor inset represents the area of the window content area that is
213 * partially or fully obscured by decorations within the window provided by the framework.
214 * This can include action bars, title bars, toolbars, etc.</p>
215 *
216 * @return The right window decor inset
Adam Powellf4a39412014-05-05 17:29:17 -0700217 * @hide pending API
Adam Powell50d7bfd2014-02-03 10:16:49 -0800218 */
219 public int getWindowDecorInsetRight() {
220 return mWindowDecorInsets.right;
221 }
222
223 /**
224 * Returns the bottom window decor inset in pixels.
225 *
226 * <p>The window decor inset represents the area of the window content area that is
227 * partially or fully obscured by decorations within the window provided by the framework.
228 * This can include action bars, title bars, toolbars, etc.</p>
229 *
230 * @return The bottom window decor inset
Adam Powellf4a39412014-05-05 17:29:17 -0700231 * @hide pending API
Adam Powell50d7bfd2014-02-03 10:16:49 -0800232 */
233 public int getWindowDecorInsetBottom() {
234 return mWindowDecorInsets.bottom;
235 }
236
237 /**
238 * Returns true if this WindowInsets has nonzero system window insets.
239 *
240 * <p>The system window inset represents the area of a full-screen window that is
241 * partially or fully obscured by the status bar, navigation bar, IME or other system windows.
242 * </p>
243 *
244 * @return true if any of the system window inset values are nonzero
245 */
246 public boolean hasSystemWindowInsets() {
247 return mSystemWindowInsets.left != 0 || mSystemWindowInsets.top != 0 ||
248 mSystemWindowInsets.right != 0 || mSystemWindowInsets.bottom != 0;
249 }
250
251 /**
252 * Returns true if this WindowInsets has nonzero window decor insets.
253 *
254 * <p>The window decor inset represents the area of the window content area that is
255 * partially or fully obscured by decorations within the window provided by the framework.
256 * This can include action bars, title bars, toolbars, etc.</p>
257 *
258 * @return true if any of the window decor inset values are nonzero
Adam Powellf4a39412014-05-05 17:29:17 -0700259 * @hide pending API
Adam Powell50d7bfd2014-02-03 10:16:49 -0800260 */
261 public boolean hasWindowDecorInsets() {
262 return mWindowDecorInsets.left != 0 || mWindowDecorInsets.top != 0 ||
263 mWindowDecorInsets.right != 0 || mWindowDecorInsets.bottom != 0;
264 }
265
266 /**
267 * Returns true if this WindowInsets has any nonzero insets.
268 *
269 * @return true if any inset values are nonzero
270 */
271 public boolean hasInsets() {
Adrian Roosd4970af2017-11-10 15:48:01 +0100272 return hasSystemWindowInsets() || hasWindowDecorInsets() || hasStableInsets()
Adrian Roosd07bafd2017-12-11 17:30:56 +0100273 || mDisplayCutout != null;
Adam Powell50d7bfd2014-02-03 10:16:49 -0800274 }
275
Adam Powell973ddaa2014-04-15 17:38:54 -0700276 /**
Adrian Roosd07bafd2017-12-11 17:30:56 +0100277 * Returns the display cutout if there is one.
278 *
279 * @return the display cutout or null if there is none
Adrian Roosd4970af2017-11-10 15:48:01 +0100280 * @see DisplayCutout
Adrian Roosd4970af2017-11-10 15:48:01 +0100281 */
Adrian Roosd07bafd2017-12-11 17:30:56 +0100282 @Nullable
Adrian Roosd4970af2017-11-10 15:48:01 +0100283 public DisplayCutout getDisplayCutout() {
284 return mDisplayCutout;
285 }
286
287 /**
288 * Returns a copy of this WindowInsets with the cutout fully consumed.
289 *
290 * @return A modified copy of this WindowInsets
Adrian Roosd4970af2017-11-10 15:48:01 +0100291 */
Adrian Roosd07bafd2017-12-11 17:30:56 +0100292 public WindowInsets consumeDisplayCutout() {
Adrian Roosd4970af2017-11-10 15:48:01 +0100293 final WindowInsets result = new WindowInsets(this);
Adrian Roosd07bafd2017-12-11 17:30:56 +0100294 result.mDisplayCutout = null;
295 result.mDisplayCutoutConsumed = true;
Adrian Roosd4970af2017-11-10 15:48:01 +0100296 return result;
297 }
298
299
300 /**
Adam Powell0d9fdba2014-06-11 15:33:08 -0700301 * Check if these insets have been fully consumed.
302 *
303 * <p>Insets are considered "consumed" if the applicable <code>consume*</code> methods
304 * have been called such that all insets have been set to zero. This affects propagation of
305 * insets through the view hierarchy; insets that have not been fully consumed will continue
306 * to propagate down to child views.</p>
307 *
308 * <p>The result of this method is equivalent to the return value of
309 * {@link View#fitSystemWindows(android.graphics.Rect)}.</p>
310 *
311 * @return true if the insets have been fully consumed.
Adam Powell0d9fdba2014-06-11 15:33:08 -0700312 */
313 public boolean isConsumed() {
Adrian Roosd4970af2017-11-10 15:48:01 +0100314 return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed && mStableInsetsConsumed
Adrian Roosd07bafd2017-12-11 17:30:56 +0100315 && mDisplayCutoutConsumed;
Adam Powell0d9fdba2014-06-11 15:33:08 -0700316 }
317
318 /**
Adam Powell973ddaa2014-04-15 17:38:54 -0700319 * Returns true if the associated window has a round shape.
320 *
321 * <p>A round window's left, top, right and bottom edges reach all the way to the
322 * associated edges of the window but the corners may not be visible. Views responding
323 * to round insets should take care to not lay out critical elements within the corners
324 * where they may not be accessible.</p>
325 *
326 * @return True if the window is round
327 */
328 public boolean isRound() {
329 return mIsRound;
330 }
331
Adam Powellf4a39412014-05-05 17:29:17 -0700332 /**
333 * Returns a copy of this WindowInsets with the system window insets fully consumed.
334 *
335 * @return A modified copy of this WindowInsets
336 */
337 public WindowInsets consumeSystemWindowInsets() {
Adam Powell50d7bfd2014-02-03 10:16:49 -0800338 final WindowInsets result = new WindowInsets(this);
Adam Powell0d9fdba2014-06-11 15:33:08 -0700339 result.mSystemWindowInsets = EMPTY_RECT;
340 result.mSystemWindowInsetsConsumed = true;
Adam Powell50d7bfd2014-02-03 10:16:49 -0800341 return result;
342 }
343
Adam Powellf4a39412014-05-05 17:29:17 -0700344 /**
345 * Returns a copy of this WindowInsets with selected system window insets fully consumed.
346 *
347 * @param left true to consume the left system window inset
348 * @param top true to consume the top system window inset
349 * @param right true to consume the right system window inset
350 * @param bottom true to consume the bottom system window inset
351 * @return A modified copy of this WindowInsets
352 * @hide pending API
353 */
354 public WindowInsets consumeSystemWindowInsets(boolean left, boolean top,
Adam Powell50d7bfd2014-02-03 10:16:49 -0800355 boolean right, boolean bottom) {
356 if (left || top || right || bottom) {
357 final WindowInsets result = new WindowInsets(this);
Adam Powell0d9fdba2014-06-11 15:33:08 -0700358 result.mSystemWindowInsets = new Rect(
359 left ? 0 : mSystemWindowInsets.left,
Adam Powell50d7bfd2014-02-03 10:16:49 -0800360 top ? 0 : mSystemWindowInsets.top,
361 right ? 0 : mSystemWindowInsets.right,
362 bottom ? 0 : mSystemWindowInsets.bottom);
363 return result;
364 }
365 return this;
366 }
367
Adam Powellf4a39412014-05-05 17:29:17 -0700368 /**
369 * Returns a copy of this WindowInsets with selected system window insets replaced
370 * with new values.
371 *
372 * @param left New left inset in pixels
373 * @param top New top inset in pixels
374 * @param right New right inset in pixels
375 * @param bottom New bottom inset in pixels
376 * @return A modified copy of this WindowInsets
377 */
378 public WindowInsets replaceSystemWindowInsets(int left, int top,
379 int right, int bottom) {
Adam Powell50d7bfd2014-02-03 10:16:49 -0800380 final WindowInsets result = new WindowInsets(this);
381 result.mSystemWindowInsets = new Rect(left, top, right, bottom);
382 return result;
383 }
384
Adam Powellf4a39412014-05-05 17:29:17 -0700385 /**
Adam Powelld72068b2014-09-12 14:42:25 -0700386 * Returns a copy of this WindowInsets with selected system window insets replaced
387 * with new values.
388 *
389 * @param systemWindowInsets New system window insets. Each field is the inset in pixels
390 * for that edge
391 * @return A modified copy of this WindowInsets
392 */
393 public WindowInsets replaceSystemWindowInsets(Rect systemWindowInsets) {
394 final WindowInsets result = new WindowInsets(this);
395 result.mSystemWindowInsets = new Rect(systemWindowInsets);
Adam Powelld72068b2014-09-12 14:42:25 -0700396 return result;
397 }
398
399 /**
Adam Powellf4a39412014-05-05 17:29:17 -0700400 * @hide
401 */
402 public WindowInsets consumeWindowDecorInsets() {
Adam Powell50d7bfd2014-02-03 10:16:49 -0800403 final WindowInsets result = new WindowInsets(this);
404 result.mWindowDecorInsets.set(0, 0, 0, 0);
Adam Powell0d9fdba2014-06-11 15:33:08 -0700405 result.mWindowDecorInsetsConsumed = true;
Adam Powell50d7bfd2014-02-03 10:16:49 -0800406 return result;
407 }
408
Adam Powellf4a39412014-05-05 17:29:17 -0700409 /**
410 * @hide
411 */
412 public WindowInsets consumeWindowDecorInsets(boolean left, boolean top,
Adam Powell50d7bfd2014-02-03 10:16:49 -0800413 boolean right, boolean bottom) {
414 if (left || top || right || bottom) {
415 final WindowInsets result = new WindowInsets(this);
416 result.mWindowDecorInsets = new Rect(left ? 0 : mWindowDecorInsets.left,
417 top ? 0 : mWindowDecorInsets.top,
418 right ? 0 : mWindowDecorInsets.right,
419 bottom ? 0 : mWindowDecorInsets.bottom);
420 return result;
421 }
422 return this;
423 }
424
Adam Powellf4a39412014-05-05 17:29:17 -0700425 /**
426 * @hide
427 */
428 public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) {
Adam Powell50d7bfd2014-02-03 10:16:49 -0800429 final WindowInsets result = new WindowInsets(this);
430 result.mWindowDecorInsets = new Rect(left, top, right, bottom);
431 return result;
432 }
433
Adrian Roosfa104232014-06-20 16:10:14 -0700434 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700435 * Returns the top stable inset in pixels.
436 *
437 * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
438 * partially or fully obscured by the system UI elements. This value does not change
439 * based on the visibility state of those elements; for example, if the status bar is
440 * normally shown, but temporarily hidden, the stable inset will still provide the inset
441 * associated with the status bar being shown.</p>
442 *
443 * @return The top stable inset
Adrian Roosfa104232014-06-20 16:10:14 -0700444 */
445 public int getStableInsetTop() {
446 return mStableInsets.top;
447 }
448
449 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700450 * Returns the left stable inset in pixels.
451 *
452 * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
453 * partially or fully obscured by the system UI elements. This value does not change
454 * based on the visibility state of those elements; for example, if the status bar is
455 * normally shown, but temporarily hidden, the stable inset will still provide the inset
456 * associated with the status bar being shown.</p>
457 *
458 * @return The left stable inset
Adrian Roosfa104232014-06-20 16:10:14 -0700459 */
460 public int getStableInsetLeft() {
461 return mStableInsets.left;
462 }
463
464 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700465 * Returns the right stable inset in pixels.
466 *
467 * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
468 * partially or fully obscured by the system UI elements. This value does not change
469 * based on the visibility state of those elements; for example, if the status bar is
470 * normally shown, but temporarily hidden, the stable inset will still provide the inset
471 * associated with the status bar being shown.</p>
472 *
473 * @return The right stable inset
Adrian Roosfa104232014-06-20 16:10:14 -0700474 */
475 public int getStableInsetRight() {
476 return mStableInsets.right;
477 }
478
479 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700480 * Returns the bottom stable inset in pixels.
481 *
482 * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
483 * partially or fully obscured by the system UI elements. This value does not change
484 * based on the visibility state of those elements; for example, if the status bar is
485 * normally shown, but temporarily hidden, the stable inset will still provide the inset
486 * associated with the status bar being shown.</p>
487 *
488 * @return The bottom stable inset
Adrian Roosfa104232014-06-20 16:10:14 -0700489 */
490 public int getStableInsetBottom() {
491 return mStableInsets.bottom;
492 }
493
494 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700495 * Returns true if this WindowInsets has nonzero stable insets.
496 *
497 * <p>The stable inset represents the area of a full-screen window that <b>may</b> be
498 * partially or fully obscured by the system UI elements. This value does not change
499 * based on the visibility state of those elements; for example, if the status bar is
500 * normally shown, but temporarily hidden, the stable inset will still provide the inset
501 * associated with the status bar being shown.</p>
502 *
503 * @return true if any of the stable inset values are nonzero
Adrian Roosfa104232014-06-20 16:10:14 -0700504 */
505 public boolean hasStableInsets() {
506 return mStableInsets.top != 0 || mStableInsets.left != 0 || mStableInsets.right != 0
507 || mStableInsets.bottom != 0;
508 }
509
510 /**
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700511 * Returns a copy of this WindowInsets with the stable insets fully consumed.
512 *
513 * @return A modified copy of this WindowInsets
Adrian Roosfa104232014-06-20 16:10:14 -0700514 */
515 public WindowInsets consumeStableInsets() {
516 final WindowInsets result = new WindowInsets(this);
517 result.mStableInsets = EMPTY_RECT;
518 result.mStableInsetsConsumed = true;
519 return result;
520 }
521
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -0800522 /**
523 * @hide
524 */
525 public boolean shouldAlwaysConsumeNavBar() {
526 return mAlwaysConsumeNavBar;
527 }
528
Adam Powell50d7bfd2014-02-03 10:16:49 -0800529 @Override
530 public String toString() {
Adrian Roosfa104232014-06-20 16:10:14 -0700531 return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets
532 + " windowDecorInsets=" + mWindowDecorInsets
Adrian Roosd4970af2017-11-10 15:48:01 +0100533 + " stableInsets=" + mStableInsets
Adrian Roosd07bafd2017-12-11 17:30:56 +0100534 + (mDisplayCutout != null ? " cutout=" + mDisplayCutout : "")
Adrian Roosd4970af2017-11-10 15:48:01 +0100535 + (isRound() ? " round" : "")
536 + "}";
Adam Powell50d7bfd2014-02-03 10:16:49 -0800537 }
538}