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; FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged; FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged; FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged; FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug; 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.GetDb(); if (db.Loaded) { 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.GetDb().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 >= 16) { quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref); FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).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( FindPreference(GetString(Resource.String.ShowUnlockedNotification_key))); } } catch (Exception ex) { Kp2aLog.LogUnexpectedError(ex); } //AppSettingsActivity.PrepareKeyboardSwitchingPreferences(this); _switchPrefManager = new KeyboardSwitchPrefManager(this); PrepareSeparateNotificationsPreference(); FindPreference("IconSetKey").PreferenceChange += (sender, args) => { if (App.Kp2a.GetDb() != null) { App.Kp2a.GetDb().DrawableFactory.Clear(); } }; Preference cachingPreference = FindPreference(GetString(Resource.String.UseOfflineCache_key)); cachingPreference.PreferenceChange += OnUseOfflineCacheChanged; }
protected override void OnCreate(Bundle savedInstanceState) { _design.ApplyTheme(); base.OnCreate(savedInstanceState); AddPreferencesFromResource(Resource.Xml.preferences); FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged; Preference designPref = FindPreference(GetString(Resource.String.design_key)); if (!_design.HasThemes()) { try { ((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))).RemovePreference(designPref); } catch (Exception ex) { Kp2aLog.Log(ex.ToString()); throw; } } else { designPref.PreferenceChange += (sender, args) => Recreate(); } Util.PrepareNoDonatePreference(this, FindPreference(GetString(Resource.String.NoDonateOption_key))); Preference cachingPreference = FindPreference(GetString(Resource.String.UseOfflineCache_key)); cachingPreference.PreferenceChange += OnUseOfflineCacheChanged; #if NoNet try { ((PreferenceScreen) FindPreference(GetString(Resource.String.FileHandling_prefs_key))).RemovePreference(cachingPreference); } catch (Exception ex) { Kp2aLog.Log(ex.ToString()); } #endif 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 >= 16) { quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref); FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += (sender, args) => App.Kp2a.UpdateOngoingNotification(); hideQuickUnlockIconPref.PreferenceChange += OnQuickUnlockHiddenChanged; } 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( FindPreference(GetString(Resource.String.ShowUnlockedNotification_key))); } } catch (Exception ex) { Kp2aLog.Log(ex.ToString()); } FindPreference(GetString(Resource.String.db_key)).Enabled = false; _switchPrefManager = new KeyboardSwitchPrefManager(this); PrepareSeparateNotificationsPreference(this); }
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; 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(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; }
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; HashSet <string> supportedLocales = new HashSet <string>() { "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" }; ListPreference appLanguagePref = (ListPreference)FindPreference(GetString(Resource.String.app_language_pref_key)); var localesByCode = new System.Collections.Generic.Dictionary <string, List <Java.Util.Locale> >(); foreach (var loc in Java.Util.Locale.GetAvailableLocales()) { if (!supportedLocales.Contains(loc.Language)) { continue; } if (!localesByCode.ContainsKey(loc.Language)) { localesByCode[loc.Language] = new List <Java.Util.Locale>(); } localesByCode[loc.Language].Add(loc); } var localesByCodeUnique = localesByCode.Select(l => new KeyValuePair <string, Java.Util.Locale>(l.Key, l.Value.First())).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); List <KeyValuePair <string, List <Java.Util.Locale> > > codesWithMultiple = localesByCode.Where(l => l.Value.Count > 1).ToList(); List <KeyValuePair <string, Java.Util.Locale> > localesByLanguageList = localesByCodeUnique .OrderBy(kvp => kvp.Value.DisplayLanguage).ToList(); appLanguagePref.SetEntries(localesByLanguageList.Select(kvp => kvp.Value.DisplayLanguage).ToArray()); appLanguagePref.SetEntryValues(localesByLanguageList.Select(kvp => kvp.Value.Language).ToArray()); string languageCode = appLanguagePref.Value; string summary = GetDisplayLanguage(localesByCodeUnique, languageCode); ((ListPreference)FindPreference(GetString(Resource.String.app_language_pref_key))).Summary = summary; appLanguagePref.PreferenceChange += (sender, args) => { ((ListPreference)FindPreference(GetString(Resource.String.app_language_pref_key))).Summary = GetDisplayLanguage(localesByCodeUnique, (string)args.NewValue); LocaleManager.Language = (string)args.NewValue; }; 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; }