From 1106f618eb9739746f26beba4bdd7051f1c8a86d Mon Sep 17 00:00:00 2001 From: PhilippC Date: Thu, 21 Mar 2013 01:22:27 +0100 Subject: [PATCH] Search when pressing "Enter" button --- .../Resources/layout/search.xml | 2 + src/keepass2android/search/SearchActivity.cs | 52 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/keepass2android/Resources/layout/search.xml b/src/keepass2android/Resources/layout/search.xml index 012405f3..b7bdde50 100644 --- a/src/keepass2android/Resources/layout/search.xml +++ b/src/keepass2android/Resources/layout/search.xml @@ -17,10 +17,12 @@ { - String searchString = ((EditText)FindViewById(Resource.Id.searchEditText)).Text; - if (String.IsNullOrWhiteSpace(searchString)) - return; - - SearchParameters spNew = new SearchParameters(); - - Intent searchIntent = new Intent(this, typeof(SearchResults)); - searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle)); - searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl)); - searchIntent.PutExtra("SearchInPasswords", GetCheckBoxValue(Resource.Id.cbSearchInPassword)); - searchIntent.PutExtra("SearchInUserNames", GetCheckBoxValue(Resource.Id.cbSearchInUsername)); - searchIntent.PutExtra("SearchInNotes", GetCheckBoxValue(Resource.Id.cbSearchInNotes)); - searchIntent.PutExtra("SearchInGroupNames", GetCheckBoxValue(Resource.Id.cbSearchInGroupName)); - searchIntent.PutExtra("SearchInOther", GetCheckBoxValue(Resource.Id.cbSearchInOtherStrings)); - searchIntent.PutExtra("SearchInTags", GetCheckBoxValue(Resource.Id.cbSearchInTags)); - searchIntent.PutExtra("RegularExpression", GetCheckBoxValue(Resource.Id.cbRegEx)); - searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive)); - searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries)); - searchIntent.PutExtra(SearchManager.Query, searchString); - - StartActivityForResult(searchIntent,0); - Finish(); + PerformSearch(); + }; + FindViewById(Resource.Id.searchEditText).EditorAction += (object sender, TextView.EditorActionEventArgs e) => + { + if (e.ActionId == Android.Views.InputMethods.ImeAction.Search) { + PerformSearch(); + } }; } void populateCheckBox(int resId, bool value) { ((CheckBox) FindViewById(resId)).Checked = value; } + + void PerformSearch() + { + String searchString = ((EditText)FindViewById(Resource.Id.searchEditText)).Text; + if (String.IsNullOrWhiteSpace(searchString)) + return; + SearchParameters spNew = new SearchParameters(); + Intent searchIntent = new Intent(this, typeof(SearchResults)); + searchIntent.PutExtra("SearchInTitles", GetCheckBoxValue(Resource.Id.cbSearchInTitle)); + searchIntent.PutExtra("SearchInUrls", GetCheckBoxValue(Resource.Id.cbSearchInUrl)); + searchIntent.PutExtra("SearchInPasswords", GetCheckBoxValue(Resource.Id.cbSearchInPassword)); + searchIntent.PutExtra("SearchInUserNames", GetCheckBoxValue(Resource.Id.cbSearchInUsername)); + searchIntent.PutExtra("SearchInNotes", GetCheckBoxValue(Resource.Id.cbSearchInNotes)); + searchIntent.PutExtra("SearchInGroupNames", GetCheckBoxValue(Resource.Id.cbSearchInGroupName)); + searchIntent.PutExtra("SearchInOther", GetCheckBoxValue(Resource.Id.cbSearchInOtherStrings)); + searchIntent.PutExtra("SearchInTags", GetCheckBoxValue(Resource.Id.cbSearchInTags)); + searchIntent.PutExtra("RegularExpression", GetCheckBoxValue(Resource.Id.cbRegEx)); + searchIntent.PutExtra("CaseSensitive", GetCheckBoxValue(Resource.Id.cbCaseSensitive)); + searchIntent.PutExtra("ExcludeExpired", GetCheckBoxValue(Resource.Id.cbExcludeExpiredEntries)); + searchIntent.PutExtra(SearchManager.Query, searchString); + StartActivityForResult(searchIntent, 0); + Finish(); + } } }