Merge "DO NOT MERGE Ignore insets on status_bar_container" into qt-qpr1-dev

This commit is contained in:
TreeHugger Robot
2020-03-11 20:48:55 +00:00
committed by Android (Google) Code Review
3 changed files with 45 additions and 11 deletions

View File

@@ -55,7 +55,8 @@
android:id="@+id/status_bar_container" android:id="@+id/status_bar_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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" <include layout="@layout/status_bar_expanded"
android:layout_width="match_parent" 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;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.util.leak.RotationUtils;
import java.util.Objects; import java.util.Objects;
@@ -71,6 +72,7 @@ public class PhoneStatusBarView extends PanelBar {
}; };
private DarkReceiver mBattery; private DarkReceiver mBattery;
private int mLastOrientation; private int mLastOrientation;
private int mRotationOrientation;
@Nullable @Nullable
private View mCenterIconSpace; private View mCenterIconSpace;
@Nullable @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 * Draw this many pixels into the left/right side of the cutout to optimally use the space
*/ */
private int mCutoutSideNudge = 0; private int mCutoutSideNudge = 0;
private int mStatusBarHeight;
private boolean mHeadsUpVisible; private boolean mHeadsUpVisible;
public PhoneStatusBarView(Context context, AttributeSet attrs) { public PhoneStatusBarView(Context context, AttributeSet attrs) {
@@ -155,6 +158,7 @@ public class PhoneStatusBarView extends PanelBar {
changed = true; changed = true;
mLastOrientation = newOrientation; mLastOrientation = newOrientation;
} }
mRotationOrientation = RotationUtils.getExactRotation(mContext);
} }
if (!Objects.equals(getRootWindowInsets().getDisplayCutout(), mDisplayCutout)) { if (!Objects.equals(getRootWindowInsets().getDisplayCutout(), mDisplayCutout)) {
@@ -289,14 +293,14 @@ public class PhoneStatusBarView extends PanelBar {
R.dimen.display_cutout_margin_consumption); R.dimen.display_cutout_margin_consumption);
ViewGroup.LayoutParams layoutParams = getLayoutParams(); ViewGroup.LayoutParams layoutParams = getLayoutParams();
layoutParams.height = getResources().getDimensionPixelSize( mStatusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
R.dimen.status_bar_height); layoutParams.height = mStatusBarHeight;
setLayoutParams(layoutParams); setLayoutParams(layoutParams);
} }
private void updateLayoutForCutout() { private void updateLayoutForCutout() {
Pair<Integer, Integer> cornerCutoutMargins = cornerCutoutMargins(mDisplayCutout, Pair<Integer, Integer> cornerCutoutMargins = cornerCutoutMargins(mDisplayCutout,
getDisplay()); getDisplay(), mRotationOrientation, mStatusBarHeight);
updateCutoutLocation(cornerCutoutMargins); updateCutoutLocation(cornerCutoutMargins);
updateSafeInsets(cornerCutoutMargins); updateSafeInsets(cornerCutoutMargins);
} }
@@ -332,15 +336,13 @@ public class PhoneStatusBarView extends PanelBar {
// or letterboxing from the right or left sides. // or letterboxing from the right or left sides.
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
if (mDisplayCutout == null || mDisplayCutout.isEmpty() if (mDisplayCutout == null || mDisplayCutout.isEmpty() || cornerCutoutMargins == null) {
|| mLastOrientation != ORIENTATION_PORTRAIT || cornerCutoutMargins == null) {
lp.leftMargin = 0; lp.leftMargin = 0;
lp.rightMargin = 0; lp.rightMargin = 0;
return; return;
} }
lp.leftMargin = cornerCutoutMargins.first;
lp.leftMargin = Math.max(lp.leftMargin, cornerCutoutMargins.first); lp.rightMargin = cornerCutoutMargins.second;
lp.rightMargin = Math.max(lp.rightMargin, cornerCutoutMargins.second);
// If we're already inset enough (e.g. on the status bar side), we can have 0 margin // If we're already inset enough (e.g. on the status bar side), we can have 0 margin
WindowInsets insets = getRootWindowInsets(); 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, public static Pair<Integer, Integer> cornerCutoutMargins(DisplayCutout cutout,
Display display) { 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) { if (cutout == null) {
return null; return null;
} }
@@ -363,14 +376,33 @@ public class PhoneStatusBarView extends PanelBar {
display.getRealSize(size); display.getRealSize(size);
Rect bounds = new Rect(); 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) { if (bounds.left <= 0) {
return new Pair<>(bounds.right, 0); return new Pair<>(bounds.right, 0);
} }
if (bounds.right >= size.x) { if (bounds.right >= size.x) {
return new Pair<>(0, size.x - bounds.left); return new Pair<>(0, size.x - bounds.left);
} }
return null; return null;
} }

View File

@@ -180,7 +180,8 @@ public class StatusBarWindowView extends FrameLayout {
int targetLeft = Math.max(insets.left, leftCutout); int targetLeft = Math.max(insets.left, leftCutout);
int targetRight = Math.max(insets.right, rightCutout); 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) { if (targetRight != mRightInset || targetLeft != mLeftInset) {
mRightInset = targetRight; mRightInset = targetRight;
mLeftInset = targetLeft; mLeftInset = targetLeft;