added option to disable "clear password on leave" (eg. for switching between KP2A and Google Authenticator)
directly load db when enter key is pressed
This commit is contained in:
		| @@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasterKeePlugin", "MasterKe | ||||
| EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayServicesTest", "PlayServicesTest\PlayServicesTest.csproj", "{B8E78075-3936-42E9-9AB4-C82B341935A6}" | ||||
| EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App1", "App1\App1.csproj", "{A29ECF2C-3313-4F93-8B78-DC3F1319E835}" | ||||
| EndProject | ||||
| Global | ||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| 		Debug|Any CPU = Debug|Any CPU | ||||
| @@ -378,6 +380,30 @@ Global | ||||
| 		{B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|Win32.Build.0 = Release|Any CPU | ||||
| 		{B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|x64.ActiveCfg = Release|Any CPU | ||||
| 		{B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|x64.Build.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Win32.ActiveCfg = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|x64.ActiveCfg = Debug|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Win32.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|x64.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.Deploy.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.Build.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.Deploy.0 = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Win32.ActiveCfg = Release|Any CPU | ||||
| 		{A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|x64.ActiveCfg = Release|Any CPU | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(SolutionProperties) = preSolution | ||||
| 		HideSolutionNode = FALSE | ||||
|   | ||||
| @@ -28,6 +28,7 @@ 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; | ||||
| @@ -638,6 +639,11 @@ namespace keepass2android | ||||
| 					_password = FindViewById<EditText>(Resource.Id.password).Text; | ||||
| 					UpdateOkButtonState(); | ||||
| 				}; | ||||
| 			FindViewById<EditText>(Resource.Id.password).EditorAction += (sender, args) => | ||||
| 				{ | ||||
| 					if ((args.ActionId == ImeAction.Done) || ((args.ActionId == ImeAction.ImeNull) && (args.Event.Action == KeyEventActions.Down))) | ||||
| 						OnOk(); | ||||
| 				}; | ||||
|  | ||||
| 			FindViewById<EditText>(Resource.Id.pass_otpsecret).TextChanged += (sender, args) => UpdateOkButtonState(); | ||||
|  | ||||
| @@ -767,12 +773,17 @@ namespace keepass2android | ||||
| 			Button confirmButton = (Button) FindViewById(Resource.Id.pass_ok); | ||||
| 			confirmButton.Click += (sender, e) => | ||||
| 				{ | ||||
| 					App.Kp2a.GetFileStorage(_ioConnection) | ||||
| 					   .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), _ioConnection, | ||||
| 					                     RequestCodePrepareDbFile, false); | ||||
| 					OnOk(); | ||||
| 				}; | ||||
| 		} | ||||
|  | ||||
| 		private void OnOk() | ||||
| 		{ | ||||
| 			App.Kp2a.GetFileStorage(_ioConnection) | ||||
| 			   .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), _ioConnection, | ||||
| 			                     RequestCodePrepareDbFile, false); | ||||
| 		} | ||||
|  | ||||
| 		private void InitializeTogglePasswordButton() | ||||
| 		{ | ||||
| 			ImageButton btnTogglePassword = (ImageButton) FindViewById(Resource.Id.toggle_password); | ||||
| @@ -1277,7 +1288,13 @@ namespace keepass2android | ||||
|  | ||||
| 			if (!_keepPasswordInOnResume) | ||||
| 			{ | ||||
| 				ClearEnteredPassword(); | ||||
| 				if ( | ||||
| 					PreferenceManager.GetDefaultSharedPreferences(this) | ||||
| 					                 .GetBoolean(GetString(Resource.String.ClearPasswordOnLeave_key), true)) | ||||
| 				{ | ||||
| 					ClearEnteredPassword(); | ||||
| 				} | ||||
| 				 | ||||
| 			} | ||||
| 			_keepPasswordInOnResume = false; | ||||
|  | ||||
|   | ||||
| @@ -101,20 +101,7 @@ namespace keepass2android | ||||
| 			Button btnUnlock = (Button) FindViewById(Resource.Id.QuickUnlock_button); | ||||
| 			btnUnlock.Click += (object sender, EventArgs e) => | ||||
| 				{ | ||||
| 					KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword)); | ||||
| 					String password = kcpPassword.Password.ReadString(); | ||||
| 					String expectedPasswordPart = password.Substring(Math.Max(0, password.Length - quickUnlockLength), | ||||
| 					                                                 Math.Min(password.Length, quickUnlockLength)); | ||||
| 					if (pwd.Text == expectedPasswordPart) | ||||
| 					{ | ||||
| 						App.Kp2a.UnlockDatabase(); | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| 						App.Kp2a.LockDatabase(false); | ||||
| 						Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show(); | ||||
| 					} | ||||
| 					Finish(); | ||||
| 					OnUnlock(quickUnlockLength, pwd); | ||||
| 				}; | ||||
|  | ||||
| 			Button btnLock = (Button) FindViewById(Resource.Id.QuickUnlock_buttonLock); | ||||
| @@ -123,6 +110,11 @@ namespace keepass2android | ||||
| 					App.Kp2a.LockDatabase(false); | ||||
| 					Finish(); | ||||
| 				}; | ||||
| 			pwd.EditorAction += (sender, args) => | ||||
| 				{ | ||||
| 					if ((args.ActionId == ImeAction.Done) || ((args.ActionId == ImeAction.ImeNull) && (args.Event.Action == KeyEventActions.Down))) | ||||
| 						OnUnlock(quickUnlockLength, pwd); | ||||
| 				}; | ||||
|  | ||||
| 			_intentReceiver = new QuickUnlockBroadcastReceiver(this); | ||||
| 			IntentFilter filter = new IntentFilter(); | ||||
| @@ -130,6 +122,24 @@ namespace keepass2android | ||||
| 			RegisterReceiver(_intentReceiver, filter); | ||||
| 		} | ||||
|  | ||||
| 		private void OnUnlock(int quickUnlockLength, EditText pwd) | ||||
| 		{ | ||||
| 			KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword)); | ||||
| 			String password = kcpPassword.Password.ReadString(); | ||||
| 			String expectedPasswordPart = password.Substring(Math.Max(0, password.Length - quickUnlockLength), | ||||
| 			                                                 Math.Min(password.Length, quickUnlockLength)); | ||||
| 			if (pwd.Text == expectedPasswordPart) | ||||
| 			{ | ||||
| 				App.Kp2a.UnlockDatabase(); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				App.Kp2a.LockDatabase(false); | ||||
| 				Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show(); | ||||
| 			} | ||||
| 			Finish(); | ||||
| 		} | ||||
|  | ||||
| 		private void OnLockDatabase() | ||||
| 		{ | ||||
| 			CheckIfUnloaded(); | ||||
|   | ||||
| @@ -172,4 +172,6 @@ | ||||
| 	<string name="PreloadDatabaseEnabled_key">PreloadDatabaseEnabled</string> | ||||
| 	<bool name="PreloadDatabaseEnabled_default">true</bool> | ||||
|  | ||||
| 	<string name="ClearPasswordOnLeave_key">ClearPasswordOnLeave</string> | ||||
|  | ||||
| </resources> | ||||
| @@ -282,6 +282,9 @@ | ||||
|   <string name="UseFileTransactions_summary">Use file transactions for writing databases</string> | ||||
| 	<string name="LockWhenScreenOff_title">Lock when screen off</string> | ||||
|   <string name="LockWhenScreenOff_summary">Lock the database when screen is switched off.</string> | ||||
|  | ||||
| 	<string name="ClearPasswordOnLeave_title">Clear entered master password</string> | ||||
| 	<string name="ClearPasswordOnLeave_summary">Clear the entered master password when leaving the screen without unlocking the database.</string> | ||||
| 	 | ||||
| 	<string name="LockWhenNavigateBack_title">Lock when leaving app</string> | ||||
| 	<string name="LockWhenNavigateBack_summary">Lock the database when leaving the app by pressing the back button.</string> | ||||
|   | ||||
| @@ -127,6 +127,15 @@ | ||||
| 				android:title="@string/show_kill_app" | ||||
| 				android:summary="@string/show_kill_app_summary" | ||||
| 				android:defaultValue="false"/> | ||||
| 			 | ||||
| 			<CheckBoxPreference | ||||
| 			     android:enabled="true" | ||||
| 				 android:persistent="true" | ||||
| 				 android:summary="@string/ClearPasswordOnLeave_summary" | ||||
| 				 android:defaultValue="false" | ||||
| 				 android:title="@string/ClearPasswordOnLeave_title" | ||||
| 				 android:key="@string/ClearPasswordOnLeave_key" /> | ||||
|  | ||||
|  | ||||
| 		</PreferenceScreen> | ||||
| 		<PreferenceScreen | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Philipp Crocoll
					Philipp Crocoll