adjust layouts and colors for Edge-to-Edge with transparent status bar as is default in Android 35+

This commit is contained in:
Philipp Crocoll
2025-07-22 15:16:28 +02:00
parent 87e979635b
commit 260bc8adb2
13 changed files with 183 additions and 63 deletions

View File

@@ -145,12 +145,14 @@ namespace keepass2android
protected override void OnCreate(Bundle savedInstanceState) { protected override void OnCreate(Bundle savedInstanceState) {
_design.ApplyTheme(); _design.ApplyTheme();
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.generate_password); SetContentView(Resource.Layout.generate_password);
SetResult(KeePass.ExitNormal); SetResult(KeePass.ExitNormal);
var prefs = GetPreferences(FileCreationMode.Private); new Util.InsetListener(FindViewById(Resource.Id.main_container)).Apply();
var prefs = GetPreferences(FileCreationMode.Private);

View File

@@ -15,6 +15,36 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>. along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Database;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Preferences;
using Android.Runtime;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.AppCompat.App;
using AndroidX.CoordinatorLayout.Widget;
using AndroidX.Core.Content;
using AndroidX.Core.View;
using AndroidX.DrawerLayout.Widget;
using Google.Android.Material.AppBar;
using Google.Android.Material.Dialog;
using Java.Lang;
using Java.Net;
using KeeChallenge;
using keepass2android;
using keepass2android.Io;
using keepass2android.Utils;
using Keepass2android.Pluginsdk;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using OtpKeyProv;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -23,49 +53,17 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
using keepass2android; using static Android.Locations.GpsStatus;
using Android.App;
using Android.Content;
using Android.Database;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using Java.Net;
using Android.Preferences;
using Android.Text;
using Android.Content.PM;
using Android.Graphics;
using AndroidX.AppCompat.App;
using AndroidX.CoordinatorLayout.Widget;
using AndroidX.Core.View;
using AndroidX.DrawerLayout.Widget;
using Google.Android.Material.AppBar;
using Google.Android.Material.Dialog;
using Java.Lang;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using Keepass2android.Pluginsdk;
using OtpKeyProv;
using keepass2android.Io;
using keepass2android.Utils;
using File = Java.IO.File;
using FileNotFoundException = Java.IO.FileNotFoundException;
using Object = Java.Lang.Object;
using Process = Android.OS.Process;
using KeeChallenge;
using AlertDialog = Android.App.AlertDialog; using AlertDialog = Android.App.AlertDialog;
using ClipboardManager = Android.Content.ClipboardManager; using ClipboardManager = Android.Content.ClipboardManager;
using Enum = System.Enum; using Enum = System.Enum;
using Exception = System.Exception; using Exception = System.Exception;
using File = Java.IO.File;
using FileNotFoundException = Java.IO.FileNotFoundException;
using Object = Java.Lang.Object;
using Process = Android.OS.Process;
using String = System.String; using String = System.String;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar; using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
using AndroidX.Core.Content;
namespace keepass2android namespace keepass2android
{ {
@@ -651,7 +649,7 @@ namespace keepass2android
_activityDesign.ApplyTheme(); _activityDesign.ApplyTheme();
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
_intentReceiver = new PasswordActivityBroadcastReceiver(this); _intentReceiver = new PasswordActivityBroadcastReceiver(this);
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.AddAction(Intent.ActionScreenOff); filter.AddAction(Intent.ActionScreenOff);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported); ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);
@@ -1165,7 +1163,9 @@ namespace keepass2android
changeDbButton.Click += (sender, args) => GoToFileSelectActivity(); changeDbButton.Click += (sender, args) => GoToFileSelectActivity();
Util.MoveBottomBarButtons(Resource.Id.change_db, Resource.Id.pass_ok, Resource.Id.bottom_bar, this); Util.MoveBottomBarButtons(Resource.Id.change_db, Resource.Id.pass_ok, Resource.Id.bottom_bar, this);
} Util.InsetListener.ForBottomElement(FindViewById(Resource.Id.bottom_bar)).Apply();
Util.InsetListener.ForTopElement(FindViewById(Resource.Id.appbar)).Apply();
}
private void OnOk(bool usedFingerprintUnlock = false) private void OnOk(bool usedFingerprintUnlock = false)
{ {

View File

@@ -81,8 +81,11 @@ namespace keepass2android
SetContentView(Resource.Layout.QuickUnlock); SetContentView(Resource.Layout.QuickUnlock);
Util.InsetListener.ForBottomElement(FindViewById(Resource.Id.bottom_bar)).Apply();
Util.InsetListener.ForTopElement(FindViewById(Resource.Id.appbar)).Apply();
var collapsingToolbar = FindViewById<CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar);
var collapsingToolbar = FindViewById<CollapsingToolbarLayout>(Resource.Id.collapsing_toolbar);
collapsingToolbar.SetTitle(GetString(Resource.String.QuickUnlock_prefs)); collapsingToolbar.SetTitle(GetString(Resource.String.QuickUnlock_prefs));
SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.toolbar)); SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.toolbar));

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true"> android:fitsSystemWindows="false">
<keepass2android.MeasuringLinearLayout <keepass2android.MeasuringLinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
@@ -17,7 +17,7 @@ android:fitsSystemWindows="true">
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:fitsSystemWindows="true"> android:fitsSystemWindows="false">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -28,7 +28,7 @@ android:fitsSystemWindows="true">
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed" app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true" android:fitsSystemWindows="false"
app:expandedTitleMarginStart="16dp" app:expandedTitleMarginStart="16dp"
app:expandedTitleMarginEnd="24dp" app:expandedTitleMarginEnd="24dp"
app:expandedTitleMarginBottom="20sp"> app:expandedTitleMarginBottom="20sp">

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_container"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:background="?android:attr/colorBackground" android:background="?android:attr/colorBackground"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
@@ -322,4 +323,3 @@
</ScrollView> </ScrollView>
</RelativeLayout> </RelativeLayout>

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<keepass2android.FixedDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true"> >
<!-- activity view --> <!-- activity view -->
<keepass2android.MeasuringLinearLayout <keepass2android.MeasuringLinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
@@ -17,14 +17,13 @@
android:id="@+id/main_content" android:id="@+id/main_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1">
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height" android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true" android:fitsSystemWindows="false"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"> android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout <com.google.android.material.appbar.CollapsingToolbarLayout
@@ -32,14 +31,17 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed" app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true" android:fitsSystemWindows="false"
app:expandedTitleMarginStart="48dp" app:collapsedTitleGravity="center"
app:expandedTitleGravity="bottom|left"
app:expandedTitleMarginStart="8dp"
app:expandedTitleMarginEnd="24dp" app:expandedTitleMarginEnd="24dp"
app:expandedTitleMarginBottom="20sp"> app:expandedTitleMarginBottom="20sp">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools" <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="false"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
<ImageView <ImageView
android:id="@+id/backdrop" android:id="@+id/backdrop"
@@ -52,7 +54,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginBottom="0sp" android:layout_marginBottom="0sp"
android:layout_marginLeft="48dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@@ -446,4 +448,4 @@
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</com.google.android.material.navigation.NavigationView> </com.google.android.material.navigation.NavigationView>
</keepass2android.FixedDrawerLayout> </androidx.drawerlayout.widget.DrawerLayout>

