Skip to content

Commit

Permalink
Android: Fix incorrect dimensions - part 2
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit bb629a2)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 89725106ed8b0f0991adacdf0189523f89cec02b)
Reviewed-by: Akseli Salovaara <[email protected]>
  • Loading branch information
samueljosemira authored and jaheikk committed Dec 12, 2022
1 parent 0d08801 commit e3e40c4
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/android/jar/src/org/qtproject/qt/android/QtLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ protected void onSizeChanged (int w, int h, int oldw, int oldh)
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);
Expand All @@ -123,21 +125,15 @@ protected void onSizeChanged (int w, int h, int oldw, int oldh)
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();
Expand Down Expand Up @@ -169,10 +165,11 @@ protected void onSizeChanged (int w, int h, int oldw, int oldh)
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,
Expand Down

0 comments on commit e3e40c4

Please sign in to comment.