From 474690caf8b3bece133b40914979ac2520036989 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 6 Mar 2013 11:33:26 -0800 Subject: [PATCH] Fix issue #8325007: EyeEm app crashes on launch- NPE at... ...android.view.ViewGroup.measureChildWithMargins The app is doing grungy stuff with trying to insert its own views inside the window decor. This new custom layout of the action bar was assuming it would get fitSystemWindows() called at which point it would retrieve all of its child views... but with the app doing this, it blocks the call down to fitSystemWindows() and breaks us. So we now make the layout manager more robust and ensure it has retrieved its children when measuring. Also fix an issue where the xlarge layouts were not updated. Change-Id: I6c69f26f26b59a6aa8fa1e5788288ffce0b490ca --- .../widget/ActionBarOverlayLayout.java | 37 +++++++----- .../res/layout-xlarge/screen_action_bar.xml | 60 +++++++++++-------- .../screen_action_bar_overlay.xml | 58 ------------------ core/res/res/values/symbols.xml | 1 - 4 files changed, 56 insertions(+), 100 deletions(-) delete mode 100644 core/res/res/layout-xlarge/screen_action_bar_overlay.xml diff --git a/core/java/com/android/internal/widget/ActionBarOverlayLayout.java b/core/java/com/android/internal/widget/ActionBarOverlayLayout.java index 79dadd75581bd..f3591463e2838 100644 --- a/core/java/com/android/internal/widget/ActionBarOverlayLayout.java +++ b/core/java/com/android/internal/widget/ActionBarOverlayLayout.java @@ -73,10 +73,6 @@ public class ActionBarOverlayLayout extends ViewGroup { ta.recycle(); } - public void setOverlayMode(boolean mode) { - mOverlayMode = mode; - } - public void setActionBar(ActionBarImpl impl, boolean overlayMode) { mActionBar = impl; mOverlayMode = overlayMode; @@ -177,7 +173,9 @@ public class ActionBarOverlayLayout extends ViewGroup { // The top and bottom action bars are always within the content area. boolean changed = applyInsets(mActionBarTop, insets, true, true, false, true); - changed |= applyInsets(mActionBarBottom, insets, true, false, true, true); + if (mActionBarBottom != null) { + changed |= applyInsets(mActionBarBottom, insets, true, false, true, true); + } mBaseInnerInsets.set(insets); computeFitSystemWindows(mBaseInnerInsets, mBaseContentInsets); @@ -219,6 +217,8 @@ public class ActionBarOverlayLayout extends ViewGroup { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + pullChildren(); + int maxHeight = 0; int maxWidth = 0; int childState = 0; @@ -234,13 +234,16 @@ public class ActionBarOverlayLayout extends ViewGroup { mActionBarTop.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); childState = combineMeasuredStates(childState, mActionBarTop.getMeasuredState()); - measureChildWithMargins(mActionBarBottom, widthMeasureSpec, 0, heightMeasureSpec, 0); - lp = (LayoutParams) mActionBarBottom.getLayoutParams(); - maxWidth = Math.max(maxWidth, - mActionBarBottom.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); - maxHeight = Math.max(maxHeight, - mActionBarBottom.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); - childState = combineMeasuredStates(childState, mActionBarBottom.getMeasuredState()); + // xlarge screen layout doesn't have bottom action bar. + if (mActionBarBottom != null) { + measureChildWithMargins(mActionBarBottom, widthMeasureSpec, 0, heightMeasureSpec, 0); + lp = (LayoutParams) mActionBarBottom.getLayoutParams(); + maxWidth = Math.max(maxWidth, + mActionBarBottom.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); + maxHeight = Math.max(maxHeight, + mActionBarBottom.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); + childState = combineMeasuredStates(childState, mActionBarBottom.getMeasuredState()); + } final int vis = getWindowSystemUiVisibility(); final boolean stable = (vis & SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0; @@ -264,10 +267,12 @@ public class ActionBarOverlayLayout extends ViewGroup { if (mActionView.isSplitActionBar()) { // If action bar is split, adjust bottom insets for it. - if (stable) { - bottomInset = mActionBarHeight; - } else { - bottomInset = mActionBarBottom.getMeasuredHeight(); + if (mActionBarBottom != null) { + if (stable) { + bottomInset = mActionBarHeight; + } else { + bottomInset = mActionBarBottom.getMeasuredHeight(); + } } } diff --git a/core/res/res/layout-xlarge/screen_action_bar.xml b/core/res/res/layout-xlarge/screen_action_bar.xml index 0b6122d5f1492..4f286780104fa 100644 --- a/core/res/res/layout-xlarge/screen_action_bar.xml +++ b/core/res/res/layout-xlarge/screen_action_bar.xml @@ -15,33 +15,43 @@ --> - - - - - - + android:layout_height="match_parent" /> + + + + + + + + diff --git a/core/res/res/layout-xlarge/screen_action_bar_overlay.xml b/core/res/res/layout-xlarge/screen_action_bar_overlay.xml deleted file mode 100644 index a95635e6a6622..0000000000000 --- a/core/res/res/layout-xlarge/screen_action_bar_overlay.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index c87cb27ee31c4..140ff704f2771 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1363,7 +1363,6 @@ -