diff options
| author | 2014-06-14 01:03:28 +0000 | |
|---|---|---|
| committer | 2014-06-13 21:09:46 +0000 | |
| commit | 1e6048e0158310ee31e0310661bed06a41ac7dd7 (patch) | |
| tree | 74be0df79ddc5a9d3ad661d356488df0bd1a1e69 | |
| parent | aa1ecf5cdf70c5b76bd5e31d252735ba52a90b72 (diff) | |
| parent | 11335f14b9a3fd0a672a0fa0206e1f58b688dd36 (diff) | |
Merge "DO NOT MERGE Cherry picking 3 CLs to fix CTS testFitSystemWindows" into klp-modular-dev
| -rw-r--r-- | core/java/android/view/View.java | 8 | ||||
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 4 | ||||
| -rw-r--r-- | core/java/android/view/WindowInsets.java | 54 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/ActionBarOverlayLayout.java | 10 |
4 files changed, 65 insertions, 11 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 4c53df7723fd..d7dc6a45f803 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -5923,12 +5923,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ protected boolean fitSystemWindows(Rect insets) { if ((mPrivateFlags3 & PFLAG3_APPLYING_INSETS) == 0) { + if (insets == null) { + // Null insets by definition have already been consumed. + // This call cannot apply insets since there are none to apply, + // so return false. + return false; + } // If we're not in the process of dispatching the newer apply insets call, // that means we're not in the compatibility path. Dispatch into the newer // apply insets path and take things from there. try { mPrivateFlags3 |= PFLAG3_FITTING_SYSTEM_WINDOWS; - return !dispatchApplyWindowInsets(new WindowInsets(insets)).hasInsets(); + return dispatchApplyWindowInsets(new WindowInsets(insets)).isConsumed(); } finally { mPrivateFlags3 &= PFLAG3_FITTING_SYSTEM_WINDOWS; } diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index dda5a608d0d1..cc6f9ab3e1ea 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -5433,11 +5433,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager @Override public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { insets = super.dispatchApplyWindowInsets(insets); - if (insets.hasInsets()) { + if (!insets.isConsumed()) { final int count = getChildCount(); for (int i = 0; i < count; i++) { insets = getChildAt(i).dispatchApplyWindowInsets(insets); - if (!insets.hasInsets()) { + if (insets.isConsumed()) { break; } } diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java index 57e774eb0062..1d2f1bfcbe06 100644 --- a/core/java/android/view/WindowInsets.java +++ b/core/java/android/view/WindowInsets.java @@ -35,6 +35,9 @@ public final class WindowInsets { private Rect mTempRect; private boolean mIsRound; + private boolean mSystemWindowInsetsConsumed = false; + private boolean mWindowDecorInsetsConsumed = false; + private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0); /** @@ -43,7 +46,13 @@ public final class WindowInsets { * since it would allow them to inadvertently consume unknown insets by returning it. * @hide */ - public static final WindowInsets EMPTY = new WindowInsets(EMPTY_RECT, EMPTY_RECT); + public static final WindowInsets CONSUMED; + + static { + CONSUMED = new WindowInsets(EMPTY_RECT, EMPTY_RECT); + CONSUMED.mSystemWindowInsetsConsumed = true; + CONSUMED.mWindowDecorInsetsConsumed = true; + } /** @hide */ public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets) { @@ -52,13 +61,17 @@ public final class WindowInsets { /** @hide */ public WindowInsets(Rect systemWindowInsets, boolean isRound) { - this(systemWindowInsets, EMPTY_RECT, isRound); + this(systemWindowInsets, null, isRound); } /** @hide */ public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, boolean isRound) { - mSystemWindowInsets = systemWindowInsets; - mWindowDecorInsets = windowDecorInsets; + mSystemWindowInsetsConsumed = systemWindowInsets == null; + mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets; + + mWindowDecorInsetsConsumed = windowDecorInsets == null; + mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets; + mIsRound = isRound; } @@ -70,12 +83,14 @@ public final class WindowInsets { public WindowInsets(WindowInsets src) { mSystemWindowInsets = src.mSystemWindowInsets; mWindowDecorInsets = src.mWindowDecorInsets; + mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed; + mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed; mIsRound = src.mIsRound; } /** @hide */ public WindowInsets(Rect systemWindowInsets) { - this(systemWindowInsets, EMPTY_RECT); + this(systemWindowInsets, null); } /** @@ -243,6 +258,24 @@ public final class WindowInsets { } /** + * Check if these insets have been fully consumed. + * + * <p>Insets are considered "consumed" if the applicable <code>consume*</code> methods + * have been called such that all insets have been set to zero. This affects propagation of + * insets through the view hierarchy; insets that have not been fully consumed will continue + * to propagate down to child views.</p> + * + * <p>The result of this method is equivalent to the return value of + * {@link View#fitSystemWindows(android.graphics.Rect)}.</p> + * + * @return true if the insets have been fully consumed. + * @hide Pending API + */ + public boolean isConsumed() { + return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed; + } + + /** * Returns true if the associated window has a round shape. * * <p>A round window's left, top, right and bottom edges reach all the way to the @@ -263,7 +296,8 @@ public final class WindowInsets { */ public WindowInsets consumeSystemWindowInsets() { final WindowInsets result = new WindowInsets(this); - result.mSystemWindowInsets = new Rect(0, 0, 0, 0); + result.mSystemWindowInsets = EMPTY_RECT; + result.mSystemWindowInsetsConsumed = true; return result; } @@ -281,10 +315,12 @@ public final class WindowInsets { boolean right, boolean bottom) { if (left || top || right || bottom) { final WindowInsets result = new WindowInsets(this); - result.mSystemWindowInsets = new Rect(left ? 0 : mSystemWindowInsets.left, + result.mSystemWindowInsets = new Rect( + left ? 0 : mSystemWindowInsets.left, top ? 0 : mSystemWindowInsets.top, right ? 0 : mSystemWindowInsets.right, bottom ? 0 : mSystemWindowInsets.bottom); + result.mSystemWindowInsetsConsumed = !hasSystemWindowInsets(); return result; } return this; @@ -304,6 +340,7 @@ public final class WindowInsets { int right, int bottom) { final WindowInsets result = new WindowInsets(this); result.mSystemWindowInsets = new Rect(left, top, right, bottom); + result.mSystemWindowInsetsConsumed = !hasSystemWindowInsets(); return result; } @@ -313,6 +350,7 @@ public final class WindowInsets { public WindowInsets consumeWindowDecorInsets() { final WindowInsets result = new WindowInsets(this); result.mWindowDecorInsets.set(0, 0, 0, 0); + result.mWindowDecorInsetsConsumed = true; return result; } @@ -327,6 +365,7 @@ public final class WindowInsets { top ? 0 : mWindowDecorInsets.top, right ? 0 : mWindowDecorInsets.right, bottom ? 0 : mWindowDecorInsets.bottom); + result.mWindowDecorInsetsConsumed = !hasWindowDecorInsets(); return result; } return this; @@ -338,6 +377,7 @@ public final class WindowInsets { public WindowInsets replaceWindowDecorInsets(int left, int top, int right, int bottom) { final WindowInsets result = new WindowInsets(this); result.mWindowDecorInsets = new Rect(left, top, right, bottom); + result.mWindowDecorInsetsConsumed = !hasWindowDecorInsets(); return result; } diff --git a/core/java/com/android/internal/widget/ActionBarOverlayLayout.java b/core/java/com/android/internal/widget/ActionBarOverlayLayout.java index c957b673ff59..d4adee19f4ba 100644 --- a/core/java/com/android/internal/widget/ActionBarOverlayLayout.java +++ b/core/java/com/android/internal/widget/ActionBarOverlayLayout.java @@ -16,6 +16,7 @@ package com.android.internal.widget; +import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; @@ -135,6 +136,13 @@ public class ActionBarOverlayLayout extends ViewGroup { } @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + init(getContext()); + requestApplyInsets(); + } + + @Override public void onWindowSystemUiVisibilityChanged(int visible) { super.onWindowSystemUiVisibilityChanged(visible); pullChildren(); @@ -219,7 +227,7 @@ public class ActionBarOverlayLayout extends ViewGroup { // insets in all cases, we need to know the measured size of the various action // bar elements. onApplyWindowInsets() happens before the measure pass, so we can't // do that here. Instead we will take this up in onMeasure(). - return WindowInsets.EMPTY; + return WindowInsets.CONSUMED; } @Override |