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 <petri.virkkunen@qt.io>
This commit is contained in:
Assam Boudjelthia 2025-01-07 18:33:29 +02:00
parent 622133ace2
commit 2ce9140c6c

View File

@ -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(() -> {