diff options
author | Adrian Roos <roosa@google.com> | 2014-06-20 16:10:14 -0700 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2014-07-02 12:34:05 +0000 |
commit | fa10423fa00f3495e451016acba9b6848eb995c9 (patch) | |
tree | dacb609ee12c80b7110960811a97abaf9bfd4304 /core/java/android/view/WindowInsets.java | |
parent | f29131f7013dc0d6994556b95e74db608c89beb8 (diff) | |
download | frameworks_base-fa10423fa00f3495e451016acba9b6848eb995c9.zip frameworks_base-fa10423fa00f3495e451016acba9b6848eb995c9.tar.gz frameworks_base-fa10423fa00f3495e451016acba9b6848eb995c9.tar.bz2 |
Add stable insets for stable system windows
Adds a new kind of inset that only accounts for stable system
windows like the system or navigation bar.
Bug: 15457292
Change-Id: I681b711f6f40a94c25b7acd3a44eb3539486afab
Diffstat (limited to 'core/java/android/view/WindowInsets.java')
-rw-r--r-- | core/java/android/view/WindowInsets.java | 81 |
1 files changed, 63 insertions, 18 deletions
diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java index 1d2f1bf..1832cc3 100644 --- a/core/java/android/view/WindowInsets.java +++ b/core/java/android/view/WindowInsets.java @@ -30,13 +30,16 @@ import android.graphics.Rect; * @see View#onApplyWindowInsets(WindowInsets) */ public final class WindowInsets { + private Rect mSystemWindowInsets; private Rect mWindowDecorInsets; + private Rect mStableInsets; private Rect mTempRect; private boolean mIsRound; private boolean mSystemWindowInsetsConsumed = false; private boolean mWindowDecorInsetsConsumed = false; + private boolean mStableInsetsConsumed = false; private static final Rect EMPTY_RECT = new Rect(0, 0, 0, 0); @@ -49,29 +52,21 @@ public final class WindowInsets { 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) { - this(systemWindowInsets, windowDecorInsets, false); - } - - /** @hide */ - public WindowInsets(Rect systemWindowInsets, boolean isRound) { - this(systemWindowInsets, null, isRound); + CONSUMED = new WindowInsets(null, null, null, false); } /** @hide */ - public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, boolean isRound) { + public WindowInsets(Rect systemWindowInsets, Rect windowDecorInsets, Rect stableInsets, + boolean isRound) { mSystemWindowInsetsConsumed = systemWindowInsets == null; mSystemWindowInsets = mSystemWindowInsetsConsumed ? EMPTY_RECT : systemWindowInsets; mWindowDecorInsetsConsumed = windowDecorInsets == null; mWindowDecorInsets = mWindowDecorInsetsConsumed ? EMPTY_RECT : windowDecorInsets; + mStableInsetsConsumed = stableInsets == null; + mStableInsets = mStableInsetsConsumed ? EMPTY_RECT : stableInsets; + mIsRound = isRound; } @@ -83,14 +78,16 @@ public final class WindowInsets { public WindowInsets(WindowInsets src) { mSystemWindowInsets = src.mSystemWindowInsets; mWindowDecorInsets = src.mWindowDecorInsets; + mStableInsets = src.mStableInsets; mSystemWindowInsetsConsumed = src.mSystemWindowInsetsConsumed; mWindowDecorInsetsConsumed = src.mWindowDecorInsetsConsumed; + mStableInsetsConsumed = src.mStableInsetsConsumed; mIsRound = src.mIsRound; } /** @hide */ public WindowInsets(Rect systemWindowInsets) { - this(systemWindowInsets, null); + this(systemWindowInsets, null, null, false); } /** @@ -272,7 +269,7 @@ public final class WindowInsets { * @hide Pending API */ public boolean isConsumed() { - return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed; + return mSystemWindowInsetsConsumed && mWindowDecorInsetsConsumed && mStableInsetsConsumed; } /** @@ -381,9 +378,57 @@ public final class WindowInsets { return result; } + /** + * @hide + */ + public int getStableInsetTop() { + return mStableInsets.top; + } + + /** + * @hide + */ + public int getStableInsetLeft() { + return mStableInsets.left; + } + + /** + * @hide + */ + public int getStableInsetRight() { + return mStableInsets.right; + } + + /** + * @hide + */ + public int getStableInsetBottom() { + return mStableInsets.bottom; + } + + /** + * @hide + */ + public boolean hasStableInsets() { + return mStableInsets.top != 0 || mStableInsets.left != 0 || mStableInsets.right != 0 + || mStableInsets.bottom != 0; + } + + /** + * @hide + */ + public WindowInsets consumeStableInsets() { + final WindowInsets result = new WindowInsets(this); + result.mStableInsets = EMPTY_RECT; + result.mStableInsetsConsumed = true; + return result; + } + @Override public String toString() { - return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + " windowDecorInsets=" + - mWindowDecorInsets + (isRound() ? "round}" : "}"); + return "WindowInsets{systemWindowInsets=" + mSystemWindowInsets + + " windowDecorInsets=" + mWindowDecorInsets + + " stableInsets=" + mStableInsets + + (isRound() ? " round}" : "}"); } } |