From 2ce9140c6c5ba666b6cd48c48f9dfbfe875640fb Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 7 Jan 2025 18:33:29 +0200 Subject: [PATCH] Android: suppress deprecation warning for safe area APIs before Android R We already handle both cases of pre and post Android R APIs, so we can safely suppress the code using older API after extracting it to its own method. Change-Id: I3f5d6dab480c5fb32d35f615db719a4a0eb3f45d Reviewed-by: Petri Virkkunen --- .../org/qtproject/qt/android/QtWindow.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java index a9a7fa3f81b..9f7c520ef47 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java @@ -83,34 +83,9 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { int types = WindowInsets.Type.displayCutout() | WindowInsets.Type.systemBars(); safeInsets = insets.getInsets(types); } else { - int left = 0; - int top = 0; - int right = 0; - int bottom = 0; - - int visibility = view.getSystemUiVisibility(); - if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - left = insets.getSystemWindowInsetLeft(); - top = insets.getSystemWindowInsetTop(); - right = insets.getSystemWindowInsetRight(); - bottom = insets.getSystemWindowInsetBottom(); - } - - // Android 9 and 10 emulators don't seem to be able - // to handle this, but let's have the logic here anyway - DisplayCutout cutout = insets.getDisplayCutout(); - if (cutout != null) { - left = Math.max(left, cutout.getSafeInsetLeft()); - top = Math.max(top, cutout.getSafeInsetTop()); - right = Math.max(right, cutout.getSafeInsetRight()); - bottom = Math.max(bottom, cutout.getSafeInsetBottom()); - } - - safeInsets = Insets.of(left, top, right, bottom); + safeInsets = getSafeInsetsPreAndroidR(view, insets); } - QtNative.runAction(() -> safeAreaMarginsChanged(safeInsets, getId())); - return insets; }); @@ -118,6 +93,35 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { } } + @SuppressWarnings("deprecation") + Insets getSafeInsetsPreAndroidR(View view, WindowInsets insets) + { + int left = 0; + int top = 0; + int right = 0; + int bottom = 0; + + int visibility = view.getSystemUiVisibility(); + if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + left = insets.getSystemWindowInsetLeft(); + top = insets.getSystemWindowInsetTop(); + right = insets.getSystemWindowInsetRight(); + bottom = insets.getSystemWindowInsetBottom(); + } + + // Android 9 and 10 emulators don't seem to be able + // to handle this, but let's have the logic here anyway + DisplayCutout cutout = insets.getDisplayCutout(); + if (cutout != null) { + left = Math.max(left, cutout.getSafeInsetLeft()); + top = Math.max(top, cutout.getSafeInsetTop()); + right = Math.max(right, cutout.getSafeInsetRight()); + bottom = Math.max(bottom, cutout.getSafeInsetBottom()); + } + + return Insets.of(left, top, right, bottom); + } + @UsedFromNativeCode void setVisible(boolean visible) { QtNative.runAction(() -> {