Android: Make Edge To Edge work again for SDK >= 35
This commit is contained in:
parent
c5797ffc44
commit
8736717370
@ -29,6 +29,7 @@
|
|||||||
#include <QtCore/private/qandroidextras_p.h>
|
#include <QtCore/private/qandroidextras_p.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QJniObject>
|
#include <QJniObject>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
// WindowManager.LayoutParams
|
// WindowManager.LayoutParams
|
||||||
#define FLAG_TRANSLUCENT_STATUS 0x04000000
|
#define FLAG_TRANSLUCENT_STATUS 0x04000000
|
||||||
@ -89,8 +90,20 @@ PlatformHelperAndroid::PlatformHelperAndroid(QObject *parent) : PlatformHelper(p
|
|||||||
qCritical() << "----> Application state changed" << state;
|
qCritical() << "----> Application state changed" << state;
|
||||||
if (state == Qt::ApplicationActive) {
|
if (state == Qt::ApplicationActive) {
|
||||||
emit locationServicesEnabledChanged();
|
emit locationServicesEnabledChanged();
|
||||||
|
updateSafeAreaPadding();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (QScreen *screen = qApp->primaryScreen()) {
|
||||||
|
connect(screen, &QScreen::orientationChanged, this, [this](Qt::ScreenOrientation){
|
||||||
|
updateSafeAreaPadding();
|
||||||
|
});
|
||||||
|
connect(screen, &QScreen::availableGeometryChanged, this, [this](const QRect &){
|
||||||
|
updateSafeAreaPadding();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, &PlatformHelperAndroid::updateSafeAreaPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformHelperAndroid::hideSplashScreen()
|
void PlatformHelperAndroid::hideSplashScreen()
|
||||||
@ -266,26 +279,34 @@ void PlatformHelperAndroid::setBottomPanelTheme(Theme theme)
|
|||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformHelperAndroid::updateSafeAreaPadding()
|
||||||
|
{
|
||||||
|
int topPaddingPx = 0;
|
||||||
|
int bottomPaddingPx = 0;
|
||||||
|
|
||||||
|
QJniObject context = QNativeInterface::QAndroidApplication::context();
|
||||||
|
if (context.isValid()) {
|
||||||
|
topPaddingPx = context.callMethod<jint>("topPadding", "()I");
|
||||||
|
bottomPaddingPx = context.callMethod<jint>("bottomPadding", "()I");
|
||||||
|
}
|
||||||
|
|
||||||
|
QScreen *screen = qApp->primaryScreen();
|
||||||
|
qreal dpr = screen ? screen->devicePixelRatio() : 1.0;
|
||||||
|
if (dpr <= 0.0) {
|
||||||
|
dpr = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSafeAreaPadding(qRound(topPaddingPx / dpr), 0, qRound(bottomPaddingPx / dpr), 0);
|
||||||
|
}
|
||||||
|
|
||||||
int PlatformHelperAndroid::topPadding() const
|
int PlatformHelperAndroid::topPadding() const
|
||||||
{
|
{
|
||||||
// Edge to edge has been forced since android SDK 35
|
return PlatformHelper::topPadding();
|
||||||
// We don't want to handle it in earlied versions.
|
|
||||||
// if (QtAndroid::androidSdkVersion() < 35)
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
//return QNativeInterface::QAndroidApplication::context().callMethod<jint>("topPadding") / QApplication::primaryScreen()->devicePixelRatio();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlatformHelperAndroid::bottomPadding() const
|
int PlatformHelperAndroid::bottomPadding() const
|
||||||
{
|
{
|
||||||
// Edge to edge has been forced since android SDK 35
|
return PlatformHelper::bottomPadding();
|
||||||
// We don't want to handle it in earlied versions.
|
|
||||||
// if (QtAndroid::androidSdkVersion() < 35)
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
// return QNativeInterface::QAndroidApplication::context().callMethod<jint>("bottomPadding") / QApplication::primaryScreen()->devicePixelRatio();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlatformHelperAndroid::darkModeEnabled() const
|
bool PlatformHelperAndroid::darkModeEnabled() const
|
||||||
|
|||||||
@ -68,6 +68,9 @@ public:
|
|||||||
static void notificationActionReceivedJNI(JNIEnv *env, jobject /*thiz*/, jstring data);
|
static void notificationActionReceivedJNI(JNIEnv *env, jobject /*thiz*/, jstring data);
|
||||||
static void locationServicesEnabledChangedJNI();
|
static void locationServicesEnabledChangedJNI();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateSafeAreaPadding();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLATFORMHELPERANDROID_H
|
#endif // PLATFORMHELPERANDROID_H
|
||||||
|
|||||||
Reference in New Issue
Block a user