DO NOT MERGE Ignore insets on status_bar_container

- Instead, PhoneStatusBarView will take care of display cutout insets
based on the rotation of the device

Test: atest SystemUITests
Bug: 149197103
Change-Id: Ie4df9ce5c754408dcf2d50108576df42173fa17d
This commit is contained in:
Beverly
2020-03-09 16:07:56 -04:00
parent 12c8c244a6
commit ae242892e2
3 changed files with 45 additions and 11 deletions

View File

@@ -55,7 +55,8 @@
android:id="@+id/status_bar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/system_bar_background" />
android:background="@drawable/system_bar_background"
sysui:ignoreRightInset="true" />
<include layout="@layout/status_bar_expanded"
android:layout_width="match_parent"

View File

@@ -46,6 +46,7 @@ import com.android.systemui.R;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.util.leak.RotationUtils;
import java.util.Objects;
@@ -71,6 +72,7 @@ public class PhoneStatusBarView extends PanelBar {
};
private DarkReceiver mBattery;
private int mLastOrientation;
private int mRotationOrientation;
@Nullable
private View mCenterIconSpace;
@Nullable
@@ -81,6 +83,7 @@ public class PhoneStatusBarView extends PanelBar {
* Draw this many pixels into the left/right side of the cutout to optimally use the space
*/
private int mCutoutSideNudge = 0;
private int mStatusBarHeight;
private boolean mHeadsUpVisible;
public PhoneStatusBarView(Context context, AttributeSet attrs) {
@@ -155,6 +158,7 @@ public class PhoneStatusBarView extends PanelBar {
changed = true;
mLastOrientation = newOrientation;
}
mRotationOrientation = RotationUtils.getExactRotation(mContext);
}
if (!Objects.equals(getRootWindowInsets().getDisplayCutout(), mDisplayCutout)) {
@@ -289,14 +293,14 @@ public class PhoneStatusBarView extends PanelBar {
R.dimen.display_cutout_margin_consumption);
ViewGroup.LayoutParams layoutParams = getLayoutParams();
layoutParams.height = getResources().getDimensionPixelSize(
R.dimen.status_bar_height);
mStatusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
layoutParams.height = mStatusBarHeight;
setLayoutParams(layoutParams);
}
private void updateLayoutForCutout() {
Pair<Integer, Integer> cornerCutoutMargins = cornerCutoutMargins(mDisplayCutout,
getDisplay());
getDisplay(), mRotationOrientation, mStatusBarHeight);
updateCutoutLocation(cornerCutoutMargins);
updateSafeInsets(cornerCutoutMargins);
}
@@ -332,15 +336,13 @@ public class PhoneStatusBarView extends PanelBar {
// or letterboxing from the right or left sides.
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
if (mDisplayCutout == null || mDisplayCutout.isEmpty()
|| mLastOrientation != ORIENTATION_PORTRAIT || cornerCutoutMargins == null) {
if (mDisplayCutout == null || mDisplayCutout.isEmpty() || cornerCutoutMargins == null) {
lp.leftMargin = 0;
lp.rightMargin = 0;
return;
}
lp.leftMargin = Math.max(lp.leftMargin, cornerCutoutMargins.first);
lp.rightMargin = Math.max(lp.rightMargin, cornerCutoutMargins.second);
lp.leftMargin = cornerCutoutMargins.first;
lp.rightMargin = cornerCutoutMargins.second;
// If we're already inset enough (e.g. on the status bar side), we can have 0 margin
WindowInsets insets = getRootWindowInsets();
@@ -354,8 +356,19 @@ public class PhoneStatusBarView extends PanelBar {
}
}
/**
* Returns a Pair of integers where
* - Pair.first is the left margin inset
* - Pair.second is the right margin inset
* This method always assumes the cutout is on the top when the device is in portrait mode.
*/
public static Pair<Integer, Integer> cornerCutoutMargins(DisplayCutout cutout,
Display display) {
return cornerCutoutMargins(cutout, display, RotationUtils.ROTATION_NONE, -1);
}
private static Pair<Integer, Integer> cornerCutoutMargins(DisplayCutout cutout,
Display display, int rotationOrientation, int statusBarHeight) {
if (cutout == null) {
return null;
}
@@ -363,14 +376,33 @@ public class PhoneStatusBarView extends PanelBar {
display.getRealSize(size);
Rect bounds = new Rect();
boundsFromDirection(cutout, Gravity.TOP, bounds);
switch (rotationOrientation) {
case RotationUtils.ROTATION_LANDSCAPE:
boundsFromDirection(cutout, Gravity.LEFT, bounds);
break;
case RotationUtils.ROTATION_SEASCAPE:
boundsFromDirection(cutout, Gravity.RIGHT, bounds);
break;
case RotationUtils.ROTATION_NONE:
boundsFromDirection(cutout, Gravity.TOP, bounds);
break;
case RotationUtils.ROTATION_UPSIDE_DOWN:
// we assume the cutout is always on top in portrait mode
return null;
}
if (statusBarHeight >= 0 && bounds.top > statusBarHeight) {
return null;
}
if (bounds.left <= 0) {
return new Pair<>(bounds.right, 0);
}
if (bounds.right >= size.x) {
return new Pair<>(0, size.x - bounds.left);
}
return null;
}

View File

@@ -180,7 +180,8 @@ public class StatusBarWindowView extends FrameLayout {
int targetLeft = Math.max(insets.left, leftCutout);
int targetRight = Math.max(insets.right, rightCutout);
// Super-special right inset handling, because scrims and backdrop need to ignore it.
// Super-special right inset handling, because scrims, backdrop and status bar
// container need to ignore it.
if (targetRight != mRightInset || targetLeft != mLeftInset) {
mRightInset = targetRight;
mLeftInset = targetLeft;