Merge "Fixing wrong window insets estimation" into tm-dev am: 53c0b2c00f

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/18127262

Change-Id: I86257ce61bb5960f4a8585db9a41b46bc83bf1c2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-05-03 17:19:32 +00:00
committed by Automerger Merge Worker
3 changed files with 43 additions and 12 deletions
@@ -31,6 +31,10 @@ public class ResourceUtils {
public static final String NAVBAR_HEIGHT = "navigation_bar_height"; public static final String NAVBAR_HEIGHT = "navigation_bar_height";
public static final String NAVBAR_HEIGHT_LANDSCAPE = "navigation_bar_height_landscape"; public static final String NAVBAR_HEIGHT_LANDSCAPE = "navigation_bar_height_landscape";
public static final String STATUS_BAR_HEIGHT = "status_bar_height";
public static final String STATUS_BAR_HEIGHT_LANDSCAPE = "status_bar_height_landscape";
public static final String STATUS_BAR_HEIGHT_PORTRAIT = "status_bar_height_portrait";
public static int getNavbarSize(String resName, Resources res) { public static int getNavbarSize(String resName, Resources res) {
return getDimenByName(resName, res, DEFAULT_NAVBAR_VALUE); return getDimenByName(resName, res, DEFAULT_NAVBAR_VALUE);
} }
@@ -22,6 +22,9 @@ import static com.android.launcher3.ResourceUtils.INVALID_RESOURCE_HANDLE;
import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT; import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT;
import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT_LANDSCAPE; import static com.android.launcher3.ResourceUtils.NAVBAR_HEIGHT_LANDSCAPE;
import static com.android.launcher3.ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE; import static com.android.launcher3.ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE;
import static com.android.launcher3.ResourceUtils.STATUS_BAR_HEIGHT;
import static com.android.launcher3.ResourceUtils.STATUS_BAR_HEIGHT_LANDSCAPE;
import static com.android.launcher3.ResourceUtils.STATUS_BAR_HEIGHT_PORTRAIT;
import static com.android.launcher3.Utilities.dpiFromPx; import static com.android.launcher3.Utilities.dpiFromPx;
import static com.android.launcher3.util.MainThreadInitializedObject.forOverride; import static com.android.launcher3.util.MainThreadInitializedObject.forOverride;
import static com.android.launcher3.util.RotationUtils.deltaRotation; import static com.android.launcher3.util.RotationUtils.deltaRotation;
@@ -152,20 +155,26 @@ public class WindowManagerProxy implements ResourceBasedOverride {
boolean isTablet = config.smallestScreenWidthDp > MIN_TABLET_WIDTH; boolean isTablet = config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
boolean isGesture = isGestureNav(context); boolean isGesture = isGestureNav(context);
boolean isPortrait = config.screenHeightDp > config.screenWidthDp;
int bottomNav = isTablet int bottomNav = isTablet
? 0 ? 0
: (config.screenHeightDp > config.screenWidthDp : (isPortrait
? getDimenByName(NAVBAR_HEIGHT, systemRes) ? getDimenByName(systemRes, NAVBAR_HEIGHT)
: (isGesture : (isGesture
? getDimenByName(NAVBAR_HEIGHT_LANDSCAPE, systemRes) ? getDimenByName(systemRes, NAVBAR_HEIGHT_LANDSCAPE)
: 0)); : 0));
Insets newNavInsets = Insets.of(navInsets.left, navInsets.top, navInsets.right, bottomNav); Insets newNavInsets = Insets.of(navInsets.left, navInsets.top, navInsets.right, bottomNav);
insetsBuilder.setInsets(WindowInsets.Type.navigationBars(), newNavInsets); insetsBuilder.setInsets(WindowInsets.Type.navigationBars(), newNavInsets);
insetsBuilder.setInsetsIgnoringVisibility(WindowInsets.Type.navigationBars(), newNavInsets); insetsBuilder.setInsetsIgnoringVisibility(WindowInsets.Type.navigationBars(), newNavInsets);
Insets statusBarInsets = oldInsets.getInsets(WindowInsets.Type.statusBars()); Insets statusBarInsets = oldInsets.getInsets(WindowInsets.Type.statusBars());
int statusBarHeight = getDimenByName("status_bar_height", systemRes);
int statusBarHeight = getDimenByName(systemRes,
(isPortrait) ? STATUS_BAR_HEIGHT_PORTRAIT : STATUS_BAR_HEIGHT_LANDSCAPE,
STATUS_BAR_HEIGHT);
Insets newStatusBarInsets = Insets.of( Insets newStatusBarInsets = Insets.of(
statusBarInsets.left, statusBarInsets.left,
Math.max(statusBarInsets.top, statusBarHeight), Math.max(statusBarInsets.top, statusBarHeight),
@@ -221,23 +230,26 @@ public class WindowManagerProxy implements ResourceBasedOverride {
boolean isTabletOrGesture = isTablet boolean isTabletOrGesture = isTablet
|| (Utilities.ATLEAST_R && isGestureNav(context)); || (Utilities.ATLEAST_R && isGestureNav(context));
int statusBarHeight = getDimenByName("status_bar_height", systemRes); int statusBarHeightPortrait = getDimenByName(systemRes,
STATUS_BAR_HEIGHT_PORTRAIT, STATUS_BAR_HEIGHT);
int statusBarHeightLandscape = getDimenByName(systemRes,
STATUS_BAR_HEIGHT_LANDSCAPE, STATUS_BAR_HEIGHT);
int navBarHeightPortrait, navBarHeightLandscape, navbarWidthLandscape; int navBarHeightPortrait, navBarHeightLandscape, navbarWidthLandscape;
navBarHeightPortrait = isTablet navBarHeightPortrait = isTablet
? (mTaskbarDrawnInProcess ? (mTaskbarDrawnInProcess
? 0 : systemRes.getDimensionPixelSize(R.dimen.taskbar_size)) ? 0 : systemRes.getDimensionPixelSize(R.dimen.taskbar_size))
: getDimenByName(NAVBAR_HEIGHT, systemRes); : getDimenByName(systemRes, NAVBAR_HEIGHT);
navBarHeightLandscape = isTablet navBarHeightLandscape = isTablet
? (mTaskbarDrawnInProcess ? (mTaskbarDrawnInProcess
? 0 : systemRes.getDimensionPixelSize(R.dimen.taskbar_size)) ? 0 : systemRes.getDimensionPixelSize(R.dimen.taskbar_size))
: (isTabletOrGesture : (isTabletOrGesture
? getDimenByName(NAVBAR_HEIGHT_LANDSCAPE, systemRes) : 0); ? getDimenByName(systemRes, NAVBAR_HEIGHT_LANDSCAPE) : 0);
navbarWidthLandscape = isTabletOrGesture navbarWidthLandscape = isTabletOrGesture
? 0 ? 0
: getDimenByName(NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE, systemRes); : getDimenByName(systemRes, NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE);
WindowBounds[] result = new WindowBounds[4]; WindowBounds[] result = new WindowBounds[4];
Point tempSize = new Point(); Point tempSize = new Point();
@@ -247,13 +259,15 @@ public class WindowManagerProxy implements ResourceBasedOverride {
rotateSize(tempSize, rotationChange); rotateSize(tempSize, rotationChange);
Rect bounds = new Rect(0, 0, tempSize.x, tempSize.y); Rect bounds = new Rect(0, 0, tempSize.x, tempSize.y);
int navBarHeight, navbarWidth; int navBarHeight, navbarWidth, statusBarHeight;
if (tempSize.y > tempSize.x) { if (tempSize.y > tempSize.x) {
navBarHeight = navBarHeightPortrait; navBarHeight = navBarHeightPortrait;
navbarWidth = 0; navbarWidth = 0;
statusBarHeight = statusBarHeightPortrait;
} else { } else {
navBarHeight = navBarHeightLandscape; navBarHeight = navBarHeightLandscape;
navbarWidth = navbarWidthLandscape; navbarWidth = navbarWidthLandscape;
statusBarHeight = statusBarHeightLandscape;
} }
Rect insets = new Rect(safeCutout); Rect insets = new Rect(safeCutout);
@@ -276,10 +290,18 @@ public class WindowManagerProxy implements ResourceBasedOverride {
/** /**
* Wrapper around the utility method for easier emulation * Wrapper around the utility method for easier emulation
*/ */
protected int getDimenByName(String resName, Resources res) { protected int getDimenByName(Resources res, String resName) {
return ResourceUtils.getDimenByName(resName, res, 0); return ResourceUtils.getDimenByName(resName, res, 0);
} }
/**
* Wrapper around the utility method for easier emulation
*/
protected int getDimenByName(Resources res, String resName, String fallback) {
int dimen = ResourceUtils.getDimenByName(resName, res, -1);
return dimen > -1 ? dimen : getDimenByName(res, fallback);
}
protected boolean isGestureNav(Context context) { protected boolean isGestureNav(Context context) {
return ResourceUtils.getIntegerByName("config_navBarInteractionMode", return ResourceUtils.getIntegerByName("config_navBarInteractionMode",
context.getResources(), INVALID_RESOURCE_HANDLE) == 2; context.getResources(), INVALID_RESOURCE_HANDLE) == 2;
@@ -43,9 +43,14 @@ public class TestWindowManagerProxy extends WindowManagerProxy {
} }
@Override @Override
protected int getDimenByName(String resName, Resources res) { protected int getDimenByName(Resources res, String resName) {
Integer mock = mDevice.resourceOverrides.get(resName); Integer mock = mDevice.resourceOverrides.get(resName);
return mock != null ? mock : super.getDimenByName(resName, res); return mock != null ? mock : super.getDimenByName(res, resName);
}
@Override
protected int getDimenByName(Resources res, String resName, String fallback) {
return getDimenByName(res, resName);
} }
@Override @Override