From f9a7d66e8e4cf5ae9b26adba74f0e82d5c20a31b Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Fri, 19 Dec 2014 21:40:50 +0100 Subject: [PATCH] password generator activity remembers last settings --- .../GeneratePasswordActivity.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/keepass2android/GeneratePasswordActivity.cs b/src/keepass2android/GeneratePasswordActivity.cs index b9f53e4d..6c0ae4d1 100644 --- a/src/keepass2android/GeneratePasswordActivity.cs +++ b/src/keepass2android/GeneratePasswordActivity.cs @@ -16,9 +16,11 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file */ using System; +using System.Globalization; using Android.App; using Android.Content; using Android.OS; +using Android.Preferences; using Android.Views; using Android.Widget; @@ -48,6 +50,17 @@ namespace keepass2android base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.generate_password); SetResult(KeePass.ExitNormal); + + var prefs = GetPreferences(FileCreationMode.Private); + ((CheckBox) FindViewById(Resource.Id.cb_uppercase)).Checked = prefs.GetBoolean("cb_uppercase", true); + ((CheckBox)FindViewById(Resource.Id.cb_lowercase)).Checked = prefs.GetBoolean("cb_lowercase", true); + ((CheckBox)FindViewById(Resource.Id.cb_digits)).Checked = prefs.GetBoolean("cb_digits", true); + ((CheckBox)FindViewById(Resource.Id.cb_minus)).Checked = prefs.GetBoolean("cb_minus", false); + ((CheckBox)FindViewById(Resource.Id.cb_underline)).Checked = prefs.GetBoolean("cb_underline", false); + ((CheckBox)FindViewById(Resource.Id.cb_space)).Checked = prefs.GetBoolean("cb_space", false); + ((CheckBox)FindViewById(Resource.Id.cb_specials)).Checked = prefs.GetBoolean("cb_specials", false); + ((CheckBox)FindViewById(Resource.Id.cb_brackets)).Checked = prefs.GetBoolean("cb_brackets", false); + ((EditText)FindViewById(Resource.Id.length)).Text = prefs.GetInt("length", 12).ToString(CultureInfo.InvariantCulture); foreach (int id in _buttonIds) { Button button = (Button) FindViewById(id); @@ -122,6 +135,22 @@ namespace keepass2android ((CheckBox) FindViewById(Resource.Id.cb_space)).Checked, ((CheckBox) FindViewById(Resource.Id.cb_specials)).Checked, ((CheckBox) FindViewById(Resource.Id.cb_brackets)).Checked); + + var prefs = GetPreferences(FileCreationMode.Private); + prefs.Edit() + .PutBoolean("cb_uppercase", ((CheckBox) FindViewById(Resource.Id.cb_uppercase)).Checked) + .PutBoolean("cb_lowercase", ((CheckBox) FindViewById(Resource.Id.cb_lowercase)).Checked) + .PutBoolean("cb_digits", ((CheckBox) FindViewById(Resource.Id.cb_digits)).Checked) + .PutBoolean("cb_minus", ((CheckBox) FindViewById(Resource.Id.cb_minus)).Checked) + .PutBoolean("cb_underline", ((CheckBox) FindViewById(Resource.Id.cb_underline)).Checked) + .PutBoolean("cb_space", ((CheckBox) FindViewById(Resource.Id.cb_space)).Checked) + .PutBoolean("cb_specials", ((CheckBox) FindViewById(Resource.Id.cb_specials)).Checked) + .PutBoolean("cb_brackets", ((CheckBox) FindViewById(Resource.Id.cb_brackets)).Checked) + .PutInt("length", length) + .Commit(); + + + } catch (ArgumentException e) { Toast.MakeText(this, e.Message, ToastLength.Long).Show(); }