summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2022-11-16 09:54:24 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2022-12-12 10:23:31 +0000
commite3e40c44d3f998a433a6a1080297c5f28e9a768f (patch)
tree1b5d9c6cffd99eb7276376ce6a9328f8a75edb6b
parent0d08801da2a76d2e8ce098cc2de435c78efff72f (diff)
Android: Fix incorrect dimensions - part 2v6.4.26.4.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>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtLayout.java33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
index 3c01c76400..98d3deca8c 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
@@ -95,11 +95,13 @@ public class QtLayout extends ViewGroup
insetLeft = rootInsets.getStableInsetLeft();
insetTop = rootInsets.getStableInsetTop();
- int insetsWidth = rootInsets.getStableInsetRight() + rootInsets.getStableInsetLeft();
- int insetsHeight = rootInsets.getStableInsetTop() + rootInsets.getStableInsetBottom();
+ appWidth = appMetrics.widthPixels - rootInsets.getStableInsetRight() + rootInsets.getStableInsetLeft();
- appWidth = appMetrics.widthPixels - insetsWidth;
- appHeight = appMetrics.heightPixels - insetsHeight;
+ if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
+ appHeight = appMetrics.heightPixels - rootInsets.getStableInsetTop();
+ } else {
+ appHeight = appMetrics.heightPixels - rootInsets.getStableInsetTop() + rootInsets.getStableInsetBottom();
+ }
final DisplayMetrics maxMetrics = new DisplayMetrics();
display.getRealMetrics(maxMetrics);
@@ -123,21 +125,15 @@ public class QtLayout extends ViewGroup
final WindowMetrics maxMetrics = windowManager.getMaximumWindowMetrics();
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;
- insetTop = insets.top;
+ insetLeft = cutoutInsets.left;
+ insetTop = statusBarInsets.top;
- int insetsWidth = insets.right + insets.left;
- int insetsHeight = insets.top + insets.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;
+ appWidth = w;
+ appHeight = h - imeInsets.bottom;
maxWidth = maxMetrics.getBounds().width();
maxHeight = maxMetrics.getBounds().height();
@@ -169,10 +165,11 @@ public class QtLayout extends ViewGroup
final int flag =
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
appWidth = maxWidth;
appHeight = maxHeight;
+ insetLeft = insetTop = 0;
}
QtNative.setApplicationDisplayMetrics(maxWidth, maxHeight, insetLeft,