summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtLayout.java67
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp21
2 files changed, 50 insertions, 38 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 6c52a00422..04a0f6c378 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
@@ -50,6 +50,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
+import android.graphics.Insets;
public class QtLayout extends ViewGroup
{
@@ -93,14 +94,20 @@ public class QtLayout extends ViewGroup
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh)
{
- WindowInsets insets = getRootWindowInsets();
+ Activity activity = (Activity)getContext();
+ if (activity == null)
+ return;
- DisplayMetrics realMetrics = new DisplayMetrics();
Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
- ? ((Activity)getContext()).getWindowManager().getDefaultDisplay()
- : ((Activity)getContext()).getDisplay();
+ ? activity.getWindowManager().getDefaultDisplay()
+ : activity.getDisplay();
+
+ DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
+ DisplayMetrics appMetrics = new DisplayMetrics();
+ display.getMetrics(appMetrics);
+
if ((realMetrics.widthPixels > realMetrics.heightPixels) != (w > h)) {
// This is an intermediate state during display rotation.
// The new size is still reported for old orientation, while
@@ -112,34 +119,36 @@ public class QtLayout extends ViewGroup
return;
}
- boolean isFullScreenView = h == realMetrics.heightPixels;
- // The code uses insets for fullscreen mode only. However in practice
- // the insets can be reported incorrectly. Both on Android 6 and Android 11
- // a non-zero bottom inset is reported even when the
- // WindowManager.LayoutParams.FLAG_FULLSCREEN flag is set.
- // To avoid that, add an extra check for the fullscreen mode.
- // The insets-related logic is not removed for the case when
- // isFullScreenView == true, but hasFlagFullscreen == false, although
- // I can't get such case in my tests.
- final int windowFlags = ((Activity)getContext()).getWindow().getAttributes().flags;
- final boolean hasFlagFullscreen =
- (windowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
- int insetLeft =
- (isFullScreenView && !hasFlagFullscreen) ? insets.getSystemWindowInsetLeft() : 0;
- int insetTop =
- (isFullScreenView && !hasFlagFullscreen) ? insets.getSystemWindowInsetTop() : 0;
- int insetRight =
- (isFullScreenView && !hasFlagFullscreen) ? insets.getSystemWindowInsetRight() : 0;
- int insetBottom =
- (isFullScreenView && !hasFlagFullscreen) ? insets.getSystemWindowInsetBottom() : 0;
-
- int usableAreaWidth = w - insetLeft - insetRight;
- int usableAreaHeight = h - insetTop - insetBottom;
+ WindowInsets rootInsets = getRootWindowInsets();
+
+ int insetLeft = 0;
+ int insetTop = 0;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ Insets insets = rootInsets.getInsets(WindowInsets.Type.systemBars());
+ insetLeft = insets.left;
+ insetTop = insets.top;
+ } else {
+ insetLeft = rootInsets.getSystemWindowInsetLeft();
+ insetTop = rootInsets.getSystemWindowInsetTop();
+ }
+
+ int appWidthPixels = appMetrics.widthPixels;
+ int appHeightPixels = appMetrics.heightPixels;
+
+ final int flag =
+ activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN;
+
+ if (flag == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
+ // immersive mode uses the whole screen
+ appWidthPixels = realMetrics.widthPixels;
+ appHeightPixels = realMetrics.heightPixels;
+ }
QtNative.setApplicationDisplayMetrics(
realMetrics.widthPixels, realMetrics.heightPixels, insetLeft, insetTop,
- usableAreaWidth, usableAreaHeight, realMetrics.xdpi, realMetrics.ydpi,
- realMetrics.scaledDensity, realMetrics.density, display.getRefreshRate());
+ appWidthPixels, appHeightPixels, appMetrics.xdpi, appMetrics.ydpi,
+ appMetrics.scaledDensity, appMetrics.density, display.getRefreshRate());
int newRotation = display.getRotation();
if (m_ownDisplayRotation != m_activityDisplayRotation
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index 207ace0c12..68ca88b31e 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -657,24 +657,27 @@ static void setDisplayMetrics(JNIEnv * /*env*/, jclass /*clazz*/, jint screenWid
jint availableHeightPixels, jdouble xdpi, jdouble ydpi,
jdouble scaledDensity, jdouble density, jfloat refreshRate)
{
+ Q_UNUSED(availableLeftPixels)
+ Q_UNUSED(availableTopPixels)
+
m_availableWidthPixels = availableWidthPixels;
m_availableHeightPixels = availableHeightPixels;
m_scaledDensity = scaledDensity;
m_density = density;
+ const QSize screenSize(screenWidthPixels, screenHeightPixels);
+ // available geometry always starts from top left
+ const QRect availableGeometry(0, 0, availableWidthPixels, availableHeightPixels);
+ const QSize physicalSize(qRound(double(screenWidthPixels) / xdpi * 25.4),
+ qRound(double(screenHeightPixels) / ydpi * 25.4));
+
QMutexLocker lock(&m_platformMutex);
if (!m_androidPlatformIntegration) {
QAndroidPlatformIntegration::setDefaultDisplayMetrics(
- availableLeftPixels, availableTopPixels, availableWidthPixels,
- availableHeightPixels, qRound(double(screenWidthPixels) / xdpi * 25.4),
- qRound(double(screenHeightPixels) / ydpi * 25.4), screenWidthPixels,
- screenHeightPixels);
+ availableGeometry.left(), availableGeometry.top(), availableGeometry.width(),
+ availableGeometry.height(), physicalSize.width(), physicalSize.height(),
+ screenSize.width(), screenSize.height());
} else {
- const QSize physicalSize(qRound(double(screenWidthPixels) / xdpi * 25.4),
- qRound(double(screenHeightPixels) / ydpi * 25.4));
- const QSize screenSize(screenWidthPixels, screenHeightPixels);
- const QRect availableGeometry(availableLeftPixels, availableTopPixels,
- availableWidthPixels, availableHeightPixels);
m_androidPlatformIntegration->setScreenSizeParameters(physicalSize, screenSize,
availableGeometry);
m_androidPlatformIntegration->setRefreshRate(refreshRate);