From d83219f3a0915c30b297aeaadfb37f1ba966d5c1 Mon Sep 17 00:00:00 2001 From: chipset95 Date: Fri, 6 Mar 2015 11:13:56 +0530 Subject: Created EmailEditText, PasswordEditText and implemented wherever required --- .../keychain/ui/CreateKeyInputFragment.java | 56 ++------------- .../ui/dialog/AddUserIdDialogFragment.java | 36 +--------- .../ui/dialog/SetPassphraseDialogFragment.java | 10 ++- .../keychain/ui/widget/EmailEditText.java | 80 +++++++++++++++++++++ .../keychain/ui/widget/PasswordEditText.java | 84 ++++++++++++++++++++++ 5 files changed, 182 insertions(+), 84 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java (limited to 'OpenKeychain/src/main/java/org') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java index 115614808..b496d40fd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java @@ -20,9 +20,6 @@ package org.sufficientlysecure.keychain.ui; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -33,19 +30,19 @@ import android.widget.EditText; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; +import org.sufficientlysecure.keychain.ui.widget.EmailEditText; +import org.sufficientlysecure.keychain.ui.widget.PasswordEditText; import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView; import org.sufficientlysecure.keychain.util.ContactHelper; -import java.util.regex.Matcher; - public class CreateKeyInputFragment extends Fragment { CreateKeyActivity mCreateKeyActivity; PasswordStrengthView mPassphraseStrengthView; AutoCompleteTextView mNameEdit; - AutoCompleteTextView mEmailEdit; - EditText mPassphraseEdit; + EmailEditText mEmailEdit; + PasswordEditText mPassphraseEdit; EditText mPassphraseEditAgain; View mCreateButton; @@ -74,8 +71,8 @@ public class CreateKeyInputFragment extends Fragment { mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id .create_key_passphrase_strength); mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_name); - mEmailEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_email); - mPassphraseEdit = (EditText) view.findViewById(R.id.create_key_passphrase); + mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); + mPassphraseEdit = (PasswordEditText) view.findViewById(R.id.create_key_passphrase); mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); mCreateButton = view.findViewById(R.id.create_key_button); @@ -99,33 +96,7 @@ public class CreateKeyInputFragment extends Fragment { ContactHelper.getPossibleUserEmails(getActivity()) ) ); - mEmailEdit.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()) { - mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_ok, 0); - } else { - mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); - } - } else { - // remove drawable if email is empty - mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } - } - }); mNameEdit.setThreshold(1); // Start working from first character mNameEdit.setAdapter( @@ -141,21 +112,8 @@ public class CreateKeyInputFragment extends Fragment { mPassphraseEdit.getPaddingTop(), (int) (56 * getResources().getDisplayMetrics().density), mPassphraseEdit.getPaddingBottom()); - mPassphraseEdit.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - @Override - public void afterTextChanged(Editable editable) { - String passphrase = editable.toString(); - mPassphraseStrengthView.setPassword(passphrase); - } - }); + mPassphraseEdit.setPasswordStrengthView(mPassphraseStrengthView); mCreateButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java index 094c4d8a9..ee4af8cbe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddUserIdDialogFragment.java @@ -28,9 +28,6 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.support.v4.app.DialogFragment; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Patterns; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -46,11 +43,10 @@ import android.widget.TextView.OnEditorActionListener; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; +import org.sufficientlysecure.keychain.ui.widget.EmailEditText; import org.sufficientlysecure.keychain.util.ContactHelper; import org.sufficientlysecure.keychain.util.Log; -import java.util.regex.Matcher; - public class AddUserIdDialogFragment extends DialogFragment implements OnEditorActionListener { private static final String ARG_MESSENGER = "messenger"; private static final String ARG_NAME = "name"; @@ -62,7 +58,7 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA private Messenger mMessenger; private AutoCompleteTextView mName; - private AutoCompleteTextView mEmail; + private EmailEditText mEmail; private EditText mComment; public static AddUserIdDialogFragment newInstance(Messenger messenger, String predefinedName) { @@ -99,38 +95,12 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA alert.setView(view); mName = (AutoCompleteTextView) view.findViewById(R.id.add_user_id_name); - mEmail = (AutoCompleteTextView) view.findViewById(R.id.add_user_id_address); + mEmail = (EmailEditText) view.findViewById(R.id.add_user_id_address); mComment = (EditText) view.findViewById(R.id.add_user_id_comment); mName.setText(predefinedName); - mEmail.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - @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, - R.drawable.uid_mail_ok, 0); - } else { - mEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, - R.drawable.uid_mail_bad, 0); - } - } else { - // remove drawable if email is empty - mEmail.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } - } - }); mEmail.setThreshold(1); // Start working from first character mEmail.setAdapter(autoCompleteEmailAdapter); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java index a3ffe250b..9e1f21f60 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java @@ -43,6 +43,8 @@ import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.widget.PasswordEditText; +import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView; import org.sufficientlysecure.keychain.util.Log; public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener { @@ -55,9 +57,10 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase"; private Messenger mMessenger; - private EditText mPassphraseEditText; + private PasswordEditText mPassphraseEditText; private EditText mPassphraseAgainEditText; private CheckBox mNoPassphraseCheckBox; + private PasswordStrengthView mPassphraseStrengthView; /** * Creates new instance of this dialog fragment @@ -97,9 +100,12 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi View view = inflater.inflate(R.layout.passphrase_repeat_dialog, null); alert.setView(view); - mPassphraseEditText = (EditText) view.findViewById(R.id.passphrase_passphrase); + mPassphraseEditText = (PasswordEditText) view.findViewById(R.id.passphrase_passphrase); mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again); mNoPassphraseCheckBox = (CheckBox) view.findViewById(R.id.passphrase_no_passphrase); + mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id.passphrase_repeat_passphrase_strength); + mPassphraseEditText.setPasswordStrengthView(mPassphraseStrengthView); + if (TextUtils.isEmpty(oldPassphrase)) { mNoPassphraseCheckBox.setChecked(true); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java new file mode 100644 index 000000000..22845fda0 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java @@ -0,0 +1,80 @@ +package org.sufficientlysecure.keychain.ui.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.text.Editable; +import android.text.InputType; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.util.Patterns; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.ContactHelper; + +import java.util.regex.Matcher; + +public class EmailEditText extends AutoCompleteTextView { + EmailEditText emailEditText; + + public EmailEditText(Context context) { + super(context); + emailEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + this.addTextChangedListener(textWatcher); + } + + public EmailEditText(Context context, AttributeSet attrs) { + super(context, attrs); + emailEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + this.addTextChangedListener(textWatcher); + } + + public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + emailEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + this.addTextChangedListener(textWatcher); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + emailEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + this.addTextChangedListener(textWatcher); + } + + TextWatcher textWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable editable) { + String email = editable.toString(); + if (email.length() > 0) { + Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email); + if (emailMatcher.matches()) { + emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_ok, 0); + } else { + emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, + R.drawable.uid_mail_bad, 0); + } + } else { + // remove drawable if email is empty + emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + } + }; +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java new file mode 100644 index 000000000..dea9e5163 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java @@ -0,0 +1,84 @@ +package org.sufficientlysecure.keychain.ui.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.text.Editable; +import android.text.InputType; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.widget.EditText; + +import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView; + +/** + * Developer: chipset + * Package : org.sufficientlysecure.keychain.layouts + * Project : open-keychain + * Date : 6/3/15 + */ +public class PasswordEditText extends EditText { + + PasswordEditText passwordEditText; + PasswordStrengthView passwordStrengthView; + + public PasswordEditText(Context context) { + super(context); + passwordEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + this.addTextChangedListener(textWatcher); + } + + public PasswordEditText(Context context, AttributeSet attrs) { + super(context, attrs); + passwordEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + this.addTextChangedListener(textWatcher); + } + + public PasswordEditText(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + passwordEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + this.addTextChangedListener(textWatcher); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public PasswordEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + passwordEditText = this; + this.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + this.addTextChangedListener(textWatcher); + } + + + TextWatcher textWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable editable) { + String passphrase = editable.toString(); + passwordStrengthView.setPassword(passphrase); + } + }; + +// public PasswordStrengthView getPasswordStrengthView() { +// return passwordStrengthView; +// } + + public void setPasswordStrengthView(PasswordStrengthView mPasswordStrengthView) { + this.passwordStrengthView = mPasswordStrengthView; + } +} -- cgit v1.2.3 From 7c2fefe2f7b9f6f7d770e37041336ae563518e93 Mon Sep 17 00:00:00 2001 From: chipset95 Date: Fri, 6 Mar 2015 14:47:11 +0530 Subject: Added GPLv3 License --- .../keychain/ui/widget/EmailEditText.java | 17 +++++++++++++++++ .../keychain/ui/widget/PasswordEditText.java | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'OpenKeychain/src/main/java/org') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java index 22845fda0..697f5a61e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.sufficientlysecure.keychain.ui.widget; import android.annotation.TargetApi; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java index dea9e5163..04c48922b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.sufficientlysecure.keychain.ui.widget; import android.annotation.TargetApi; -- cgit v1.2.3