View File

@@ -0,0 +1,22 @@
<resources>
<style name="Kp2aTheme_ActionBar" parent="AppTheme.Primary">
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_BlueActionBar" parent="AppTheme.Secondary">
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_NoActionBar" parent="AppTheme.Primary.NoActionBar">
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_BlueNoActionBar" parent="AppTheme.Secondary.NoActionBar">
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@@ -0,0 +1,22 @@
<resources>
<style name="Kp2aTheme_ActionBar" parent="AppTheme.Primary">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_BlueActionBar" parent="AppTheme.Secondary">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_NoActionBar" parent="AppTheme.Primary.NoActionBar">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="Kp2aTheme_BlueNoActionBar" parent="AppTheme.Secondary.NoActionBar">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@@ -4,7 +4,7 @@
<dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="detail_backdrop_height">200dp</dimen> <dimen name="detail_backdrop_height">250dp</dimen>
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="splash_logo_width">79dp</dimen> <dimen name="splash_logo_width">79dp</dimen>

View File

@@ -253,12 +253,12 @@
<item name="android:statusBarColor">@color/statusbar_color_green</item></style> <item name="android:statusBarColor">@color/statusbar_color_green</item></style>
<style name="Kp2aTheme_BlueActionBar" parent="AppTheme.Secondary"></style> <style name="Kp2aTheme_BlueActionBar" parent="AppTheme.Secondary"></style>
<style name="Kp2aTheme_NoActionBar" parent="AppTheme.Primary.NoActionBar"> <style name="Kp2aTheme_NoActionBar" parent="AppTheme.Primary.NoActionBar">
<item name="android:statusBarColor">@color/statusbar_color_green</item> <item name="android:statusBarColor">@color/statusbar_color_green</item>
</style> </style>
<style name="Kp2aTheme_BlueNoActionBar" parent="AppTheme.Secondary.NoActionBar"> <style name="Kp2aTheme_BlueNoActionBar" parent="AppTheme.Secondary.NoActionBar">
</style> </style>
<style name="Widget.Kp2a.Toolbar" parent="Widget.Material3.Toolbar.OnSurface" /> <style name="Widget.Kp2a.Toolbar" parent="Widget.Material3.Toolbar.OnSurface" />

