]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Fix edge-to-edge layout issues with settings and app selection
authorTobias Brunner <tobias@strongswan.org>
Thu, 30 Oct 2025 15:36:45 +0000 (16:36 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 30 Oct 2025 15:55:05 +0000 (16:55 +0100)
Using FrameLayout for the settings instead of the recommended
FragmentContainerView because the latter makes handling insets more
complicated (fitsSystemWindows doesn't work as the fragment is responsible
for handling insets but how that should work with PreferenceFragmentCompat
is unclear).

Fixes: 2404b2bee632 ("android: Apply UI changes for edge-to-edge views in Android 15+")
src/frontends/android/app/src/main/java/org/strongswan/android/ui/SelectedApplicationsActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/SelectedApplicationsListFragment.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/SettingsActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificateImportActivity.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificatesActivity.java
src/frontends/android/app/src/main/res/layout/selected_applications_activity.xml [new file with mode: 0644]
src/frontends/android/app/src/main/res/layout/settings_activity.xml [new file with mode: 0644]

index b3c23ffc86333f2ad4765b56f72e7e1ff04b6a5f..d7a606d7f546179cc34ae8255208d6f005a9642e 100644 (file)
@@ -20,7 +20,9 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.view.MenuItem;
 
+import org.strongswan.android.R;
 import org.strongswan.android.data.VpnProfileDataSource;
+import org.strongswan.android.utils.Utils;
 
 import androidx.activity.OnBackPressedCallback;
 import androidx.annotation.Nullable;
@@ -38,8 +40,9 @@ public class SelectedApplicationsActivity extends AppCompatActivity
        protected void onCreate(@Nullable Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
+               setContentView(R.layout.selected_applications_activity);
                WindowCompat.enableEdgeToEdge(getWindow());
-               WindowCompat.setDecorFitsSystemWindows(getWindow(), true);
+               Utils.applyWindowInsetsAsMarginsForLists(findViewById(R.id.fragment_container));
 
                ActionBar actionBar = getSupportActionBar();
                actionBar.setDisplayHomeAsUpEnabled(true);
@@ -59,7 +62,7 @@ public class SelectedApplicationsActivity extends AppCompatActivity
                if (mApps == null)
                {
                        mApps = new SelectedApplicationsListFragment();
-                       fm.beginTransaction().add(android.R.id.content, mApps, LIST_TAG).commit();
+                       fm.beginTransaction().add(R.id.fragment_container, mApps, LIST_TAG).commit();
                }
        }
 
index 89b5815301e8453b4c411d8f0e5e16a1dd4f3f2f..013a7adc5f24cd08dee2732ab40607c545d3d4aa 100644 (file)
@@ -34,6 +34,7 @@ import org.strongswan.android.R;
 import org.strongswan.android.data.VpnProfileDataSource;
 import org.strongswan.android.ui.adapter.SelectedApplicationEntry;
 import org.strongswan.android.ui.adapter.SelectedApplicationsAdapter;
+import org.strongswan.android.utils.Utils;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -61,6 +62,9 @@ public class SelectedApplicationsListFragment extends ListFragment implements Me
                super.onViewCreated(view, savedInstanceState);
                requireActivity().addMenuProvider(this, getViewLifecycleOwner());
 
+               getListView().setClipToPadding(false);
+               Utils.applyWindowInsetsAsPaddingForLists(getListView());
+
                final boolean readOnly = getActivity().getIntent().getBooleanExtra(VpnProfileDataSource.KEY_READ_ONLY, false);
                getListView().setChoiceMode(readOnly ? ListView.CHOICE_MODE_NONE : ListView.CHOICE_MODE_MULTIPLE);
 
index eec782fb71b994ac3faae153eded680cca03dcad..d3cd8a8d5ed7ed9014e73de909cdce6652d8cefc 100644 (file)
@@ -19,6 +19,8 @@ package org.strongswan.android.ui;
 import android.os.Bundle;
 import android.view.MenuItem;
 
+import org.strongswan.android.R;
+
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.core.view.WindowCompat;
 
@@ -29,14 +31,18 @@ public class SettingsActivity extends AppCompatActivity
        protected void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
+               setContentView(R.layout.settings_activity);
                WindowCompat.enableEdgeToEdge(getWindow());
-               WindowCompat.setDecorFitsSystemWindows(getWindow(), true);
 
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 
-               getSupportFragmentManager().beginTransaction()
-                                                       .replace(android.R.id.content, new SettingsFragment())
-                                                       .commit();
+               if (savedInstanceState == null)
+               {
+                       getSupportFragmentManager().beginTransaction()
+                               .setReorderingAllowed(true)
+                               .add(R.id.fragment_container, SettingsFragment.class, null)
+                               .commit();
+               }
        }
 
        @Override
index a794e93bae720b7ba28b349bda870eeff2b61836..322e21e2c0ab93010c37424f6d4a23e5073cf915 100644 (file)
@@ -41,7 +41,6 @@ import androidx.activity.result.contract.ActivityResultContracts;
 import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.app.AppCompatDialogFragment;
-import androidx.core.view.WindowCompat;
 import androidx.fragment.app.FragmentTransaction;
 
 public class TrustedCertificateImportActivity extends AppCompatActivity
index c9e24288103db5e5ef206c54feb96b19e032eaf4..a6fd0bc09c73684a0b36c27e66e9b48f928e4f4b 100644 (file)
@@ -33,7 +33,6 @@ import org.strongswan.android.logic.TrustedCertificateManager;
 import org.strongswan.android.logic.TrustedCertificateManager.TrustedCertificateSource;
 import org.strongswan.android.security.TrustedCertificateEntry;
 import org.strongswan.android.ui.CertificateDeleteConfirmationDialog.OnCertificateDeleteListener;
-import org.strongswan.android.utils.Utils;
 
 import java.security.KeyStore;
 
diff --git a/src/frontends/android/app/src/main/res/layout/selected_applications_activity.xml b/src/frontends/android/app/src/main/res/layout/selected_applications_activity.xml
new file mode 100644 (file)
index 0000000..f2bed6f
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2025 Tobias Brunner
+
+    Copyright (C) secunet Security Networks AG
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<androidx.fragment.app.FragmentContainerView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/fragment_container"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" />
diff --git a/src/frontends/android/app/src/main/res/layout/settings_activity.xml b/src/frontends/android/app/src/main/res/layout/settings_activity.xml
new file mode 100644 (file)
index 0000000..d8eccc4
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2025 Tobias Brunner
+
+    Copyright (C) secunet Security Networks AG
+
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+
+    This program is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+-->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/fragment_container"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:fitsSystemWindows="true" />