summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2022-09-05 20:57:56 +0300
committerSamuel Mira <samuel.mira@qt.io>2022-09-17 08:42:48 +0000
commit072387edecb2269097821e35f1f232da6c657650 (patch)
treea4b165c57b913b1fc9ae12d2a1be7c325f09b1c3 /src/android
parent66485a4c5d0d65502ec4d99f338391f44e3004fd (diff)
Android: Fix flickering on window resize and show keyboard
Changed to use display getMetrics which will return the size of the application window, and use getRealMetrics to obtain the size of the largest region accessible to the app. I updated the fullscreen mode to use the new sizes. Task-number: QTBUG-41170 Task-number: QTBUG-66727 Pick-to: 6.4 6.3 6.2 5.15 Change-Id: Ic25555ed2e1b910b3fdbc0f3a31e3a19763a04eb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtLayout.java67
1 files changed, 38 insertions, 29 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 a0c1f4b2af..a9059fb188 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java
@@ -14,6 +14,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
{
@@ -57,14 +58,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
@@ -76,34 +83,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