Android: Fix incorrect dimensions - part 2

The previous fix worked for lower API levels but failed to
work properly on some devices (Devices with > 29 API levels). This
patch fixes that issue.

Task-number: QTBUG-107604
Task-number: QTBUG-107923
Change-Id: I8fd3601225026ea5c370a8a1a1aab317558432b5
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
(cherry picked from commit bb629a2e293b8b181cfb176087aab96f68cfbbd7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 89725106ed8b0f0991adacdf0189523f89cec02b)
Reviewed-by: Akseli Salovaara <akseli.salovaara@qt.io>
This commit is contained in:
Samuel Mira 2022-11-16 09:54:24 +02:00 committed by Jani Heikkinen
parent 0d08801da2
commit e3e40c44d3

View File

@ -95,11 +95,13 @@ public class QtLayout extends ViewGroup
insetLeft = rootInsets.getStableInsetLeft(); insetLeft = rootInsets.getStableInsetLeft();
insetTop = rootInsets.getStableInsetTop(); insetTop = rootInsets.getStableInsetTop();
int insetsWidth = rootInsets.getStableInsetRight() + rootInsets.getStableInsetLeft(); appWidth = appMetrics.widthPixels - rootInsets.getStableInsetRight() + rootInsets.getStableInsetLeft();
int insetsHeight = rootInsets.getStableInsetTop() + rootInsets.getStableInsetBottom();
appWidth = appMetrics.widthPixels - insetsWidth; if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
appHeight = appMetrics.heightPixels - insetsHeight; appHeight = appMetrics.heightPixels - rootInsets.getStableInsetTop();
} else {
appHeight = appMetrics.heightPixels - rootInsets.getStableInsetTop() + rootInsets.getStableInsetBottom();
}
final DisplayMetrics maxMetrics = new DisplayMetrics(); final DisplayMetrics maxMetrics = new DisplayMetrics();
display.getRealMetrics(maxMetrics); display.getRealMetrics(maxMetrics);
@ -123,21 +125,15 @@ public class QtLayout extends ViewGroup
final WindowMetrics maxMetrics = windowManager.getMaximumWindowMetrics(); final WindowMetrics maxMetrics = windowManager.getMaximumWindowMetrics();
final WindowInsets windowInsets = appMetrics.getWindowInsets(); final WindowInsets windowInsets = appMetrics.getWindowInsets();
Insets insets = windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.tappableElement()); Insets statusBarInsets = windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.statusBars());
Insets cutoutInsets = windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.displayCutout());
Insets imeInsets = windowInsets.getInsets(WindowInsets.Type.ime());
insetLeft = insets.left; insetLeft = cutoutInsets.left;
insetTop = insets.top; insetTop = statusBarInsets.top;
int insetsWidth = insets.right + insets.left; appWidth = w;
int insetsHeight = insets.top + insets.bottom; appHeight = h - imeInsets.bottom;
if (h == maxMetrics.getBounds().height()){
//when h == maxheight the system is ignoring insets
insetsWidth = insetsHeight = insetLeft = insetTop = 0;
}
appWidth = appMetrics.getBounds().width() - insetsWidth;
appHeight = appMetrics.getBounds().height() - insetsHeight;
maxWidth = maxMetrics.getBounds().width(); maxWidth = maxMetrics.getBounds().width();
maxHeight = maxMetrics.getBounds().height(); maxHeight = maxMetrics.getBounds().height();
@ -169,10 +165,11 @@ public class QtLayout extends ViewGroup
final int flag = final int flag =
activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN; activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN;
if (flag == WindowManager.LayoutParams.FLAG_FULLSCREEN) { if (flag == WindowManager.LayoutParams.FLAG_FULLSCREEN || h == maxHeight) {
// immersive mode uses the whole screen // immersive mode uses the whole screen
appWidth = maxWidth; appWidth = maxWidth;
appHeight = maxHeight; appHeight = maxHeight;
insetLeft = insetTop = 0;
} }
QtNative.setApplicationDisplayMetrics(maxWidth, maxHeight, insetLeft, QtNative.setApplicationDisplayMetrics(maxWidth, maxHeight, insetLeft,