Android: Add left and right margins and handle cutout in the MainMenu
This commit is contained in:
parent
612397be6b
commit
3286fd154d
@ -178,6 +178,34 @@ public class NymeaAppActivity extends QtActivity
|
||||
return windowInsets.getStableInsetBottom();
|
||||
}
|
||||
|
||||
public int leftPadding() {
|
||||
WindowInsets windowInsets = getWindow().getDecorView().getRootWindowInsets();
|
||||
if (windowInsets == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Insets insets = windowInsets.getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
|
||||
return insets != null ? insets.left : 0;
|
||||
}
|
||||
|
||||
return windowInsets.getStableInsetLeft();
|
||||
}
|
||||
|
||||
public int rightPadding() {
|
||||
WindowInsets windowInsets = getWindow().getDecorView().getRootWindowInsets();
|
||||
if (windowInsets == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Insets insets = windowInsets.getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
|
||||
return insets != null ? insets.right : 0;
|
||||
}
|
||||
|
||||
return windowInsets.getStableInsetRight();
|
||||
}
|
||||
|
||||
private void logStaticInitClassesMetadata() {
|
||||
try {
|
||||
ApplicationInfo appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
|
||||
|
||||
@ -283,11 +283,15 @@ void PlatformHelperAndroid::updateSafeAreaPadding()
|
||||
{
|
||||
int topPaddingPx = 0;
|
||||
int bottomPaddingPx = 0;
|
||||
int leftPaddingPx = 0;
|
||||
int rightPaddingPx = 0;
|
||||
|
||||
QJniObject context = QNativeInterface::QAndroidApplication::context();
|
||||
if (context.isValid()) {
|
||||
topPaddingPx = context.callMethod<jint>("topPadding", "()I");
|
||||
bottomPaddingPx = context.callMethod<jint>("bottomPadding", "()I");
|
||||
leftPaddingPx = context.callMethod<jint>("leftPadding", "()I");
|
||||
rightPaddingPx = context.callMethod<jint>("rightPadding", "()I");
|
||||
}
|
||||
|
||||
QScreen *screen = qApp->primaryScreen();
|
||||
@ -296,7 +300,10 @@ void PlatformHelperAndroid::updateSafeAreaPadding()
|
||||
dpr = 1.0;
|
||||
}
|
||||
|
||||
setSafeAreaPadding(qRound(topPaddingPx / dpr), 0, qRound(bottomPaddingPx / dpr), 0);
|
||||
setSafeAreaPadding(qRound(topPaddingPx / dpr),
|
||||
qRound(rightPaddingPx / dpr),
|
||||
qRound(bottomPaddingPx / dpr),
|
||||
qRound(leftPaddingPx / dpr));
|
||||
}
|
||||
|
||||
int PlatformHelperAndroid::topPadding() const
|
||||
@ -309,6 +316,16 @@ int PlatformHelperAndroid::bottomPadding() const
|
||||
return PlatformHelper::bottomPadding();
|
||||
}
|
||||
|
||||
int PlatformHelperAndroid::leftPadding() const
|
||||
{
|
||||
return PlatformHelper::leftPadding();
|
||||
}
|
||||
|
||||
int PlatformHelperAndroid::rightPadding() const
|
||||
{
|
||||
return PlatformHelper::rightPadding();
|
||||
}
|
||||
|
||||
bool PlatformHelperAndroid::darkModeEnabled() const
|
||||
{
|
||||
return QNativeInterface::QAndroidApplication::context().callMethod<jboolean>("darkModeEnabled");
|
||||
|
||||
@ -68,6 +68,7 @@ Drawer {
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: PlatformHelper.topPadding
|
||||
anchors.leftMargin: PlatformHelper.leftPadding
|
||||
spacing: 0
|
||||
|
||||
Rectangle {
|
||||
|
||||
Reference in New Issue
Block a user