From f5e9b5c305aa98cafd0c24cfdadc5dd32bad8020 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 10 Sep 2014 15:27:41 +0200 Subject: [PATCH] Hide the increased window size due to colored bars from the view hierarchy For windows with L-bars, the window size has been extended to include the area below the nav bar. This change makes DecorView hide that fact from the rest of the view hierarchy, unless it has explicitly ask to extend below the navigation bar. Bug: 17421744 Change-Id: I7bd32531130d199c0734ffcb800194e77b7e16c3 --- .../internal/policy/impl/PhoneWindow.java | 47 +++++++++++++++++-- .../policy/impl/PhoneWindowManager.java | 3 +- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index f39727a88d532..79859fc9efe38 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -149,6 +149,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // mDecor itself, or a child of mDecor where the contents go. private ViewGroup mContentParent; + private ViewGroup mContentRoot; + SurfaceHolder.Callback2 mTakeSurfaceCallback; InputQueue.Callback mTakeInputQueueCallback; @@ -2153,6 +2155,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { private int mLastTopInset = 0; private int mLastBottomInset = 0; + private int mLastRightInset = 0; private int mLastSystemUiVisibility = 0; @@ -2731,7 +2734,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { @Override public WindowInsets onApplyWindowInsets(WindowInsets insets) { mFrameOffsets.set(insets.getSystemWindowInsets()); - updateColorViews(insets); + insets = updateColorViews(insets); insets = updateStatusGuard(insets); updateNavigationGuard(insets); if (getForeground() != null) { @@ -2748,8 +2751,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { private WindowInsets updateColorViews(WindowInsets insets) { if (!mIsFloating && ActivityManager.isHighEndGfx()) { if (insets != null) { - mLastTopInset = insets.getStableInsetTop(); - mLastBottomInset = insets.getStableInsetBottom(); + mLastTopInset = Math.min(insets.getStableInsetTop(), + insets.getSystemWindowInsetTop()); + mLastBottomInset = Math.min(insets.getStableInsetBottom(), + insets.getSystemWindowInsetBottom()); + mLastRightInset = Math.min(insets.getStableInsetRight(), + insets.getSystemWindowInsetRight()); } mStatusColorView = updateColorViewInt(mStatusColorView, SYSTEM_UI_FLAG_FULLSCREEN, FLAG_TRANSLUCENT_STATUS, @@ -2762,8 +2769,39 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME, com.android.internal.R.id.navigationBarBackground); } + + WindowManager.LayoutParams attrs = getAttributes(); + int sysUiVisibility = attrs.systemUiVisibility | attrs.subtreeSystemUiVisibility; + + // When we expand the window with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, we still need + // to ensure that the rest of the view hierarchy doesn't notice it, unless they've + // explicitly asked for it. + + boolean consumingNavBar = + (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 + && (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0 + && (mLastSystemUiVisibility & SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; + + int consumedRight = consumingNavBar ? mLastRightInset : 0; + int consumedBottom = consumingNavBar ? mLastBottomInset : 0; + + if (mContentRoot != null + && mContentRoot.getLayoutParams() instanceof MarginLayoutParams) { + MarginLayoutParams lp = (MarginLayoutParams) mContentRoot.getLayoutParams(); + if (lp.rightMargin != consumedRight || lp.bottomMargin != consumedBottom) { + lp.rightMargin = consumedRight; + lp.bottomMargin = consumedBottom; + mContentRoot.setLayoutParams(lp); + } + } + if (insets != null) { - insets = insets.consumeStableInsets(); + insets = insets.consumeStableInsets().replaceSystemWindowInsets( + insets.getSystemWindowInsetLeft(), + insets.getSystemWindowInsetTop(), + insets.getSystemWindowInsetRight() - consumedRight, + insets.getSystemWindowInsetBottom() - consumedBottom + ); } return insets; } @@ -3373,6 +3411,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { View in = mLayoutInflater.inflate(layoutResource, null); decor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); + mContentRoot = (ViewGroup) in; ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); if (contentParent == null) { diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index ab311c04f5ade..d776aebb103ee 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -1520,8 +1520,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (ActivityManager.isHighEndGfx() && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) { - attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; } }