diff --git a/src/keepass2android-appSdkStyle/AboutActivity.cs b/src/keepass2android-appSdkStyle/AboutActivity.cs index 11029c600..e0a8cf3e1 100644 --- a/src/keepass2android-appSdkStyle/AboutActivity.cs +++ b/src/keepass2android-appSdkStyle/AboutActivity.cs @@ -21,10 +21,7 @@ protected override void OnResume() { if ((_dialog == null) || (_dialog.IsShowing == false)) { - if (new ActivityDesign(this).UseDarkTheme) - _dialog = new AboutDialog(this, Android.Resource.Style.ThemeHoloNoActionBarFullscreen); - else - _dialog = new AboutDialog(this, Android.Resource.Style.ThemeHoloLightNoActionBarFullscreen); + _dialog = new AboutDialog(this); _dialog.SetOnDismissListener(this); _dialog.Show(); } diff --git a/src/keepass2android-appSdkStyle/LifecycleAwareActivity.cs b/src/keepass2android-appSdkStyle/LifecycleAwareActivity.cs index 5b0cee9f8..dd67ad3e3 100644 --- a/src/keepass2android-appSdkStyle/LifecycleAwareActivity.cs +++ b/src/keepass2android-appSdkStyle/LifecycleAwareActivity.cs @@ -24,33 +24,36 @@ You should have received a copy of the GNU General Public License namespace keepass2android { - - public abstract class LifecycleAwareActivity : AndroidX.AppCompat.App.AppCompatActivity + + public abstract class LifecycleAwareActivity : AndroidX.AppCompat.App.AppCompatActivity { - protected override void AttachBaseContext(Context baseContext) - { - base.AttachBaseContext(LocaleManager.setLocale(baseContext)); - } - protected LifecycleAwareActivity (IntPtr javaReference, JniHandleOwnership transfer) - : base(javaReference, transfer) - { - - } - - protected LifecycleAwareActivity() - { - } - - - string _className; - string ClassName - { - get { - if (_className == null) - _className = GetType().Name; - return _className; - } - } + protected override void AttachBaseContext(Context baseContext) + { + base.AttachBaseContext(LocaleManager.setLocale(baseContext)); + } + + protected LifecycleAwareActivity(IntPtr javaReference, JniHandleOwnership transfer) + : base(javaReference, transfer) + { + + } + + protected LifecycleAwareActivity() + { + } + + + string _className; + + string ClassName + { + get + { + if (_className == null) + _className = GetType().Name; + return _className; + } + } public string MyDebugName { @@ -60,60 +63,87 @@ public string MyDebugName private static int staticCount = 0; private int ID = staticCount++; + protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); Kp2aLog.Log(ClassName + ".OnNewIntent " + ID); - } + } + + public Action? OnCreateListener { get; set; } + public Action? OnSaveInstanceStateListener { get; set; } + + public Func? OnSupportNavigateUpListener { get; set; } + + public override bool OnSupportNavigateUp() + { + bool baseRes = base.OnSupportNavigateUp(); + bool? res = OnSupportNavigateUpListener?.Invoke(); + if (res != null) + return res.Value; + return baseRes; + } + + public Action? OnResumeListener { get; set; } protected override void OnResume() - { - base.OnResume(); - Kp2aLog.Log(ClassName+".OnResume " + ID); - if (App.Kp2a.CurrentDb== null) - { - Kp2aLog.Log(" DB null" + " " + ID); - } - else - { - Kp2aLog.Log(" DatabaseIsUnlocked=" + App.Kp2a.DatabaseIsUnlocked + " " + ID); - } - } - - protected override void OnStart() - { - ProgressTask.SetNewActiveActivity(this); - base.OnStart(); - Kp2aLog.Log(ClassName+".OnStart" + " " + ID); - } - - protected override void OnCreate(Bundle bundle) - { - - base.OnCreate(bundle); - - Kp2aLog.Log(ClassName+".OnCreate" + " " + ID); - Kp2aLog.Log(ClassName+":apptask="+Intent.GetStringExtra("KP2A_APP_TASK_TYPE") + " " + ID); - } - - protected override void OnDestroy() - { - base.OnDestroy(); - Kp2aLog.Log(ClassName+".OnDestroy"+IsFinishing.ToString() + " " + ID); - } - - protected override void OnPause() - { - base.OnPause(); - Kp2aLog.Log(ClassName+".OnPause" + " " + ID); - } - - protected override void OnStop() - { - base.OnStop(); - Kp2aLog.Log(ClassName+".OnStop" + " " + ID); - ProgressTask.RemoveActiveActivity(this); + { + base.OnResume(); + OnResumeListener?.Invoke(); + + Kp2aLog.Log(ClassName + ".OnResume " + ID); + if (App.Kp2a.CurrentDb == null) + { + Kp2aLog.Log(" DB null" + " " + ID); + } + else + { + Kp2aLog.Log(" DatabaseIsUnlocked=" + App.Kp2a.DatabaseIsUnlocked + " " + ID); + } + } + + protected override void OnStart() + { + ProgressTask.SetNewActiveActivity(this); + base.OnStart(); + Kp2aLog.Log(ClassName + ".OnStart" + " " + ID); + } + + protected override void OnCreate(Bundle bundle) + { + + base.OnCreate(bundle); + + OnCreateListener?.Invoke(bundle); + + Kp2aLog.Log(ClassName + ".OnCreate" + " " + ID); + Kp2aLog.Log(ClassName + ":apptask=" + Intent.GetStringExtra("KP2A_APP_TASK_TYPE") + " " + ID); + } + + protected override void OnDestroy() + { + base.OnDestroy(); + Kp2aLog.Log(ClassName + ".OnDestroy" + IsFinishing.ToString() + " " + ID); + } + + protected override void OnPause() + { + base.OnPause(); + Kp2aLog.Log(ClassName + ".OnPause" + " " + ID); + } + + protected override void OnStop() + { + base.OnStop(); + Kp2aLog.Log(ClassName + ".OnStop" + " " + ID); + ProgressTask.RemoveActiveActivity(this); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + OnSaveInstanceStateListener?.Invoke(outState); } - } + } } diff --git a/src/keepass2android-appSdkStyle/Resources/layout/database_kdf_settings.xml b/src/keepass2android-appSdkStyle/Resources/layout/database_kdf_settings.xml new file mode 100644 index 000000000..fe262d2d8 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/layout/database_kdf_settings.xml @@ -0,0 +1,32 @@ + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/layout/preference.axml b/src/keepass2android-appSdkStyle/Resources/layout/preference.axml index 3072ae609..6d12ab00e 100644 --- a/src/keepass2android-appSdkStyle/Resources/layout/preference.axml +++ b/src/keepass2android-appSdkStyle/Resources/layout/preference.axml @@ -1,16 +1,9 @@ - - + + - - - \ No newline at end of file + android:layout_height="match_parent" /> + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/values-night/colors.xml b/src/keepass2android-appSdkStyle/Resources/values-night/colors.xml new file mode 100644 index 000000000..d324ef63c --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/values-night/colors.xml @@ -0,0 +1,143 @@ + + #ACE668 + #1E3700 + #84BB43 + #132600 + #99CBFF + #003355 + #006DAE + #FFFFFF + #4CF0B1 + #003825 + #00C48B + #002819 + #FFB4AB + #690005 + #93000A + #FFDAD6 + #11150C + #E1E4D6 + #11150C + #E1E4D6 + #424939 + #C2C9B4 + #8C9380 + #424939 + #000000 + #E1E4D6 + #2E3228 + #3E6A00 + #B9F474 + #0F2000 + #9ED75B + #2E4F00 + #CFE5FF + #001D34 + #99CBFF + #004A78 + #5DFDBE + #002114 + #36E0A3 + #005138 + #11150C + #373A31 + #0C0F08 + #191D14 + #1D2118 + #282B22 + #32362C + #ACE668 + #122500 + #84BB43 + #000000 + #A2CFFF + #00182B + #3F96DE + #000000 + #4CF0B1 + #002618 + #00C48B + #000000 + #FFBAB1 + #370001 + #FF5449 + #000000 + #11150C + #E1E4D6 + #11150C + #FAFCEE + #424939 + #C7CDB8 + #9FA592 + #7F8673 + #000000 + #E1E4D6 + #282B22 + #2F5100 + #B9F474 + #081400 + #9ED75B + #223D00 + #CFE5FF + #001223 + #99CBFF + #00395E + #5DFDBE + #00150C + #36E0A3 + #003F2A + #11150C + #373A31 + #0C0F08 + #191D14 + #1D2118 + #282B22 + #32362C + #F4FFE0 + #000000 + #A2DC5F + #000000 + #FAFAFF + #000000 + #A2CFFF + #000000 + #EEFFF3 + #000000 + #3CE4A7 + #000000 + #FFF9F9 + #000000 + #FFBAB1 + #000000 + #11150C + #E1E4D6 + #11150C + #FFFFFF + #424939 + #F7FEE7 + #C7CDB8 + #C7CDB8 + #000000 + #E1E4D6 + #000000 + #1A3000 + #BDF978 + #000000 + #A2DC5F + #0C1A00 + #D7E9FF + #000000 + #A2CFFF + #00182B + #79FFC6 + #000000 + #3CE4A7 + #001B10 + #11150C + #373A31 + #0C0F08 + #191D14 + #1D2118 + #282B22 + #32362C + diff --git a/src/keepass2android-appSdkStyle/Resources/values/colors_kp2a.xml b/src/keepass2android-appSdkStyle/Resources/values/colors_kp2a.xml new file mode 100644 index 000000000..1cec8d524 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/values/colors_kp2a.xml @@ -0,0 +1,46 @@ + + + + + #fff + #0000 + + #8bc34a + #548a2e + #0277bd + #015080 + + #0000dd + #333333 + #00555555 + #000000 + #a8a8a8 + #303030 + + #a8a8a8 + + #31b6e7 + #4f7a8a + + #f4511e + #42000000 + #009688 + + diff --git a/src/keepass2android-appSdkStyle/Resources/values/themes.xml b/src/keepass2android-appSdkStyle/Resources/values/themes.xml new file mode 100644 index 000000000..71344400c --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/values/themes.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app.xml new file mode 100644 index 000000000..ea5b70c30 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_debug.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_debug.xml new file mode 100644 index 000000000..f5aab5282 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_debug.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_display.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_display.xml new file mode 100644 index 000000000..01b99365b --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_display.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_file_handling.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_file_handling.xml new file mode 100644 index 000000000..98b85e90b --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_file_handling.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access.xml new file mode 100644 index 000000000..4cc843f90 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill.xml new file mode 100644 index 000000000..e0a75584b --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill_totp.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill_totp.xml new file mode 100644 index 000000000..34bdde6c2 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_autofill_totp.xml @@ -0,0 +1,30 @@ + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_keyboard_switch.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_keyboard_switch.xml new file mode 100644 index 000000000..b3c1f6157 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_password_access_keyboard_switch.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_quick_unlock.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_quick_unlock.xml new file mode 100644 index 000000000..5c676c5f2 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_quick_unlock.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_security.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_security.xml new file mode 100644 index 000000000..10844852d --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_security.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_app_traytotp.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_traytotp.xml new file mode 100644 index 000000000..4d1e2b3df --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_app_traytotp.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_database.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_database.xml new file mode 100644 index 000000000..97a8d1e34 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_database.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/pref_database_key_deriv_func.xml b/src/keepass2android-appSdkStyle/Resources/xml/pref_database_key_deriv_func.xml new file mode 100644 index 000000000..f2f49adb6 --- /dev/null +++ b/src/keepass2android-appSdkStyle/Resources/xml/pref_database_key_deriv_func.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/Resources/xml/preferences.xml b/src/keepass2android-appSdkStyle/Resources/xml/preferences.xml index 71daf0a28..7747d4506 100644 --- a/src/keepass2android-appSdkStyle/Resources/xml/preferences.xml +++ b/src/keepass2android-appSdkStyle/Resources/xml/preferences.xml @@ -2,7 +2,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - + \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/keepass2android-appSdkStyle.csproj b/src/keepass2android-appSdkStyle/keepass2android-appSdkStyle.csproj index 51387542e..2c3b00686 100644 --- a/src/keepass2android-appSdkStyle/keepass2android-appSdkStyle.csproj +++ b/src/keepass2android-appSdkStyle/keepass2android-appSdkStyle.csproj @@ -551,7 +551,7 @@ - + @@ -695,7 +695,7 @@ - + @@ -705,6 +705,9 @@ + + + diff --git a/src/keepass2android-appSdkStyle/settings/DatabaseSettingsActivity.cs b/src/keepass2android-appSdkStyle/settings/DatabaseSettingsActivity.cs index cfb726aa1..c2de2a241 100644 --- a/src/keepass2android-appSdkStyle/settings/DatabaseSettingsActivity.cs +++ b/src/keepass2android-appSdkStyle/settings/DatabaseSettingsActivity.cs @@ -25,7 +25,6 @@ You should have received a copy of the GNU General Public License using Android.Content.PM; using Android.OS; using Android.Widget; -using Android.Preferences; using Android.Provider; using Android.Views.Autofill; using Java.IO; @@ -40,856 +39,12 @@ You should have received a copy of the GNU General Public License using KeePassLib.Cryptography.KeyDerivation; using KeePassLib.Interfaces; using System.Collections.Generic; +using AndroidX.Preference; using keepass2android_appSdkStyle; namespace keepass2android { - //http://stackoverflow.com/a/27422401/292233 -#pragma warning disable CS0618 // Type or member is obsolete - public class SettingsFragment : PreferenceFragment - { - - - - - public class KeyboardSwitchPrefManager - { - private readonly Activity _act; - private CheckBoxPreference _switchPref; - private CheckBoxPreference _openKp2aAutoPref; - private CheckBoxPreference _openOnlyOnSearchPref; - private CheckBoxPreference _switchBackPref; - private PreferenceScreen _screen; - private PreferenceFragment _fragment; - - public KeyboardSwitchPrefManager(PreferenceFragment fragment) - { - var act = fragment.Activity; - this._act = act; - this._fragment = fragment; - this._screen = (PreferenceScreen)_fragment.FindPreference(act.GetString(Resource.String.keyboardswitch_prefs_key)); - - var keyboardSwapPref = _fragment.FindPreference("get_keyboardswap"); - var pm = act.PackageManager; - var intnt = Keepass2android.Kbbridge.ImeSwitcher.GetLaunchIntentForKeyboardSwap(act); - if ((intnt != null) && pm.QueryIntentActivities(intnt, 0).Any()) - { - _screen.RemovePreference(keyboardSwapPref); - } - else - { - keyboardSwapPref.PreferenceClick += (sender, args) => - { - Util.GotoUrl(act, act.GetString(Resource.String.MarketURL) + "keepass2android.plugin.keyboardswap2"); - }; - } - - _switchPref = (CheckBoxPreference)_fragment.FindPreference("kp2a_switch_rooted"); - _openKp2aAutoPref = - (CheckBoxPreference)_fragment.FindPreference(act.GetString(Resource.String.OpenKp2aKeyboardAutomatically_key)); - _openOnlyOnSearchPref = - (CheckBoxPreference) - _fragment.FindPreference(act.GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key)); - _switchBackPref = - (CheckBoxPreference)_fragment.FindPreference(act.GetString(Resource.String.AutoSwitchBackKeyboard_key)); - - EnableSwitchPreferences(_switchPref.Checked); - - _switchPref.PreferenceChange += (sender, args) => - { - bool switchOnRooted = (bool)args.NewValue; - EnableSwitchPreferences(switchOnRooted); - }; - } - - - private void EnableSwitchPreferences(bool switchOnRooted) - { - if (!switchOnRooted) - { - if (_fragment.FindPreference(_act.GetString(Resource.String.OpenKp2aKeyboardAutomatically_key)) == null) - { - _screen.AddPreference(_openKp2aAutoPref); - } - if (_fragment.FindPreference(_act.GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key)) != null) - { - _screen.RemovePreference(_openOnlyOnSearchPref); - } - } - else - { - { - _screen.RemovePreference(_openKp2aAutoPref); - } - if (_fragment.FindPreference(_act.GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key)) == null) - { - _screen.AddPreference(_openOnlyOnSearchPref); - } - } - /*_openKp2aAutoPref.Enabled = !switchOnRooted; - - _openOnlyOnSearchPref.Enabled = switchOnRooted; - - _switchBackPref.Enabled = switchOnRooted;*/ - } - } - - private KeyboardSwitchPrefManager _switchPrefManager; - private Preference aesRounds, argon2parallelism, argon2rounds, argon2memory; - - - void OnRememberKeyFileHistoryChanged(object sender, Preference.PreferenceChangeEventArgs eventArgs) - { - if (!(bool)eventArgs.NewValue) - { - App.Kp2a.FileDbHelper.DeleteAllKeys(); - } - } - - void OnShowUnlockedNotificationChanged(object sender, Preference.PreferenceChangeEventArgs eventArgs) - { - App.Kp2a.UpdateOngoingNotification(); - } - - public override void OnResume() - { - base.OnResume(); - - UpdateAutofillPref(); - } - - - public override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - AddPreferencesFromResource(Resource.Xml.preferences); - - // Re-use the change handlers for the application settings - FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged; - var unlockedNotificationPref = FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)); - unlockedNotificationPref.PreferenceChange += OnShowUnlockedNotificationChanged; - if ((int)Build.VERSION.SdkInt >= 26) - { - //use system notification channels to control notification visibility - unlockedNotificationPref.Parent.RemovePreference(unlockedNotificationPref); - } - - - FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged; - FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug; - -#if !EXCLUDE_JAVAFILESTORAGE && !NoNet - FindPreference(GetString(Resource.String.FtpDebug_key)).PreferenceChange += OnJSchDebugChanged; -#else - FindPreference(GetString(Resource.String.FtpDebug_key)).Enabled = false; -#endif - - HashSet supportedLocales = new HashSet() { "en", "af", "ar", "az", "be", "bg", "ca", "cs", "da", "de", "el", "es", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hu", "id", "in", "it", "iw", "ja", "ko", "ml", "nb", "nl", "nn", "no", "pl", "pt", "ro", "ru", "si", "sk", "sl", "sr", "sv", "tr", "uk", "vi", "zh" }; - var languagePref = (ListPreference)FindPreference(GetString(Resource.String.app_language_pref_key)); - new AppLanguageManager(this, languagePref, supportedLocales); - - UpdateAutofillPref(); - - var autofillPref = FindPreference(GetString(Resource.String.AutoFill_prefs_key)); - if (autofillPref != null) - { - autofillPref.PreferenceClick += (sender, args) => - { - - var intent = new Intent(Settings.ActionRequestSetAutofillService); - if (((AutofillManager)Activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)))) - .HasEnabledAutofillServices) - { - intent.SetData(Android.Net.Uri.Parse("package:" + Context.PackageName + "notexisting")); //if we use our package name, the activity won't launch - } - else - { - intent.SetData(Android.Net.Uri.Parse("package:" + Context.PackageName)); - } - - try - { - Context.StartActivity(intent); - } - catch (ActivityNotFoundException e) - { - //this exception was reported by many Huawei users - Kp2aLog.LogUnexpectedError(e); - new AlertDialog.Builder(Context) - .SetTitle(Resource.String.autofill_enable) - .SetMessage(Resource.String.autofill_enable_failed) - .SetPositiveButton(Android.Resource.String.Ok, (o, eventArgs) => { }) - .Show(); - - } - catch (Exception e) - { - Kp2aLog.LogUnexpectedError(e); - } - }; - } - - - PrepareNoDonatePreference(Activity, FindPreference(GetString(Resource.String.NoDonateOption_key))); - PrepareNoDonationReminderPreference(Activity, ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))), FindPreference(GetString(Resource.String.NoDonationReminder_key))); - - FindPreference(GetString(Resource.String.design_key)).PreferenceChange += (sender, args) => Activity.Recreate(); - - Database db = App.Kp2a.CurrentDb; - if (db != null) - { - ListPreference kdfPref = (ListPreference)FindPreference(GetString(Resource.String.kdf_key)); - kdfPref.SetEntries(KdfPool.Engines.Select(eng => eng.Name).ToArray()); - string[] kdfValues = KdfPool.Engines.Select(eng => eng.Uuid.ToHexString()).ToArray(); - kdfPref.SetEntryValues(kdfValues); - kdfPref.SetValueIndex(kdfValues.Select((v, i) => new { kdf = v, index = i }).First(el => el.kdf == db.KpDatabase.KdfParameters.KdfUuid.ToHexString()).index); - kdfPref.PreferenceChange += OnKdfChange; - - aesRounds = FindPreference(GetString(Resource.String.rounds_key)); - argon2rounds = FindPreference("argon2rounds"); - argon2memory = FindPreference("argon2memory"); - argon2parallelism = FindPreference("argon2parallelism"); - - aesRounds.PreferenceChange += (sender, e) => UpdateKdfSummary(e.Preference); - argon2rounds.PreferenceChange += (sender, e) => UpdateKdfSummary(e.Preference); - argon2memory.PreferenceChange += (sender, e) => UpdateKdfSummary(e.Preference); - argon2parallelism.PreferenceChange += (sender, e) => UpdateKdfSummary(e.Preference); - - UpdateKdfScreen(); - - PrepareDefaultUsername(db); - PrepareDatabaseName(db); - PrepareMasterPassword(); - PrepareTemplates(db); - - ListPreference algorithmPref = (ListPreference)FindPreference(GetString(Resource.String.algorithm_key)); - algorithmPref.SetEntries(CipherPool.GlobalPool.Engines.Select(eng => eng.DisplayName).ToArray()); - string[] algoValues = CipherPool.GlobalPool.Engines.Select(eng => eng.CipherUuid.ToHexString()).ToArray(); - algorithmPref.SetEntryValues(algoValues); - algorithmPref.SetValueIndex(algoValues.Select((v, i) => new { kdf = v, index = i }).First(el => el.kdf == db.KpDatabase.DataCipherUuid.ToHexString()).index); - algorithmPref.PreferenceChange += AlgorithmPrefChange; - algorithmPref.Summary = - CipherPool.GlobalPool.GetCipher(App.Kp2a.CurrentDb.KpDatabase.DataCipherUuid).DisplayName; - UpdateImportDbPref(); - UpdateImportKeyfilePref(); - } - - try - { - //depending on Android version, we offer to use a transparent icon for QuickUnlock or use the notification priority (since API level 16) - Preference hideQuickUnlockTranspIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden_key)); - Preference hideQuickUnlockIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden16_key)); - var quickUnlockScreen = ((PreferenceScreen)FindPreference(GetString(Resource.String.QuickUnlock_prefs_key))); - if ((int)Android.OS.Build.VERSION.SdkInt >= 26) - { - //use notification channels - quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref); - quickUnlockScreen.RemovePreference(hideQuickUnlockIconPref); - } - else if ((int)Android.OS.Build.VERSION.SdkInt >= 16) - { - quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref); - unlockedNotificationPref.PreferenceChange += (sender, args) => App.Kp2a.UpdateOngoingNotification(); - hideQuickUnlockIconPref.PreferenceChange += delegate { App.Kp2a.UpdateOngoingNotification(); }; - } - else - { - //old version: only show transparent quickUnlock and no option to hide unlocked icon: - quickUnlockScreen.RemovePreference(hideQuickUnlockIconPref); - FindPreference(GetString(Resource.String.QuickUnlockIconHidden_key)).PreferenceChange += - delegate { App.Kp2a.UpdateOngoingNotification(); }; - - ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))).RemovePreference( - unlockedNotificationPref); - } - } - catch (Exception ex) - { - Kp2aLog.LogUnexpectedError(ex); - } - - - - //AppSettingsActivity.PrepareKeyboardSwitchingPreferences(this); - _switchPrefManager = new KeyboardSwitchPrefManager(this); - PrepareSeparateNotificationsPreference(); - - FindPreference("IconSetKey").PreferenceChange += (sender, args) => - { - if (App.Kp2a.CurrentDb != null) - App.Kp2a.CurrentDb.DrawableFactory.Clear(); - - }; - - Preference cachingPreference = FindPreference(GetString(Resource.String.UseOfflineCache_key)); - cachingPreference.PreferenceChange += OnUseOfflineCacheChanged; - - - } - - private void UpdateAutofillPref() - { - var autofillScreen = FindPreference(GetString(Resource.String.AutoFill_prefs_screen_key)); - var autofillPref = FindPreference(GetString(Resource.String.AutoFill_prefs_key)); - var autofillDisabledPref = FindPreference(GetString(Resource.String.AutofillDisabledQueriesPreference_key)); - var autofillSavePref = FindPreference(GetString(Resource.String.OfferSaveCredentials_key)); - var autofillInlineSuggestions = FindPreference(GetString(Resource.String.InlineSuggestions_key)); - var noAutofillDisablingPref = FindPreference(GetString(Resource.String.NoAutofillDisabling_key)); - var autofillNoDalVerification = FindPreference(GetString(Resource.String.NoDalVerification_key)); - if (autofillPref == null) - return; - if ((Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O) || - !((AutofillManager) Activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)))) - .IsAutofillSupported) - { - var passwordAccessScreen = - (PreferenceScreen) FindPreference(Activity.GetString(Resource.String.password_access_prefs_key)); - passwordAccessScreen.RemovePreference(autofillScreen); - } - else - { - if (((AutofillManager) Activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)))) - .HasEnabledAutofillServices) - { - autofillDisabledPref.Enabled = true; - autofillSavePref.Enabled = true; - autofillNoDalVerification.Enabled = true; - autofillInlineSuggestions.Enabled = true; - noAutofillDisablingPref.Enabled = true; - autofillPref.Summary = Activity.GetString(Resource.String.plugin_enabled); - autofillPref.Intent = new Intent(Intent.ActionView); - autofillPref.Intent.SetData(Android.Net.Uri.Parse("https://philippc.github.io/keepass2android/OreoAutoFill.html")); - } - else - { - autofillNoDalVerification.Enabled = false; - autofillDisabledPref.Enabled = false; - autofillSavePref.Enabled = false; - noAutofillDisablingPref.Enabled = false; - autofillInlineSuggestions.Enabled = false; - autofillPref.Summary = Activity.GetString(Resource.String.not_enabled); - } - if ((int)Android.OS.Build.VERSION.SdkInt < 30) - { - autofillInlineSuggestions.Summary = Activity.GetString(Resource.String.requires_android11); - CheckBoxPreference cbp = autofillInlineSuggestions as CheckBoxPreference; - if (cbp != null) - cbp.Checked = false; - autofillInlineSuggestions.Enabled = false; - } - } - } - - private void OnSendDebug(object sender, Preference.PreferenceClickEventArgs e) - { - Kp2aLog.SendLog(this.Activity); - } - - private void OnDebugLogChanged(object sender, Preference.PreferenceChangeEventArgs e) - { - if ((bool)e.NewValue) - Kp2aLog.CreateLogFile(); - else - Kp2aLog.FinishLogFile(); - -#if !EXCLUDE_JAVAFILESTORAGE && !NoNet - SetJSchLogging(PreferenceManager.GetDefaultSharedPreferences(Application.Context) - .GetBoolean(Application.Context.GetString(Resource.String.FtpDebug_key), false)); -#endif - } - -#if !EXCLUDE_JAVAFILESTORAGE && !NoNet - private void OnJSchDebugChanged(object sender, Preference.PreferenceChangeEventArgs e) - { - bool debugEnabled = (bool)e.NewValue; - SetJSchLogging(debugEnabled); - - string prefKey = Application.Context.GetString(Resource.String.FtpDebug_key); - PreferenceManager.SharedPreferences.Edit().PutBoolean(prefKey, debugEnabled).Apply(); - } - - private void SetJSchLogging(bool enabled) - { - var sftpStorage = new Keepass2android.Javafilestorage.SftpStorage(Context); - string? logFilename = null; - if (Kp2aLog.LogToFile) - { - logFilename = Kp2aLog.LogFilename; - } - sftpStorage.SetJschLogging(enabled, logFilename); - } - -#endif - - private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs) - { - var db = App.Kp2a.CurrentDb; - var previousCipher = db.KpDatabase.DataCipherUuid; - db.KpDatabase.DataCipherUuid = new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue)); - - SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnFinish(Activity, (success, message, activity) => - { - if (!success) - { - db.KpDatabase.DataCipherUuid = previousCipher; - Toast.MakeText(activity, message, ToastLength.Long).Show(); - return; - } - preferenceChangeEventArgs.Preference.Summary = - CipherPool.GlobalPool.GetCipher(db.KpDatabase.DataCipherUuid).DisplayName; - })); - ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); - pt.Run(); - } - - private void UpdateKdfScreen() - { - var db = App.Kp2a.CurrentDb; - var kdf = KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid); - - var kdfpref = FindPreference(GetString(Resource.String.kdf_key)); - - - kdfpref.Summary = kdf.Name; - - var kdfscreen = ((PreferenceScreen)FindPreference(GetString(Resource.String.kdf_screen_key))); - if (kdf is AesKdf) - { - if (kdfscreen.FindPreference(GetString(Resource.String.rounds_key)) == null) - kdfscreen.AddPreference(aesRounds); - kdfscreen.RemovePreference(argon2rounds); - kdfscreen.RemovePreference(argon2memory); - kdfscreen.RemovePreference(argon2parallelism); - - aesRounds.Enabled = db.CanWrite; - UpdateKdfSummary(aesRounds); - } - else - { - kdfscreen.RemovePreference(aesRounds); - if (kdfscreen.FindPreference("argon2rounds") == null) - { - kdfscreen.AddPreference(argon2rounds); - kdfscreen.AddPreference(argon2memory); - kdfscreen.AddPreference(argon2parallelism); - } - UpdateKdfSummary(argon2rounds); - UpdateKdfSummary(argon2memory); - UpdateKdfSummary(argon2parallelism); - } - - } - - private void OnKdfChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs) - { - var db = App.Kp2a.CurrentDb; - var previousKdfParams = db.KpDatabase.KdfParameters; - Kp2aLog.Log("previous kdf: " + KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid) + " " + db.KpDatabase.KdfParameters.KdfUuid.ToHexString() ); - db.KpDatabase.KdfParameters = - KdfPool.Get( - new PwUuid(MemUtil.HexStringToByteArray((string)preferenceChangeEventArgs.NewValue))) - .GetDefaultParameters(); - - Kp2aLog.Log("--new kdf: " + KdfPool.Get(db.KpDatabase.KdfParameters.KdfUuid) + " " + db.KpDatabase.KdfParameters.KdfUuid.ToHexString()); - - SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnFinish(Activity, (success, message, activity) => - { - if (!success) - { - db.KpDatabase.KdfParameters = previousKdfParams; - Toast.MakeText(activity, message, ToastLength.Long).Show(); - return; - } - UpdateKdfScreen(); - - })); - ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); - pt.Run(); - - } - - private void UpdateKdfSummary(Preference preference) - { - preference.Summary = ((keepass2android.settings.KdfNumberParamPreference)preference).ParamValue.ToString(); - } - - private void PrepareNoDonationReminderPreference(Activity ctx, PreferenceScreen screen, Preference preference) - { - ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx); - - if (!prefs.GetBoolean("DismissedDonateReminder", false)) - { - screen.RemovePreference(preference); - } - - - } - private void PrepareTemplates(Database db) - { - Preference pref = FindPreference("AddTemplates_pref_key"); - if ((!db.DatabaseFormat.SupportsTemplates) || (AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb))) - { - pref.Enabled = false; - } - else - { - pref.PreferenceClick += (sender, args) => - { - ProgressTask pt = new ProgressTask(App.Kp2a, Activity, - new AddTemplateEntries(Activity, App.Kp2a, new ActionOnFinish(Activity, - delegate - { - pref.Enabled = false; - }))); - pt.Run(); - }; - } - - } - - private void PrepareMasterPassword() - { - Preference changeMaster = FindPreference(GetString(Resource.String.master_pwd_key)); - if (App.Kp2a.CurrentDb.CanWrite) - { - changeMaster.Enabled = true; - changeMaster.PreferenceClick += delegate { new SetPasswordDialog(Activity).Show(); }; - } - } - - private void PrepareDatabaseName(Database db) - { - Preference databaseName = FindPreference(GetString(Resource.String.database_name_key)); - if (!db.DatabaseFormat.HasDatabaseName) - { - ((PreferenceScreen) FindPreference(GetString(Resource.String.db_key))).RemovePreference(databaseName); - } - else - { - databaseName.Enabled = db.CanWrite; - ((EditTextPreference) databaseName).EditText.Text = db.KpDatabase.Name; - ((EditTextPreference) databaseName).Text = db.KpDatabase.Name; - databaseName.PreferenceChange += (sender, e) => - { - DateTime previousNameChanged = db.KpDatabase.NameChanged; - String previousName = db.KpDatabase.Name; - db.KpDatabase.Name = e.NewValue.ToString(); - - SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnFinish(Activity, (success, message, activity) => - { - if (!success) - { - db.KpDatabase.Name = previousName; - db.KpDatabase.NameChanged = previousNameChanged; - Toast.MakeText(activity, message, ToastLength.Long).Show(); - } - else - { - // Name is reflected in notification, so update it - App.Kp2a.UpdateOngoingNotification(); - } - })); - ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); - pt.Run(); - }; - } - } - - private void PrepareDefaultUsername(Database db) - { - Preference defaultUser = FindPreference(GetString(Resource.String.default_username_key)); - if (!db.DatabaseFormat.HasDefaultUsername) - { - ((PreferenceScreen) FindPreference(GetString(Resource.String.db_key))).RemovePreference(defaultUser); - } - else - { - defaultUser.Enabled = db.CanWrite; - ((EditTextPreference) defaultUser).EditText.Text = db.KpDatabase.DefaultUserName; - ((EditTextPreference) defaultUser).Text = db.KpDatabase.DefaultUserName; - defaultUser.PreferenceChange += (sender, e) => - { - DateTime previousUsernameChanged = db.KpDatabase.DefaultUserNameChanged; - String previousUsername = db.KpDatabase.DefaultUserName; - db.KpDatabase.DefaultUserName = e.NewValue.ToString(); - - SaveDb save = new SaveDb(Activity, App.Kp2a, App.Kp2a.CurrentDb, new ActionOnFinish(Activity, (success, message, activity) => - { - if (!success) - { - db.KpDatabase.DefaultUserName = previousUsername; - db.KpDatabase.DefaultUserNameChanged = previousUsernameChanged; - Toast.MakeText(activity, message, ToastLength.Long).Show(); - } - })); - ProgressTask pt = new ProgressTask(App.Kp2a, Activity, save); - pt.Run(); - }; - } - } - - public void PrepareSeparateNotificationsPreference() - { - try - { - //depending on Android version, we offer to show a combined notification (with action buttons) (since API level 16) - Preference separateNotificationsPref = FindPreference(Activity.GetString(Resource.String.ShowSeparateNotifications_key)); - var passwordAccessScreen = ((PreferenceScreen)FindPreference(Activity.GetString(Resource.String.password_access_prefs_key))); - if ((int)Build.VERSION.SdkInt < 16) - { - passwordAccessScreen.RemovePreference(separateNotificationsPref); - } - } - catch (Exception ex) - { - Kp2aLog.LogUnexpectedError(ex); - } - } - - private void OnUseOfflineCacheChanged(object sender, Preference.PreferenceChangeEventArgs e) - { - if (!(bool)e.NewValue) - { - AlertDialog.Builder builder = new AlertDialog.Builder(Activity); - builder.SetTitle(GetString(Resource.String.ClearOfflineCache_title)); - - builder.SetMessage(GetString(Resource.String.ClearOfflineCache_question)); - - builder.SetPositiveButton(App.Kp2a.GetResourceString(UiStringKey.yes), (o, args) => - { - try - { - App.Kp2a.ClearOfflineCache(); - } - catch (Exception ex) - { - Kp2aLog.LogUnexpectedError(ex); - Toast.MakeText(LocaleManager.LocalizedAppContext, ex.Message, ToastLength.Long).Show(); - } - } - ); - - builder.SetNegativeButton(App.Kp2a.GetResourceString(UiStringKey.no), (o, args) => - { - ((CheckBoxPreference) e.Preference).Checked = true; - } - ); - builder.SetCancelable(false); - Dialog dialog = builder.Create(); - dialog.Show(); - - - } - } - - private void UpdateImportKeyfilePref() - { - var prefs = PreferenceManager.GetDefaultSharedPreferences(Activity); - var rememberKeyfile = prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default)); - - Preference importKeyfile = FindPreference("import_keyfile_prefs"); - Preference exportKeyfile = FindPreference("export_keyfile_prefs"); - importKeyfile.Summary = ""; - - if (!rememberKeyfile) - { - importKeyfile.Summary = GetString(Resource.String.KeyfileMoveRequiresRememberKeyfile); - importKeyfile.Enabled = false; - exportKeyfile.Enabled = false; - return; - } - CompositeKey masterKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey; - if (masterKey.ContainsType(typeof(KcpKeyFile))) - { - IOConnectionInfo iocKeyfile = ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).Ioc; - if (iocKeyfile.IsLocalFile() && IoUtil.IsInInternalDirectory(iocKeyfile.Path, Activity)) - { - importKeyfile.Enabled = false; - exportKeyfile.Enabled = true; - exportKeyfile.PreferenceClick += (sender, args) => { ExportKeyfileFromInternalFolder(); }; - importKeyfile.Summary = GetString(Resource.String.FileIsInInternalDirectory); - } - else - { - exportKeyfile.Enabled = false; - importKeyfile.Enabled = true; - importKeyfile.PreferenceClick += (sender, args) => { MoveKeyfileToInternalFolder(); }; - } - - - } - else - { - exportKeyfile.Enabled = false; - importKeyfile.Enabled = false; - } - } - - - - private void ExportKeyfileFromInternalFolder() - { - StartActivity(new Intent(Activity.ApplicationContext, typeof(ExportKeyfileActivity))); - - } - - private void MoveKeyfileToInternalFolder() - { - Func copyAndReturnPostExecute = () => - { - try - { - CompositeKey masterKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey; - var sourceIoc = ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).Ioc; - var newIoc = IoUtil.ImportFileToInternalDirectory(sourceIoc, Activity, App.Kp2a); - ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).ResetIoc(newIoc); - var keyfileString = IOConnectionInfo.SerializeToString(newIoc); - App.Kp2a.StoreOpenedFileAsRecent(App.Kp2a.CurrentDb.Ioc, keyfileString, false); - return () => - { - UpdateImportKeyfilePref(); - var builder = new AlertDialog.Builder(Activity); - builder - .SetMessage(Resource.String.KeyfileMoved); - builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { }); - builder.Show(); - - }; - - - - - } - catch (Exception e) - { - return () => - { - Toast.MakeText(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show(); - }; - } - - - - }; - - new SimpleLoadingDialog(Activity, GetString(Resource.String.CopyingFile), false, - copyAndReturnPostExecute - ).Execute(); - - } - private void UpdateImportDbPref() - { - //Import db/key file preferences: - Preference importDb = FindPreference("import_db_prefs"); - bool isLocalOrContent = - App.Kp2a.CurrentDb.Ioc.IsLocalFile() || App.Kp2a.CurrentDb.Ioc.Path.StartsWith("content://"); - if (!isLocalOrContent) - { - importDb.Summary = GetString(Resource.String.OnlyAvailableForLocalFiles); - importDb.Enabled = false; - } - else - { - if (IoUtil.IsInInternalDirectory(App.Kp2a.CurrentDb.Ioc.Path, Activity)) - { - importDb.Summary = GetString(Resource.String.FileIsInInternalDirectory); - importDb.Enabled = false; - } - else - { - importDb.Enabled = true; - importDb.PreferenceClick += delegate { MoveDbToInternalFolder(); }; - } - } - } - - private void MoveDbToInternalFolder() - { - Func copyAndReturnPostExecute = () => - { - try - { - var sourceIoc = App.Kp2a.CurrentDb.Ioc; - var newIoc = IoUtil.ImportFileToInternalDirectory(sourceIoc, Activity, App.Kp2a); - return () => - { - var builder = new AlertDialog.Builder(Activity); - builder - .SetMessage(Resource.String.DatabaseFileMoved); - builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => - { - var key = App.Kp2a.CurrentDb.KpDatabase.MasterKey; - App.Kp2a.CloseDatabase(App.Kp2a.CurrentDb); - PasswordActivity.Launch(Activity, newIoc, key, new ActivityLaunchModeSimple(), false); - - }); - builder.Show(); - - }; - - - - - } - catch (Exception e) - { - return () => - { - Toast.MakeText(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show(); - }; - } - - - - }; - - new SimpleLoadingDialog(Activity, GetString(Resource.String.CopyingFile), false, - copyAndReturnPostExecute - ).Execute(); - - } - - - - private void SetAlgorithm(Database db, Preference algorithm) - { - algorithm.Summary = CipherPool.GlobalPool.GetCipher(db.KpDatabase.DataCipherUuid).DisplayName; - } - - public void PrepareNoDonatePreference(Context ctx, Preference preference) - { - ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(ctx); - - long usageCount = prefs.GetLong(ctx.GetString(Resource.String.UsageCount_key), 0); - -#if DEBUG - preference.Enabled = (usageCount > 1); -#else - preference.Enabled = (usageCount > 50); -#endif - preference.PreferenceChange += delegate(object sender, Preference.PreferenceChangeEventArgs args) - { - if ((bool)args.NewValue) - { - new AlertDialog.Builder(ctx) - .SetTitle(ctx.GetString(AppNames.AppNameResource)) - .SetCancelable(false) - .SetPositiveButton(Android.Resource.String.Ok, delegate(object o, DialogClickEventArgs eventArgs) - { - Util.GotoDonateUrl(ctx); - ((Dialog)o).Dismiss(); - }) - .SetMessage(Resource.String.NoDonateOption_question) - .Create().Show(); - - } - }; - - } - - - } /// /// @@ -910,11 +65,11 @@ public void PrepareNoDonatePreference(Context ctx, Preference preference) /// internal class AppLanguageManager { - private readonly PreferenceFragment _fragment; - private readonly ListPreference _langPref; + private readonly PreferenceFragmentCompat _fragment; + private readonly AndroidX.Preference.ListPreference _langPref; private readonly Dictionary _langEntriesByCodeUnique; - public AppLanguageManager(PreferenceFragment fragment, ListPreference langPref, HashSet supportedLocales) + public AppLanguageManager(PreferenceFragmentCompat fragment, AndroidX.Preference.ListPreference langPref, HashSet supportedLocales) { this._fragment = fragment; this._langPref = langPref; @@ -923,7 +78,7 @@ public AppLanguageManager(PreferenceFragment fragment, ListPreference langPref, ConfigureLanguageList(); } - private static Dictionary CreateCodeToEntryMapping(PreferenceFragment fragment, HashSet supportedLocales) + private static Dictionary CreateCodeToEntryMapping(PreferenceFragmentCompat fragment, HashSet supportedLocales) { var localesByCode = new Dictionary>(); foreach (var loc in Java.Util.Locale.GetAvailableLocales()) @@ -973,7 +128,7 @@ private string GetDisplayLanguage(string languageCode) return _fragment.GetString(Resource.String.SystemLanguage); } - private void AppLanguagePrefChange(object sender, Preference.PreferenceChangeEventArgs args) + private void AppLanguagePrefChange(object sender, AndroidX.Preference.Preference.PreferenceChangeEventArgs args) { string langCode = LanguageEntry.PrefCodeToLanguage((string)args.NewValue); LocaleManager.Language = langCode; @@ -987,29 +142,42 @@ private void AppLanguagePrefChange(object sender, Preference.PreferenceChangeEve /// /// Activity to configure the application and database settings. The database must be unlocked, and this activity will close if it becomes locked. /// - [Activity(Label = "@string/app_name", Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden)] - public class DatabaseSettingsActivity : LockCloseActivity - { - - public DatabaseSettingsActivity() - { - - } + [Activity(Label = "@string/app_name", Theme = "@style/MyTheme_ActionBar", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden)] + public class DatabaseSettingsActivity : LockCloseActivity, PreferenceFragmentCompat.IOnPreferenceStartFragmentCallback + { public static void Launch(Activity ctx) { ctx.StartActivity(new Intent(ctx, typeof(DatabaseSettingsActivity))); } - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - SetContentView(Resource.Layout.preference); + private ActivityDesign _design; - SetSupportActionBar(FindViewById(Resource.Id.mytoolbar)); + public DatabaseSettingsActivity() + { + _design = new ActivityDesign(this); + settingsFragmentManager = new SettingsFragmentManager(this); + } - } + public static void Launch(Context ctx) + { + ctx.StartActivity(new Intent(ctx, typeof(AppSettingsActivity))); + } - } + protected override void OnCreate(Bundle savedInstanceState) + { + _design.ApplyTheme(); + base.OnCreate(savedInstanceState); + + + } + + public SettingsFragmentManager settingsFragmentManager; + public bool OnPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) + { + return settingsFragmentManager.OnPreferenceStartFragment(caller, pref); + } + + } } diff --git a/src/keepass2android-appSdkStyle/settings/IconSetPreference.cs b/src/keepass2android-appSdkStyle/settings/IconSetPreference.cs index 59872005f..1afb8394b 100644 --- a/src/keepass2android-appSdkStyle/settings/IconSetPreference.cs +++ b/src/keepass2android-appSdkStyle/settings/IconSetPreference.cs @@ -7,11 +7,12 @@ using Android.Content.Res; using Android.Graphics; using Android.Graphics.Drawables; -using Android.Preferences; +using AndroidX.Preference; using Android.Runtime; using Android.Util; using Android.Views; using Android.Widget; +using Google.Android.Material.Dialog; using keepass2android_appSdkStyle; namespace keepass2android @@ -127,6 +128,8 @@ public override int Count } } + public Dialog Dialog { get; set; } + List _iconSets = null; List IconSets @@ -183,12 +186,9 @@ public IconSetPreference(Context context, IAttributeSet attrs) } - - protected override void OnPrepareDialogBuilder(AlertDialog.Builder builder) + protected override void OnClick() { _populatorTask.Wait(); - base.OnPrepareDialogBuilder(builder); - var iconListPreferenceAdapter = new IconListPreferenceScreenAdapter(this, Context); @@ -202,13 +202,17 @@ protected override void OnPrepareDialogBuilder(AlertDialog.Builder builder) } } + var builder = new MaterialAlertDialogBuilder(Context); + builder.SetAdapter(iconListPreferenceAdapter, (sender, args) => { }); builder.SetNeutralButton(Resource.String.IconSet_install, (sender, args) => { Util.GotoUrl(Context, "market://search?q=keepass2android icon set"); }); - + Dialog = builder.Create(); + Dialog.Show(); } + } } \ No newline at end of file diff --git a/src/keepass2android-appSdkStyle/settings/RoundsPreference.cs b/src/keepass2android-appSdkStyle/settings/RoundsPreference.cs index 1c9029a87..5723a2023 100644 --- a/src/keepass2android-appSdkStyle/settings/RoundsPreference.cs +++ b/src/keepass2android-appSdkStyle/settings/RoundsPreference.cs @@ -21,31 +21,106 @@ You should have received a copy of the GNU General Public License using Android.OS; using Android.Views; using Android.Widget; -using Android.Preferences; + using KeePassLib; using Android.Util; +using AndroidX.Preference; using keepass2android_appSdkStyle; using KeePassLib.Cryptography.KeyDerivation; +using Google.Android.Material.Dialog; namespace keepass2android.settings { - public abstract class KdfNumberParamPreference: DialogPreference { - - internal TextView edittext; + /* + * + public class KdfNumberDialogPreference : DialogPreference + { + private readonly Context _context; + public KdfNumberDialogPreference(Context context) : base(context) + { + _context = context; + } + + public KdfNumberDialogPreference(Context context, IAttributeSet attrs) : base(context, attrs) + { + _context = context; + } + + public KdfNumberDialogPreference(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) + { + _context = context; + } + + public override int DialogLayoutResource => Resource.Layout.activity_main; + + } + + + */ + public abstract class KdfNumberDialogPreference : DialogPreference { - protected override View OnCreateDialogView() { - View view = base.OnCreateDialogView(); - - edittext = (TextView) view.FindViewById(Resource.Id.rounds); - - - ulong numRounds = ParamValue; - edittext.Text = numRounds.ToString(CultureInfo.InvariantCulture); - - view.FindViewById(Resource.Id.rounds_explaination).Text = ExplanationString; - - return view; - } + public KdfNumberDialogPreference(Context context) : base(context) + { + + } + + public KdfNumberDialogPreference(Context context, IAttributeSet attrs) : base(context, attrs) + { + + } + + public KdfNumberDialogPreference(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) + { + + } + + public void ShowDialog(PreferenceFragmentCompat containingFragment) + { + var activity = containingFragment.Activity; + MaterialAlertDialogBuilder db = new MaterialAlertDialogBuilder(activity); + + View dialogView = activity.LayoutInflater.Inflate(Resource.Layout.database_kdf_settings, null); + var inputEditText = dialogView.FindViewById(Resource.Id.rounds); + + inputEditText.Text = ParamValue.ToString(); + + db.SetView(dialogView); + db.SetTitle(Title); + db.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => + { + //store the old value for restoring in case of failure + ulong paramValue; + + String strRounds = inputEditText.Text; + if (!(ulong.TryParse(strRounds, out paramValue))) + { + Toast.MakeText(Context, Resource.String.error_param_not_number, ToastLength.Long).Show(); + return; + } + + if (paramValue < 1) + { + paramValue = 1; + } + + ulong oldValue = ParamValue; + + if (oldValue == paramValue) + { + return; + } + + ParamValue = paramValue; + + Handler handler = new Handler(); + SaveDb save = new SaveDb((Activity)Context, App.Kp2a, App.Kp2a.CurrentDb, new AfterSave((Activity)Context, handler, oldValue, this)); + ProgressTask pt = new ProgressTask(App.Kp2a, (Activity)Context, save); + pt.Run(); + }); + db.SetNegativeButton(Android.Resource.String.Cancel, ((sender, args) => { })); + + db.Create().Show(); + } public virtual string ExplanationString { @@ -53,61 +128,17 @@ public virtual string ExplanationString } public abstract ulong ParamValue { get; set; } - public KdfNumberParamPreference(Context context, IAttributeSet attrs):base(context, attrs) { - } - public KdfNumberParamPreference(Context context, IAttributeSet attrs, int defStyle) - : base(context, attrs, defStyle) - { - } - - protected override void OnDialogClosed(bool positiveResult) { - base.OnDialogClosed(positiveResult); - - if ( positiveResult ) { - ulong paramValue; - - String strRounds = edittext.Text; - if (!(ulong.TryParse(strRounds,out paramValue))) - { - Toast.MakeText(Context, Resource.String.error_param_not_number, ToastLength.Long).Show(); - return; - } - - if ( paramValue < 1 ) { - paramValue = 1; - } - - Database db = App.Kp2a.CurrentDb; - - ulong oldValue = ParamValue; - - if (oldValue == paramValue) - { - return; - } - - ParamValue = paramValue; - - Handler handler = new Handler(); - SaveDb save = new SaveDb((Activity)Context, App.Kp2a, App.Kp2a.CurrentDb, new KdfNumberParamPreference.AfterSave((Activity)Context, handler, oldValue, this)); - ProgressTask pt = new ProgressTask(App.Kp2a, (Activity)Context, save); - pt.Run(); - - } - - } - private class AfterSave : OnFinish { - private readonly ulong _oldRounds; + private readonly ulong _oldParamValue; private readonly Context _ctx; - private readonly KdfNumberParamPreference _pref; + private readonly KdfNumberDialogPreference _pref; - public AfterSave(Activity ctx, Handler handler, ulong oldRounds, KdfNumberParamPreference pref):base(ctx, handler) { + public AfterSave(Activity ctx, Handler handler, ulong oldParamValue, KdfNumberDialogPreference pref):base(ctx, handler) { _pref = pref; _ctx = ctx; - _oldRounds = oldRounds; + _oldParamValue = oldParamValue; } public override void Run() { @@ -119,8 +150,8 @@ public override void Run() { } else { DisplayMessage(_ctx); - App.Kp2a.CurrentDb.KpDatabase.KdfParameters.SetUInt64(AesKdf.ParamRounds, _oldRounds); - } + _pref.ParamValue = _oldParamValue; + } base.Run(); } @@ -132,7 +163,8 @@ public override void Run() { /// /// Represents the setting for the number of key transformation rounds. Changing this requires to save the database. /// - public class RoundsPreference : KdfNumberParamPreference { + public class RoundsPreference : KdfNumberDialogPreference + { private readonly Context _context;