summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2022-01-26 21:37:16 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-01-26 21:37:16 +0000
commitdaeb827056c8f0b3816be76fd6c0589e4f79ff76 (patch)
treee820b86af860b73f625c68b2e2b067653a94584f
parent1338b7e74b15fc1536f7b9f0e02db391e2dd1c1d (diff)
parent4dd61edf092a761b98ff8891253a82507bb5a9b7 (diff)
Merge "Factor out to NavigationBarController#scheduleRelayout()"
-rw-r--r--core/java/android/inputmethodservice/NavigationBarController.java64
1 files changed, 40 insertions, 24 deletions
diff --git a/core/java/android/inputmethodservice/NavigationBarController.java b/core/java/android/inputmethodservice/NavigationBarController.java
index 7bc95731d627..a6e475aeb813 100644
--- a/core/java/android/inputmethodservice/NavigationBarController.java
+++ b/core/java/android/inputmethodservice/NavigationBarController.java
@@ -266,34 +266,50 @@ final class NavigationBarController {
}
final boolean insetChanged = !Objects.equals(systemInsets, mLastInsets);
if (zOrderChanged || insetChanged) {
- final NavigationBarFrame that = mNavigationBarFrame;
- that.post(() -> {
- if (!that.isAttachedToWindow()) {
- return;
- }
- final Insets currentSystemInsets = getSystemInsets();
- if (!Objects.equals(currentSystemInsets, mLastInsets)) {
- that.setLayoutParams(
- new FrameLayout.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT,
- currentSystemInsets.bottom, Gravity.BOTTOM));
- mLastInsets = currentSystemInsets;
- }
- if (decor instanceof ViewGroup) {
- ViewGroup decorGroup = (ViewGroup) decor;
- final View navbarBackgroundView =
- window.getNavigationBarBackgroundView();
- if (navbarBackgroundView != null
- && decorGroup.indexOfChild(navbarBackgroundView)
- > decorGroup.indexOfChild(that)) {
- decorGroup.bringChildToFront(that);
- }
- }
- });
+ scheduleRelayout();
}
}
}
+ private void scheduleRelayout() {
+ // Capture the current frame object in case the object is replaced or cleared later.
+ final NavigationBarFrame frame = mNavigationBarFrame;
+ frame.post(() -> {
+ if (mDestroyed) {
+ return;
+ }
+ if (!frame.isAttachedToWindow()) {
+ return;
+ }
+ final Window window = mService.mWindow.getWindow();
+ if (window == null) {
+ return;
+ }
+ final View decor = window.peekDecorView();
+ if (decor == null) {
+ return;
+ }
+ if (!(decor instanceof ViewGroup)) {
+ return;
+ }
+ final ViewGroup decorGroup = (ViewGroup) decor;
+ final Insets currentSystemInsets = getSystemInsets();
+ if (!Objects.equals(currentSystemInsets, mLastInsets)) {
+ frame.setLayoutParams(new FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ currentSystemInsets.bottom, Gravity.BOTTOM));
+ mLastInsets = currentSystemInsets;
+ }
+ final View navbarBackgroundView =
+ window.getNavigationBarBackgroundView();
+ if (navbarBackgroundView != null
+ && decorGroup.indexOfChild(navbarBackgroundView)
+ > decorGroup.indexOfChild(frame)) {
+ decorGroup.bringChildToFront(frame);
+ }
+ });
+ }
+
private boolean isGesturalNavigationEnabled() {
final Resources resources = mService.getResources();
if (resources == null) {