View File

@@ -35,7 +35,9 @@ using Android.Graphics.Drawables;
using Android.Hardware.Display; using Android.Hardware.Display;
using Android.Util; using Android.Util;
using Android.Views.InputMethods; using Android.Views.InputMethods;
using AndroidX.Core.View;
using AndroidX.Core.View.InputMethod; using AndroidX.Core.View.InputMethod;
using AndroidX.ViewPager2.Widget;
using Google.Android.Material.Dialog; using Google.Android.Material.Dialog;
using KeePass.Util; using KeePass.Util;
using keepass2android; using keepass2android;
@@ -738,7 +740,73 @@ namespace keepass2android
public class InsetListener: Java.Lang.Object, IOnApplyWindowInsetsListener
{
private View _targetView;
private readonly int _insetsType;
private int _initialPaddingLeft;
private int _initialPaddingTop;
private int _initialPaddingRight;
private int _initialPaddingBottom;
public bool EnabledPaddingLeft { get; set; } = true;
public bool EnablePaddingTop { get; set; } = true;
public bool EnablePaddingRight { get; set; } = true;
public bool EnablePaddingBottom { get; set; } = true;
public InsetListener(View targetView, int insetsType)
{
_targetView = targetView;
_insetsType = insetsType;
_initialPaddingLeft = targetView.PaddingLeft;
_initialPaddingTop = targetView.PaddingTop;
_initialPaddingRight = targetView.PaddingRight;
_initialPaddingBottom = targetView.PaddingBottom;
}
public InsetListener(View targetView): this(targetView, WindowInsetsCompat.Type.SystemBars())
{
}
public WindowInsetsCompat OnApplyWindowInsets(View v, WindowInsetsCompat insets)
{
var systemBarsInsets = insets.GetInsets(_insetsType);
_targetView.SetPadding(
_initialPaddingLeft + (EnabledPaddingLeft ? systemBarsInsets.Left : 0),
_initialPaddingTop + (EnablePaddingTop ? systemBarsInsets.Top : 0),
_initialPaddingRight + (EnablePaddingRight ? systemBarsInsets.Right : 0),
_initialPaddingBottom + (EnablePaddingBottom ? systemBarsInsets.Bottom : 0)
);
return insets;
}
public static InsetListener ForBottomElement(View view)
{
return new InsetListener(view, WindowInsetsCompat.Type.Ime() | WindowInsetsCompat.Type.SystemBars() | WindowInsetsCompat.Type.DisplayCutout())
{
EnablePaddingTop = false
};
}
public static InsetListener ForTopElement(View view)
{
return new InsetListener(view, WindowInsetsCompat.Type.SystemBars() | WindowInsetsCompat.Type.DisplayCutout())
{
EnablePaddingBottom = false
};
}
public void Apply()
{
ViewCompat.SetOnApplyWindowInsetsListener(_targetView, this);
}
}
public static void MoveBottomBarButtons(int btn1Id, int btn2Id, int bottomBarId, Activity context) public static void MoveBottomBarButtons(int btn1Id, int btn2Id, int bottomBarId, Activity context)
{ {

View File

@@ -1217,7 +1217,7 @@ namespace keepass2android
{ {
_design.ApplyTheme(); _design.ApplyTheme();
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
new Util.InsetListener(FindViewById(Resource.Id.settings)).Apply();
} }

View File

@@ -163,6 +163,7 @@ namespace keepass2android
{ {
_design.ApplyTheme(); _design.ApplyTheme();
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
new Util.InsetListener(FindViewById(Resource.Id.settings)).Apply();
} }