Adding support for non-zero left insets

Bug: 29613069
Change-Id: Ifdf9bcce7ecdedc510f3be8a4dc10eb8da7c4bf1
This commit is contained in:
Sunny Goyal
2016-07-06 09:47:56 -07:00
parent 27731e4d7d
commit 6c2975e7e3
5 changed files with 56 additions and 41 deletions

View File

@@ -15,7 +15,9 @@ public class LauncherRootView extends InsettableFrameLayout {
private final Paint mOpaquePaint;
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mDrawRightInsetBar;
private boolean mDrawSideInsetBar;
@ViewDebug.ExportedProperty(category = "launcher")
private int mLeftInsetBarWidth;
@ViewDebug.ExportedProperty(category = "launcher")
private int mRightInsetBarWidth;
@@ -42,13 +44,14 @@ public class LauncherRootView extends InsettableFrameLayout {
@TargetApi(23)
@Override
protected boolean fitSystemWindows(Rect insets) {
mDrawRightInsetBar = insets.right > 0 &&
mDrawSideInsetBar = (insets.right > 0 || insets.left > 0) &&
(!Utilities.ATLEAST_MARSHMALLOW ||
getContext().getSystemService(ActivityManager.class).isLowRamDevice());
mRightInsetBarWidth = insets.right;
setInsets(mDrawRightInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets);
mLeftInsetBarWidth = insets.left;
setInsets(mDrawSideInsetBar ? new Rect(0, insets.top, 0, insets.bottom) : insets);
if (mAlignedView != null && mDrawRightInsetBar) {
if (mAlignedView != null && mDrawSideInsetBar) {
// Apply margins on aligned view to handle left/right insets.
MarginLayoutParams lp = (MarginLayoutParams) mAlignedView.getLayoutParams();
if (lp.leftMargin != insets.left || lp.rightMargin != insets.right) {
@@ -66,9 +69,14 @@ public class LauncherRootView extends InsettableFrameLayout {
super.dispatchDraw(canvas);
// If the right inset is opaque, draw a black rectangle to ensure that is stays opaque.
if (mDrawRightInsetBar) {
int width = getWidth();
canvas.drawRect(width - mRightInsetBarWidth, 0, width, getHeight(), mOpaquePaint);
if (mDrawSideInsetBar) {
if (mRightInsetBarWidth > 0) {
int width = getWidth();
canvas.drawRect(width - mRightInsetBarWidth, 0, width, getHeight(), mOpaquePaint);
}
if (mLeftInsetBarWidth > 0) {
canvas.drawRect(0, 0, mLeftInsetBarWidth, getHeight(), mOpaquePaint);
}
}
}
}