| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package android.view; |
| 19 |
|
| 20 |
import static android.view.Surface.ROTATION_0; |
| 21 |
import static android.view.WindowInsets.Type.DISPLAY_CUTOUT; |
| 22 |
import static android.view.WindowInsets.Type.FIRST; |
| 23 |
import static android.view.WindowInsets.Type.IME; |
| 24 |
import static android.view.WindowInsets.Type.LAST; |
| 25 |
import static android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES; |
| 26 |
import static android.view.WindowInsets.Type.NAVIGATION_BARS; |
| 27 |
import static android.view.WindowInsets.Type.SIZE; |
| 28 |
import static android.view.WindowInsets.Type.STATUS_BARS; |
| 29 |
import static android.view.WindowInsets.Type.SYSTEM_GESTURES; |
| 30 |
import static android.view.WindowInsets.Type.TAPPABLE_ELEMENT; |
| 31 |
import static android.view.WindowInsets.Type.all; |
| 32 |
import static android.view.WindowInsets.Type.ime; |
| 33 |
import static android.view.WindowInsets.Type.indexOf; |
| 34 |
import static android.view.WindowInsets.Type.systemBars; |
| 35 |
|
| 36 |
import android.annotation.IntDef; |
| 37 |
import android.annotation.IntRange; |
| 38 |
import android.annotation.NonNull; |
| 39 |
import android.annotation.Nullable; |
| 40 |
import android.compat.annotation.UnsupportedAppUsage; |
| 41 |
import android.content.Intent; |
| 42 |
import android.graphics.Insets; |
| 43 |
import android.graphics.Rect; |
| 44 |
import android.util.SparseArray; |
| 45 |
import android.view.View.OnApplyWindowInsetsListener; |
| 46 |
import android.view.WindowInsets.Type.InsetsType; |
| 47 |
import android.view.inputmethod.EditorInfo; |
| 48 |
import android.view.inputmethod.InputMethod; |
| 49 |
|
| 50 |
import com.android.internal.annotations.VisibleForTesting; |
| 51 |
import com.android.internal.util.Preconditions; |
| 52 |
|
| 53 |
import java.lang.annotation.Retention; |
| 54 |
import java.lang.annotation.RetentionPolicy; |
| 55 |
import java.util.Arrays; |
| 56 |
import java.util.Objects; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public final class WindowInsets { |
| 75 |
|
| 76 |
private final Insets[] mTypeInsetsMap; |
| 77 |
private final Insets[] mTypeMaxInsetsMap; |
| 78 |
private final boolean[] mTypeVisibilityMap; |
| 79 |
|
| 80 |
@Nullable private Rect mTempRect; |
| 81 |
private final boolean mIsRound; |
| 82 |
@Nullable private final DisplayCutout mDisplayCutout; |
| 83 |
@Nullable private final RoundedCorners mRoundedCorners; |
| 84 |
@Nullable private final PrivacyIndicatorBounds mPrivacyIndicatorBounds; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
private final boolean mAlwaysConsumeSystemBars; |
| 92 |
|
| 93 |
private final boolean mSystemWindowInsetsConsumed; |
| 94 |
private final boolean mStableInsetsConsumed; |
| 95 |
private final boolean mDisplayCutoutConsumed; |
| 96 |
|
| 97 |
private final int mCompatInsetsTypes; |
| 98 |
private final boolean mCompatIgnoreVisibility; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public static final @NonNull WindowInsets CONSUMED; |
| 115 |
|
| 116 |
static { |
| 117 |
CONSUMED = new WindowInsets((Rect) null, null, false, false, null); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
@Deprecated |
| 129 |
public WindowInsets(Rect systemWindowInsetsRect, Rect stableInsetsRect, boolean isRound, |
| 130 |
boolean alwaysConsumeSystemBars, DisplayCutout displayCutout) { |
| 131 |
this(createCompatTypeMap(systemWindowInsetsRect), createCompatTypeMap(stableInsetsRect), |
| 132 |
createCompatVisibilityMap(createCompatTypeMap(systemWindowInsetsRect)), |
| 133 |
isRound, alwaysConsumeSystemBars, displayCutout, null, null, |
| 134 |
systemBars(), false ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public WindowInsets(@Nullable Insets[] typeInsetsMap, |
| 150 |
@Nullable Insets[] typeMaxInsetsMap, |
| 151 |
boolean[] typeVisibilityMap, |
| 152 |
boolean isRound, |
| 153 |
boolean alwaysConsumeSystemBars, DisplayCutout displayCutout, |
| 154 |
RoundedCorners roundedCorners, |
| 155 |
PrivacyIndicatorBounds privacyIndicatorBounds, |
| 156 |
@InsetsType int compatInsetsTypes, boolean compatIgnoreVisibility) { |
| 157 |
mSystemWindowInsetsConsumed = typeInsetsMap == null; |
| 158 |
mTypeInsetsMap = mSystemWindowInsetsConsumed |
| 159 |
? new Insets[SIZE] |
| 160 |
: typeInsetsMap.clone(); |
| 161 |
|
| 162 |
mStableInsetsConsumed = typeMaxInsetsMap == null; |
| 163 |
mTypeMaxInsetsMap = mStableInsetsConsumed |
| 164 |
? new Insets[SIZE] |
| 165 |
: typeMaxInsetsMap.clone(); |
| 166 |
|
| 167 |
mTypeVisibilityMap = typeVisibilityMap; |
| 168 |
mIsRound = isRound; |
| 169 |
mAlwaysConsumeSystemBars = alwaysConsumeSystemBars; |
| 170 |
mCompatInsetsTypes = compatInsetsTypes; |
| 171 |
mCompatIgnoreVisibility = compatIgnoreVisibility; |
| 172 |
|
| 173 |
mDisplayCutoutConsumed = displayCutout == null; |
| 174 |
mDisplayCutout = (mDisplayCutoutConsumed || displayCutout.isEmpty()) |
| 175 |
? null : displayCutout; |
| 176 |
|
| 177 |
mRoundedCorners = roundedCorners; |
| 178 |
mPrivacyIndicatorBounds = privacyIndicatorBounds; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public WindowInsets(WindowInsets src) { |
| 187 |
this(src.mSystemWindowInsetsConsumed ? null : src.mTypeInsetsMap, |
| 188 |
src.mStableInsetsConsumed ? null : src.mTypeMaxInsetsMap, |
| 189 |
src.mTypeVisibilityMap, src.mIsRound, |
| 190 |
src.mAlwaysConsumeSystemBars, displayCutoutCopyConstructorArgument(src), |
| 191 |
src.mRoundedCorners, |
| 192 |
src.mPrivacyIndicatorBounds, |
| 193 |
src.mCompatInsetsTypes, |
| 194 |
src.mCompatIgnoreVisibility); |
| 195 |
} |
| 196 |
|
| 197 |
private static DisplayCutout displayCutoutCopyConstructorArgument(WindowInsets w) { |
| 198 |
if (w.mDisplayCutoutConsumed) { |
| 199 |
return null; |
| 200 |
} else if (w.mDisplayCutout == null) { |
| 201 |
return DisplayCutout.NO_CUTOUT; |
| 202 |
} else { |
| 203 |
return w.mDisplayCutout; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
static Insets getInsets(Insets[] typeInsetsMap, @InsetsType int typeMask) { |
| 212 |
Insets result = null; |
| 213 |
for (int i = FIRST; i <= LAST; i = i << 1) { |
| 214 |
if ((typeMask & i) == 0) { |
| 215 |
continue; |
| 216 |
} |
| 217 |
Insets insets = typeInsetsMap[indexOf(i)]; |
| 218 |
if (insets == null) { |
| 219 |
continue; |
| 220 |
} |
| 221 |
if (result == null) { |
| 222 |
result = insets; |
| 223 |
} else { |
| 224 |
result = Insets.max(result, insets); |
| 225 |
} |
| 226 |
} |
| 227 |
return result == null ? Insets.NONE : result; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
private static void setInsets(Insets[] typeInsetsMap, @InsetsType int typeMask, Insets insets) { |
| 234 |
for (int i = FIRST; i <= LAST; i = i << 1) { |
| 235 |
if ((typeMask & i) == 0) { |
| 236 |
continue; |
| 237 |
} |
| 238 |
typeInsetsMap[indexOf(i)] = insets; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
@UnsupportedAppUsage |
| 244 |
public WindowInsets(Rect systemWindowInsets) { |
| 245 |
this(createCompatTypeMap(systemWindowInsets), null, new boolean[SIZE], false, false, null, |
| 246 |
null, null, systemBars(), false ); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
private static Insets[] createCompatTypeMap(@Nullable Rect insets) { |
| 255 |
if (insets == null) { |
| 256 |
return null; |
| 257 |
} |
| 258 |
Insets[] typeInsetsMap = new Insets[SIZE]; |
| 259 |
assignCompatInsets(typeInsetsMap, insets); |
| 260 |
return typeInsetsMap; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
@VisibleForTesting |
| 267 |
public static void assignCompatInsets(Insets[] typeInsetsMap, Rect insets) { |
| 268 |
typeInsetsMap[indexOf(STATUS_BARS)] = Insets.of(0, insets.top, 0, 0); |
| 269 |
typeInsetsMap[indexOf(NAVIGATION_BARS)] = |
| 270 |
Insets.of(insets.left, 0, insets.right, insets.bottom); |
| 271 |
} |
| 272 |
|
| 273 |
private static boolean[] createCompatVisibilityMap(@Nullable Insets[] typeInsetsMap) { |
| 274 |
boolean[] typeVisibilityMap = new boolean[SIZE]; |
| 275 |
if (typeInsetsMap == null) { |
| 276 |
return typeVisibilityMap; |
| 277 |
} |
| 278 |
for (int i = FIRST; i <= LAST; i = i << 1) { |
| 279 |
int index = indexOf(i); |
| 280 |
if (!Insets.NONE.equals(typeInsetsMap[index])) { |
| 281 |
typeVisibilityMap[index] = true; |
| 282 |
} |
| 283 |
} |
| 284 |
return typeVisibilityMap; |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
@Deprecated |
| 295 |
@NonNull |
| 296 |
public Rect getSystemWindowInsetsAsRect() { |
| 297 |
if (mTempRect == null) { |
| 298 |
mTempRect = new Rect(); |
| 299 |
} |
| 300 |
Insets insets = getSystemWindowInsets(); |
| 301 |
mTempRect.set(insets.left, insets.top, insets.right, insets.bottom); |
| 302 |
return mTempRect; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
@Deprecated |
| 317 |
@NonNull |
| 318 |
public Insets getSystemWindowInsets() { |
| 319 |
Insets result = mCompatIgnoreVisibility |
| 320 |
? getInsetsIgnoringVisibility(mCompatInsetsTypes & ~ime()) |
| 321 |
: getInsets(mCompatInsetsTypes); |
| 322 |
|
| 323 |
|
| 324 |
if ((mCompatInsetsTypes & ime()) != 0 && mCompatIgnoreVisibility) { |
| 325 |
result = Insets.max(result, getInsets(ime())); |
| 326 |
} |
| 327 |
return result; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
@NonNull |
| 338 |
public Insets getInsets(@InsetsType int typeMask) { |
| 339 |
return getInsets(mTypeInsetsMap, typeMask); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
@NonNull |
| 362 |
public Insets getInsetsIgnoringVisibility(@InsetsType int typeMask) { |
| 363 |
if ((typeMask & IME) != 0) { |
| 364 |
throw new IllegalArgumentException("Unable to query the maximum insets for IME"); |
| 365 |
} |
| 366 |
return getInsets(mTypeMaxInsetsMap, typeMask); |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public boolean isVisible(@InsetsType int typeMask) { |
| 378 |
for (int i = FIRST; i <= LAST; i = i << 1) { |
| 379 |
if ((typeMask & i) == 0) { |
| 380 |
continue; |
| 381 |
} |
| 382 |
if (!mTypeVisibilityMap[indexOf(i)]) { |
| 383 |
return false; |
| 384 |
} |
| 385 |
} |
| 386 |
return true; |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
@Deprecated |
| 401 |
public int getSystemWindowInsetLeft() { |
| 402 |
return getSystemWindowInsets().left; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
@Deprecated |
| 417 |
public int getSystemWindowInsetTop() { |
| 418 |
return getSystemWindowInsets().top; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
@Deprecated |
| 433 |
public int getSystemWindowInsetRight() { |
| 434 |
return getSystemWindowInsets().right; |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
@Deprecated |
| 449 |
public int getSystemWindowInsetBottom() { |
| 450 |
return getSystemWindowInsets().bottom; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
@Deprecated |
| 465 |
public boolean hasSystemWindowInsets() { |
| 466 |
return !getSystemWindowInsets().equals(Insets.NONE); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
public boolean hasInsets() { |
| 475 |
return !getInsets(mTypeInsetsMap, all()).equals(Insets.NONE) |
| 476 |
|| !getInsets(mTypeMaxInsetsMap, all()).equals(Insets.NONE) |
| 477 |
|| mDisplayCutout != null || mRoundedCorners != null; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
@Nullable |
| 493 |
public DisplayCutout getDisplayCutout() { |
| 494 |
return mDisplayCutout; |
| 495 |
} |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
@Nullable |
| 510 |
public RoundedCorner getRoundedCorner(@RoundedCorner.Position int position) { |
| 511 |
return mRoundedCorners == null ? null : mRoundedCorners.getRoundedCorner(position); |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
public @Nullable Rect getPrivacyIndicatorBounds() { |
| 530 |
return mPrivacyIndicatorBounds == null ? null |
| 531 |
: mPrivacyIndicatorBounds.getStaticPrivacyIndicatorBounds(); |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
@Deprecated |
| 543 |
@NonNull |
| 544 |
public WindowInsets consumeDisplayCutout() { |
| 545 |
return new WindowInsets(mSystemWindowInsetsConsumed ? null : mTypeInsetsMap, |
| 546 |
mStableInsetsConsumed ? null : mTypeMaxInsetsMap, |
| 547 |
mTypeVisibilityMap, |
| 548 |
mIsRound, mAlwaysConsumeSystemBars, |
| 549 |
null , mRoundedCorners, mPrivacyIndicatorBounds, |
| 550 |
mCompatInsetsTypes, mCompatIgnoreVisibility); |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
public boolean isConsumed() { |
| 568 |
return mSystemWindowInsetsConsumed && mStableInsetsConsumed |
| 569 |
&& mDisplayCutoutConsumed; |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
public boolean isRound() { |
| 583 |
return mIsRound; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
@Deprecated |
| 595 |
@NonNull |
| 596 |
public WindowInsets consumeSystemWindowInsets() { |
| 597 |
return new WindowInsets(null, null, |
| 598 |
mTypeVisibilityMap, |
| 599 |
mIsRound, mAlwaysConsumeSystemBars, |
| 600 |
displayCutoutCopyConstructorArgument(this), |
| 601 |
mRoundedCorners, mPrivacyIndicatorBounds, mCompatInsetsTypes, |
| 602 |
mCompatIgnoreVisibility); |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
@Deprecated |
| 624 |
@NonNull |
| 625 |
public WindowInsets replaceSystemWindowInsets(int left, int top, int right, int bottom) { |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
if (mSystemWindowInsetsConsumed) { |
| 631 |
return this; |
| 632 |
} |
| 633 |
return new Builder(this).setSystemWindowInsets(Insets.of(left, top, right, bottom)).build(); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
@Deprecated |
| 653 |
@NonNull |
| 654 |
public WindowInsets replaceSystemWindowInsets(Rect systemWindowInsets) { |
| 655 |
return replaceSystemWindowInsets(systemWindowInsets.left, systemWindowInsets.top, |
| 656 |
systemWindowInsets.right, systemWindowInsets.bottom); |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
@Deprecated |
| 673 |
@NonNull |
| 674 |
public Insets getStableInsets() { |
| 675 |
return getInsets(mTypeMaxInsetsMap, systemBars()); |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
@Deprecated |
| 692 |
public int getStableInsetTop() { |
| 693 |
return getStableInsets().top; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
@Deprecated |
| 710 |
public int getStableInsetLeft() { |
| 711 |
return getStableInsets().left; |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
@Deprecated |
| 728 |
public int getStableInsetRight() { |
| 729 |
return getStableInsets().right; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
@Deprecated |
| 746 |
public int getStableInsetBottom() { |
| 747 |
return getStableInsets().bottom; |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
@Deprecated |
| 764 |
public boolean hasStableInsets() { |
| 765 |
return !getStableInsets().equals(Insets.NONE); |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
@Deprecated |
| 802 |
@NonNull |
| 803 |
public Insets getSystemGestureInsets() { |
| 804 |
return getInsets(mTypeInsetsMap, SYSTEM_GESTURES); |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
@Deprecated |
| 832 |
@NonNull |
| 833 |
public Insets getMandatorySystemGestureInsets() { |
| 834 |
return getInsets(mTypeInsetsMap, MANDATORY_SYSTEM_GESTURES); |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
@Deprecated |
| 861 |
@NonNull |
| 862 |
public Insets getTappableElementInsets() { |
| 863 |
return getInsets(mTypeInsetsMap, TAPPABLE_ELEMENT); |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
@Deprecated |
| 876 |
@NonNull |
| 877 |
public WindowInsets consumeStableInsets() { |
| 878 |
return this; |
| 879 |
} |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
public boolean shouldAlwaysConsumeSystemBars() { |
| 885 |
return mAlwaysConsumeSystemBars; |
| 886 |
} |
| 887 |
|
| 888 |
@Override |
| 889 |
public String toString() { |
| 890 |
StringBuilder result = new StringBuilder("WindowInsets{\n "); |
| 891 |
for (int i = 0; i < SIZE; i++) { |
| 892 |
Insets insets = mTypeInsetsMap[i]; |
| 893 |
Insets maxInsets = mTypeMaxInsetsMap[i]; |
| 894 |
boolean visible = mTypeVisibilityMap[i]; |
| 895 |
if (!Insets.NONE.equals(insets) || !Insets.NONE.equals(maxInsets) || visible) { |
| 896 |
result.append(Type.toString(1 << i)).append("=").append(insets) |
| 897 |
.append(" max=").append(maxInsets) |
| 898 |
.append(" vis=").append(visible) |
| 899 |
.append("\n "); |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
result.append(mDisplayCutout != null ? "cutout=" + mDisplayCutout : ""); |
| 904 |
result.append("\n "); |
| 905 |
result.append(mRoundedCorners != null ? "roundedCorners=" + mRoundedCorners : ""); |
| 906 |
result.append("\n "); |
| 907 |
result.append(mPrivacyIndicatorBounds != null ? "privacyIndicatorBounds=" |
| 908 |
+ mPrivacyIndicatorBounds : ""); |
| 909 |
result.append("\n "); |
| 910 |
result.append("compatInsetsTypes=" + mCompatInsetsTypes); |
| 911 |
result.append("\n "); |
| 912 |
result.append("compatIgnoreVisibility=" + mCompatIgnoreVisibility); |
| 913 |
result.append("\n "); |
| 914 |
result.append("systemWindowInsetsConsumed=" + mSystemWindowInsetsConsumed); |
| 915 |
result.append("\n "); |
| 916 |
result.append("stableInsetsConsumed=" + mStableInsetsConsumed); |
| 917 |
result.append("\n "); |
| 918 |
result.append("displayCutoutConsumed=" + mDisplayCutoutConsumed); |
| 919 |
result.append("\n "); |
| 920 |
result.append(isRound() ? "round" : ""); |
| 921 |
result.append("}"); |
| 922 |
return result.toString(); |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
@Deprecated |
| 933 |
@NonNull |
| 934 |
public WindowInsets inset(Rect r) { |
| 935 |
return inset(r.left, r.top, r.right, r.bottom); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
@NonNull |
| 954 |
public WindowInsets inset(@NonNull Insets insets) { |
| 955 |
Objects.requireNonNull(insets); |
| 956 |
return inset(insets.left, insets.top, insets.right, insets.bottom); |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
@NonNull |
| 981 |
public WindowInsets inset(@IntRange(from = 0) int left, @IntRange(from = 0) int top, |
| 982 |
@IntRange(from = 0) int right, @IntRange(from = 0) int bottom) { |
| 983 |
Preconditions.checkArgumentNonnegative(left); |
| 984 |
Preconditions.checkArgumentNonnegative(top); |
| 985 |
Preconditions.checkArgumentNonnegative(right); |
| 986 |
Preconditions.checkArgumentNonnegative(bottom); |
| 987 |
|
| 988 |
return insetUnchecked(left, top, right, bottom); |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
@NonNull |
| 996 |
public WindowInsets insetUnchecked(int left, int top, int right, int bottom) { |
| 997 |
return new WindowInsets( |
| 998 |
mSystemWindowInsetsConsumed |
| 999 |
? null |
| 1000 |
: insetInsets(mTypeInsetsMap, left, top, right, bottom), |
| 1001 |
mStableInsetsConsumed |
| 1002 |
? null |
| 1003 |
: insetInsets(mTypeMaxInsetsMap, left, top, right, bottom), |
| 1004 |
mTypeVisibilityMap, |
| 1005 |
mIsRound, mAlwaysConsumeSystemBars, |
| 1006 |
mDisplayCutoutConsumed |
| 1007 |
? null |
| 1008 |
: mDisplayCutout == null |
| 1009 |
? DisplayCutout.NO_CUTOUT |
| 1010 |
: mDisplayCutout.inset(left, top, right, bottom), |
| 1011 |
mRoundedCorners == null |
| 1012 |
? RoundedCorners.NO_ROUNDED_CORNERS |
| 1013 |
: mRoundedCorners.inset(left, top, right, bottom), |
| 1014 |
mPrivacyIndicatorBounds == null |
| 1015 |
? null |
| 1016 |
: mPrivacyIndicatorBounds.inset(left, top, right, bottom), |
| 1017 |
mCompatInsetsTypes, mCompatIgnoreVisibility); |
| 1018 |
} |
| 1019 |
|
| 1020 |
@Override |
| 1021 |
public boolean equals(@Nullable Object o) { |
| 1022 |
if (this == o) return true; |
| 1023 |
if (o == null || !(o instanceof WindowInsets)) return false; |
| 1024 |
WindowInsets that = (WindowInsets) o; |
| 1025 |
|
| 1026 |
return mIsRound == that.mIsRound |
| 1027 |
&& mAlwaysConsumeSystemBars == that.mAlwaysConsumeSystemBars |
| 1028 |
&& mSystemWindowInsetsConsumed == that.mSystemWindowInsetsConsumed |
| 1029 |
&& mStableInsetsConsumed == that.mStableInsetsConsumed |
| 1030 |
&& mDisplayCutoutConsumed == that.mDisplayCutoutConsumed |
| 1031 |
&& Arrays.equals(mTypeInsetsMap, that.mTypeInsetsMap) |
| 1032 |
&& Arrays.equals(mTypeMaxInsetsMap, that.mTypeMaxInsetsMap) |
| 1033 |
&& Arrays.equals(mTypeVisibilityMap, that.mTypeVisibilityMap) |
| 1034 |
&& Objects.equals(mDisplayCutout, that.mDisplayCutout) |
| 1035 |
&& Objects.equals(mRoundedCorners, that.mRoundedCorners) |
| 1036 |
&& Objects.equals(mPrivacyIndicatorBounds, that.mPrivacyIndicatorBounds); |
| 1037 |
} |
| 1038 |
|
| 1039 |
@Override |
| 1040 |
public int hashCode() { |
| 1041 |
return Objects.hash(Arrays.hashCode(mTypeInsetsMap), Arrays.hashCode(mTypeMaxInsetsMap), |
| 1042 |
Arrays.hashCode(mTypeVisibilityMap), mIsRound, mDisplayCutout, mRoundedCorners, |
| 1043 |
mAlwaysConsumeSystemBars, mSystemWindowInsetsConsumed, mStableInsetsConsumed, |
| 1044 |
mDisplayCutoutConsumed, mPrivacyIndicatorBounds); |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
private static Insets[] insetInsets( |
| 1055 |
Insets[] typeInsetsMap, int left, int top, int right, int bottom) { |
| 1056 |
boolean cloned = false; |
| 1057 |
for (int i = 0; i < SIZE; i++) { |
| 1058 |
Insets insets = typeInsetsMap[i]; |
| 1059 |
if (insets == null) { |
| 1060 |
continue; |
| 1061 |
} |
| 1062 |
Insets insetInsets = insetInsets(insets, left, top, right, bottom); |
| 1063 |
if (insetInsets != insets) { |
| 1064 |
if (!cloned) { |
| 1065 |
typeInsetsMap = typeInsetsMap.clone(); |
| 1066 |
cloned = true; |
| 1067 |
} |
| 1068 |
typeInsetsMap[i] = insetInsets; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
return typeInsetsMap; |
| 1072 |
} |
| 1073 |
|
| 1074 |
static Insets insetInsets(Insets insets, int left, int top, int right, int bottom) { |
| 1075 |
int newLeft = Math.max(0, insets.left - left); |
| 1076 |
int newTop = Math.max(0, insets.top - top); |
| 1077 |
int newRight = Math.max(0, insets.right - right); |
| 1078 |
int newBottom = Math.max(0, insets.bottom - bottom); |
| 1079 |
if (newLeft == left && newTop == top && newRight == right && newBottom == bottom) { |
| 1080 |
return insets; |
| 1081 |
} |
| 1082 |
return Insets.of(newLeft, newTop, newRight, newBottom); |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
boolean isSystemWindowInsetsConsumed() { |
| 1089 |
return mSystemWindowInsetsConsumed; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
public static final class Builder { |
| 1096 |
|
| 1097 |
private final Insets[] mTypeInsetsMap; |
| 1098 |
private final Insets[] mTypeMaxInsetsMap; |
| 1099 |
private final boolean[] mTypeVisibilityMap; |
| 1100 |
private boolean mSystemInsetsConsumed = true; |
| 1101 |
private boolean mStableInsetsConsumed = true; |
| 1102 |
|
| 1103 |
private DisplayCutout mDisplayCutout; |
| 1104 |
private RoundedCorners mRoundedCorners = RoundedCorners.NO_ROUNDED_CORNERS; |
| 1105 |
|
| 1106 |
private boolean mIsRound; |
| 1107 |
private boolean mAlwaysConsumeSystemBars; |
| 1108 |
|
| 1109 |
private PrivacyIndicatorBounds mPrivacyIndicatorBounds = new PrivacyIndicatorBounds(); |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
public Builder() { |
| 1115 |
mTypeInsetsMap = new Insets[SIZE]; |
| 1116 |
mTypeMaxInsetsMap = new Insets[SIZE]; |
| 1117 |
mTypeVisibilityMap = new boolean[SIZE]; |
| 1118 |
} |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
public Builder(@NonNull WindowInsets insets) { |
| 1126 |
mTypeInsetsMap = insets.mTypeInsetsMap.clone(); |
| 1127 |
mTypeMaxInsetsMap = insets.mTypeMaxInsetsMap.clone(); |
| 1128 |
mTypeVisibilityMap = insets.mTypeVisibilityMap.clone(); |
| 1129 |
mSystemInsetsConsumed = insets.mSystemWindowInsetsConsumed; |
| 1130 |
mStableInsetsConsumed = insets.mStableInsetsConsumed; |
| 1131 |
mDisplayCutout = displayCutoutCopyConstructorArgument(insets); |
| 1132 |
mRoundedCorners = insets.mRoundedCorners; |
| 1133 |
mIsRound = insets.mIsRound; |
| 1134 |
mAlwaysConsumeSystemBars = insets.mAlwaysConsumeSystemBars; |
| 1135 |
mPrivacyIndicatorBounds = insets.mPrivacyIndicatorBounds; |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
@Deprecated |
| 1150 |
@NonNull |
| 1151 |
public Builder setSystemWindowInsets(@NonNull Insets systemWindowInsets) { |
| 1152 |
Preconditions.checkNotNull(systemWindowInsets); |
| 1153 |
assignCompatInsets(mTypeInsetsMap, systemWindowInsets.toRect()); |
| 1154 |
mSystemInsetsConsumed = false; |
| 1155 |
return this; |
| 1156 |
} |
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
@Deprecated |
| 1170 |
@NonNull |
| 1171 |
public Builder setSystemGestureInsets(@NonNull Insets insets) { |
| 1172 |
WindowInsets.setInsets(mTypeInsetsMap, SYSTEM_GESTURES, insets); |
| 1173 |
return this; |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
@Deprecated |
| 1193 |
@NonNull |
| 1194 |
public Builder setMandatorySystemGestureInsets(@NonNull Insets insets) { |
| 1195 |
WindowInsets.setInsets(mTypeInsetsMap, MANDATORY_SYSTEM_GESTURES, insets); |
| 1196 |
return this; |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
@Deprecated |
| 1210 |
@NonNull |
| 1211 |
public Builder setTappableElementInsets(@NonNull Insets insets) { |
| 1212 |
WindowInsets.setInsets(mTypeInsetsMap, TAPPABLE_ELEMENT, insets); |
| 1213 |
return this; |
| 1214 |
} |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
@NonNull |
| 1231 |
public Builder setInsets(@InsetsType int typeMask, @NonNull Insets insets) { |
| 1232 |
Preconditions.checkNotNull(insets); |
| 1233 |
WindowInsets.setInsets(mTypeInsetsMap, typeMask, insets); |
| 1234 |
mSystemInsetsConsumed = false; |
| 1235 |
return this; |
| 1236 |
} |
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
@NonNull |
| 1261 |
public Builder setInsetsIgnoringVisibility(@InsetsType int typeMask, @NonNull Insets insets) |
| 1262 |
throws IllegalArgumentException{ |
| 1263 |
if (typeMask == IME) { |
| 1264 |
throw new IllegalArgumentException("Maximum inset not available for IME"); |
| 1265 |
} |
| 1266 |
Preconditions.checkNotNull(insets); |
| 1267 |
WindowInsets.setInsets(mTypeMaxInsetsMap, typeMask, insets); |
| 1268 |
mStableInsetsConsumed = false; |
| 1269 |
return this; |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
@NonNull |
| 1284 |
public Builder setVisible(@InsetsType int typeMask, boolean visible) { |
| 1285 |
for (int i = FIRST; i <= LAST; i = i << 1) { |
| 1286 |
if ((typeMask & i) == 0) { |
| 1287 |
continue; |
| 1288 |
} |
| 1289 |
mTypeVisibilityMap[indexOf(i)] = visible; |
| 1290 |
} |
| 1291 |
return this; |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
@Deprecated |
| 1309 |
@NonNull |
| 1310 |
public Builder setStableInsets(@NonNull Insets stableInsets) { |
| 1311 |
Preconditions.checkNotNull(stableInsets); |
| 1312 |
assignCompatInsets(mTypeMaxInsetsMap, stableInsets.toRect()); |
| 1313 |
mStableInsetsConsumed = false; |
| 1314 |
return this; |
| 1315 |
} |
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
@NonNull |
| 1325 |
public Builder setDisplayCutout(@Nullable DisplayCutout displayCutout) { |
| 1326 |
mDisplayCutout = displayCutout != null ? displayCutout : DisplayCutout.NO_CUTOUT; |
| 1327 |
if (!mDisplayCutout.isEmpty()) { |
| 1328 |
final Insets safeInsets = Insets.of(mDisplayCutout.getSafeInsets()); |
| 1329 |
final int index = indexOf(DISPLAY_CUTOUT); |
| 1330 |
mTypeInsetsMap[index] = safeInsets; |
| 1331 |
mTypeMaxInsetsMap[index] = safeInsets; |
| 1332 |
mTypeVisibilityMap[index] = true; |
| 1333 |
} |
| 1334 |
return this; |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
@NonNull |
| 1339 |
public Builder setRoundedCorners(RoundedCorners roundedCorners) { |
| 1340 |
mRoundedCorners = roundedCorners != null |
| 1341 |
? roundedCorners : RoundedCorners.NO_ROUNDED_CORNERS; |
| 1342 |
return this; |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
@NonNull |
| 1354 |
public Builder setRoundedCorner(@RoundedCorner.Position int position, |
| 1355 |
@Nullable RoundedCorner roundedCorner) { |
| 1356 |
mRoundedCorners.setRoundedCorner(position, roundedCorner); |
| 1357 |
return this; |
| 1358 |
} |
| 1359 |
|
| 1360 |
|
| 1361 |
@NonNull |
| 1362 |
public Builder setPrivacyIndicatorBounds(@Nullable PrivacyIndicatorBounds bounds) { |
| 1363 |
mPrivacyIndicatorBounds = bounds; |
| 1364 |
return this; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
@NonNull |
| 1373 |
public Builder setPrivacyIndicatorBounds(@Nullable Rect bounds) { |
| 1374 |
|
| 1375 |
Rect[] boundsArr = { bounds, bounds, bounds, bounds }; |
| 1376 |
mPrivacyIndicatorBounds = new PrivacyIndicatorBounds(boundsArr, ROTATION_0); |
| 1377 |
return this; |
| 1378 |
} |
| 1379 |
|
| 1380 |
|
| 1381 |
@NonNull |
| 1382 |
public Builder setRound(boolean round) { |
| 1383 |
mIsRound = round; |
| 1384 |
return this; |
| 1385 |
} |
| 1386 |
|
| 1387 |
|
| 1388 |
@NonNull |
| 1389 |
public Builder setAlwaysConsumeSystemBars(boolean alwaysConsumeSystemBars) { |
| 1390 |
mAlwaysConsumeSystemBars = alwaysConsumeSystemBars; |
| 1391 |
return this; |
| 1392 |
} |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
@NonNull |
| 1400 |
public WindowInsets build() { |
| 1401 |
return new WindowInsets(mSystemInsetsConsumed ? null : mTypeInsetsMap, |
| 1402 |
mStableInsetsConsumed ? null : mTypeMaxInsetsMap, mTypeVisibilityMap, |
| 1403 |
mIsRound, mAlwaysConsumeSystemBars, mDisplayCutout, mRoundedCorners, |
| 1404 |
mPrivacyIndicatorBounds, systemBars(), false ); |
| 1405 |
} |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
public static final class Type { |
| 1412 |
|
| 1413 |
static final int FIRST = 1 << 0; |
| 1414 |
static final int STATUS_BARS = FIRST; |
| 1415 |
static final int NAVIGATION_BARS = 1 << 1; |
| 1416 |
static final int CAPTION_BAR = 1 << 2; |
| 1417 |
|
| 1418 |
static final int IME = 1 << 3; |
| 1419 |
|
| 1420 |
static final int SYSTEM_GESTURES = 1 << 4; |
| 1421 |
static final int MANDATORY_SYSTEM_GESTURES = 1 << 5; |
| 1422 |
static final int TAPPABLE_ELEMENT = 1 << 6; |
| 1423 |
|
| 1424 |
static final int DISPLAY_CUTOUT = 1 << 7; |
| 1425 |
|
| 1426 |
static final int WINDOW_DECOR = 1 << 8; |
| 1427 |
|
| 1428 |
static final int GENERIC_OVERLAYS = 1 << 9; |
| 1429 |
static final int LAST = GENERIC_OVERLAYS; |
| 1430 |
static final int SIZE = 10; |
| 1431 |
|
| 1432 |
static int indexOf(@InsetsType int type) { |
| 1433 |
switch (type) { |
| 1434 |
case STATUS_BARS: |
| 1435 |
return 0; |
| 1436 |
case NAVIGATION_BARS: |
| 1437 |
return 1; |
| 1438 |
case CAPTION_BAR: |
| 1439 |
return 2; |
| 1440 |
case IME: |
| 1441 |
return 3; |
| 1442 |
case SYSTEM_GESTURES: |
| 1443 |
return 4; |
| 1444 |
case MANDATORY_SYSTEM_GESTURES: |
| 1445 |
return 5; |
| 1446 |
case TAPPABLE_ELEMENT: |
| 1447 |
return 6; |
| 1448 |
case DISPLAY_CUTOUT: |
| 1449 |
return 7; |
| 1450 |
case WINDOW_DECOR: |
| 1451 |
return 8; |
| 1452 |
case GENERIC_OVERLAYS: |
| 1453 |
return 9; |
| 1454 |
default: |
| 1455 |
throw new IllegalArgumentException("type needs to be >= FIRST and <= LAST," |
| 1456 |
+ " type=" + type); |
| 1457 |
} |
| 1458 |
} |
| 1459 |
|
| 1460 |
static String toString(@InsetsType int types) { |
| 1461 |
StringBuilder result = new StringBuilder(); |
| 1462 |
if ((types & STATUS_BARS) != 0) { |
| 1463 |
result.append("statusBars |"); |
| 1464 |
} |
| 1465 |
if ((types & NAVIGATION_BARS) != 0) { |
| 1466 |
result.append("navigationBars |"); |
| 1467 |
} |
| 1468 |
if ((types & CAPTION_BAR) != 0) { |
| 1469 |
result.append("captionBar |"); |
| 1470 |
} |
| 1471 |
if ((types & IME) != 0) { |
| 1472 |
result.append("ime |"); |
| 1473 |
} |
| 1474 |
if ((types & SYSTEM_GESTURES) != 0) { |
| 1475 |
result.append("systemGestures |"); |
| 1476 |
} |
| 1477 |
if ((types & MANDATORY_SYSTEM_GESTURES) != 0) { |
| 1478 |
result.append("mandatorySystemGestures |"); |
| 1479 |
} |
| 1480 |
if ((types & TAPPABLE_ELEMENT) != 0) { |
| 1481 |
result.append("tappableElement |"); |
| 1482 |
} |
| 1483 |
if ((types & DISPLAY_CUTOUT) != 0) { |
| 1484 |
result.append("displayCutout |"); |
| 1485 |
} |
| 1486 |
if ((types & WINDOW_DECOR) != 0) { |
| 1487 |
result.append("windowDecor |"); |
| 1488 |
} |
| 1489 |
if ((types & GENERIC_OVERLAYS) != 0) { |
| 1490 |
result.append("genericOverlays |"); |
| 1491 |
} |
| 1492 |
if (result.length() > 0) { |
| 1493 |
result.delete(result.length() - 2, result.length()); |
| 1494 |
} |
| 1495 |
return result.toString(); |
| 1496 |
} |
| 1497 |
|
| 1498 |
private Type() { |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
@Retention(RetentionPolicy.SOURCE) |
| 1503 |
@IntDef(flag = true, value = {STATUS_BARS, NAVIGATION_BARS, CAPTION_BAR, IME, WINDOW_DECOR, |
| 1504 |
SYSTEM_GESTURES, MANDATORY_SYSTEM_GESTURES, TAPPABLE_ELEMENT, DISPLAY_CUTOUT, |
| 1505 |
GENERIC_OVERLAYS}) |
| 1506 |
public @interface InsetsType { |
| 1507 |
} |
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
public static @InsetsType int statusBars() { |
| 1513 |
return STATUS_BARS; |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
public static @InsetsType int navigationBars() { |
| 1520 |
return NAVIGATION_BARS; |
| 1521 |
} |
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
public static @InsetsType int captionBar() { |
| 1527 |
return CAPTION_BAR; |
| 1528 |
} |
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
public static @InsetsType int ime() { |
| 1534 |
return IME; |
| 1535 |
} |
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
public static @InsetsType int systemGestures() { |
| 1555 |
return SYSTEM_GESTURES; |
| 1556 |
} |
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
public static @InsetsType int mandatorySystemGestures() { |
| 1562 |
return MANDATORY_SYSTEM_GESTURES; |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
public static @InsetsType int tappableElement() { |
| 1569 |
return TAPPABLE_ELEMENT; |
| 1570 |
} |
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
public static @InsetsType int displayCutout() { |
| 1589 |
return DISPLAY_CUTOUT; |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
public static @InsetsType int systemBars() { |
| 1597 |
return STATUS_BARS | NAVIGATION_BARS | CAPTION_BAR | GENERIC_OVERLAYS; |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
public static @InsetsType int all() { |
| 1606 |
return 0xFFFFFFFF; |
| 1607 |
} |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
public static final class Side { |
| 1614 |
|
| 1615 |
public static final int LEFT = 1 << 0; |
| 1616 |
public static final int TOP = 1 << 1; |
| 1617 |
public static final int RIGHT = 1 << 2; |
| 1618 |
public static final int BOTTOM = 1 << 3; |
| 1619 |
|
| 1620 |
private Side() { |
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
@Retention(RetentionPolicy.SOURCE) |
| 1625 |
@IntDef(flag = true, value = {LEFT, TOP, RIGHT, BOTTOM}) |
| 1626 |
public @interface InsetsSide {} |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
public static @InsetsSide int all() { |
| 1632 |
return LEFT | TOP | RIGHT | BOTTOM; |
| 1633 |
} |
| 1634 |
} |
| 1635 |
} |