Merge "Refine the bounds of the wrap-content sides" into sc-v2-dev

This commit is contained in:
Tiger Huang
2021-07-28 14:51:28 +00:00
committed by Android (Google) Code Review
2 changed files with 34 additions and 21 deletions

View File

@@ -2517,6 +2517,14 @@ public final class ViewRootImpl implements ViewParent,
|| lp.type == TYPE_VOLUME_OVERLAY;
}
private Rect getWindowBoundsInsetSystemBars() {
final Rect bounds = new Rect(
mContext.getResources().getConfiguration().windowConfiguration.getBounds());
bounds.inset(mInsetsController.getState().calculateInsets(
bounds, Type.systemBars(), false /* ignoreVisibility */));
return bounds;
}
int dipToPx(int dip) {
final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
return (int) (displayMetrics.density * dip + 0.5f);
@@ -2603,8 +2611,9 @@ public final class ViewRootImpl implements ViewParent,
|| lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
// For wrap content, we have to remeasure later on anyways. Use size consistent with
// below so we get best use of the measure cache.
desiredWindowWidth = dipToPx(config.screenWidthDp);
desiredWindowHeight = dipToPx(config.screenHeightDp);
final Rect bounds = getWindowBoundsInsetSystemBars();
desiredWindowWidth = bounds.width();
desiredWindowHeight = bounds.height();
} else {
// After addToDisplay, the frame contains the frameHint from window manager, which
// for most windows is going to be the same size as the result of relayoutWindow.
@@ -2681,9 +2690,9 @@ public final class ViewRootImpl implements ViewParent,
desiredWindowWidth = size.x;
desiredWindowHeight = size.y;
} else {
Configuration config = res.getConfiguration();
desiredWindowWidth = dipToPx(config.screenWidthDp);
desiredWindowHeight = dipToPx(config.screenHeightDp);
final Rect bounds = getWindowBoundsInsetSystemBars();
desiredWindowWidth = bounds.width();
desiredWindowHeight = bounds.height();
}
}
}

View File

@@ -133,12 +133,19 @@ class InsetsPolicy {
abortTransient();
}
mFocusedWin = focusedWin;
InsetsControlTarget statusControlTarget = getStatusControlTarget(focusedWin);
InsetsControlTarget navControlTarget = getNavControlTarget(focusedWin);
mStateController.onBarControlTargetChanged(statusControlTarget,
getFakeControlTarget(focusedWin, statusControlTarget),
final InsetsControlTarget statusControlTarget =
getStatusControlTarget(focusedWin, false /* fake */);
final InsetsControlTarget navControlTarget =
getNavControlTarget(focusedWin, false /* fake */);
mStateController.onBarControlTargetChanged(
statusControlTarget,
statusControlTarget == mDummyControlTarget
? getStatusControlTarget(focusedWin, true /* fake */)
: null,
navControlTarget,
getFakeControlTarget(focusedWin, navControlTarget));
navControlTarget == mDummyControlTarget
? getNavControlTarget(focusedWin, true /* fake */)
: null);
mStatusBar.updateVisibility(statusControlTarget, ITYPE_STATUS_BAR);
mNavBar.updateVisibility(navControlTarget, ITYPE_NAVIGATION_BAR);
}
@@ -294,13 +301,9 @@ class InsetsPolicy {
mShowingTransientTypes.clear();
}
private @Nullable InsetsControlTarget getFakeControlTarget(@Nullable WindowState focused,
InsetsControlTarget realControlTarget) {
return realControlTarget == mDummyControlTarget ? focused : null;
}
private @Nullable InsetsControlTarget getStatusControlTarget(@Nullable WindowState focusedWin) {
if (mShowingTransientTypes.indexOf(ITYPE_STATUS_BAR) != -1) {
private @Nullable InsetsControlTarget getStatusControlTarget(@Nullable WindowState focusedWin,
boolean fake) {
if (mShowingTransientTypes.indexOf(ITYPE_STATUS_BAR) != -1 && !fake) {
return mDummyControlTarget;
}
final WindowState notificationShade = mPolicy.getNotificationShade();
@@ -318,7 +321,7 @@ class InsetsPolicy {
// we will dispatch the real visibility of status bar to the client.
return null;
}
if (forceShowsStatusBarTransiently()) {
if (forceShowsStatusBarTransiently() && !fake) {
// Status bar is forcibly shown transiently, and its new visibility won't be
// dispatched to the client so that we can keep the layout stable. We will dispatch the
// fake control to the client, so that it can re-show the bar during this scenario.
@@ -343,13 +346,14 @@ class InsetsPolicy {
&& !win.inMultiWindowMode();
}
private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin) {
private @Nullable InsetsControlTarget getNavControlTarget(@Nullable WindowState focusedWin,
boolean fake) {
final WindowState imeWin = mDisplayContent.mInputMethodWindow;
if (imeWin != null && imeWin.isVisible()) {
// Force showing navigation bar while IME is visible.
return null;
}
if (mShowingTransientTypes.indexOf(ITYPE_NAVIGATION_BAR) != -1) {
if (mShowingTransientTypes.indexOf(ITYPE_NAVIGATION_BAR) != -1 && !fake) {
return mDummyControlTarget;
}
if (focusedWin == mPolicy.getNotificationShade()) {
@@ -366,7 +370,7 @@ class InsetsPolicy {
// bar, and we will dispatch the real visibility of navigation bar to the client.
return null;
}
if (forceShowsNavigationBarTransiently()) {
if (forceShowsNavigationBarTransiently() && !fake) {
// Navigation bar is forcibly shown transiently, and its new visibility won't be
// dispatched to the client so that we can keep the layout stable. We will dispatch the
// fake control to the client, so that it can re-show the bar during this scenario.