diff options
author | uberspot <onexemailx@gmail.com> | 2014-03-13 23:52:21 +0200 |
---|---|---|
committer | uberspot <onexemailx@gmail.com> | 2014-03-14 00:02:31 +0200 |
commit | b12392594f54cac1ef8812c80decc315f70866db (patch) | |
tree | dd8049a48c79e9f204e7c4df9a09040f1c76d24b | |
parent | c737f01a727b9a6f074e88b31a025cd273f0a632 (diff) | |
download | open-keychain-b12392594f54cac1ef8812c80decc315f70866db.tar.gz open-keychain-b12392594f54cac1ef8812c80decc315f70866db.tar.bz2 open-keychain-b12392594f54cac1ef8812c80decc315f70866db.zip |
Make email address less restrictive and add icon to show when it's correct
2 files changed, 28 insertions, 11 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index a0186f08c..edf980773 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -600,8 +600,6 @@ public class EditKeyActivity extends ActionBarActivity { } catch (UserIdEditor.NoEmailException e) { throw new PgpGeneralException( this.getString(R.string.error_user_id_needs_an_email_address)); - } catch (UserIdEditor.InvalidEmailException e) { - throw new PgpGeneralException(e.getMessage()); } if (userId.equals("")) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java index d3c6f02fe..ed81b162e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java @@ -17,6 +17,8 @@ package org.sufficientlysecure.keychain.ui.widget; import android.content.Context; +import android.text.Editable; +import android.text.TextWatcher; import android.util.AttributeSet; import android.util.Patterns; import android.view.View; @@ -102,6 +104,31 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene (this.getContext(), android.R.layout.simple_dropdown_item_1line, ContactHelper.getMailAccounts(getContext()) )); + mEmail.addTextChangedListener(new TextWatcher(){ + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } + + @Override + public void afterTextChanged(Editable editable) { + String email = editable.toString(); + if (email.length() > 0) { + Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email); + if (emailMatcher.matches()) { + mEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, + android.R.drawable.presence_online, 0); + } else { + mEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, + android.R.drawable.presence_offline, 0); + } + } else { + // remove drawable if email is empty + mEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + } + }); super.onFinishInflate(); } @@ -129,19 +156,11 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene } } - public String getValue() throws NoNameException, NoEmailException, InvalidEmailException { + public String getValue() throws NoNameException, NoEmailException { String name = ("" + mName.getText()).trim(); String email = ("" + mEmail.getText()).trim(); String comment = ("" + mComment.getText()).trim(); - if (email.length() > 0) { - Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email); - if (!emailMatcher.matches()) { - throw new InvalidEmailException(getContext().getString(R.string.error_invalid_email, - email)); - } - } - String userId = name; if (comment.length() > 0) { userId += " (" + comment + ")"; |