From e2c502a51131927ddc9cd9fba5e56c2642dd377a Mon Sep 17 00:00:00 2001 From: chipset95 Date: Mon, 9 Mar 2015 17:55:46 +0530 Subject: [PATCH 1/2] Improved EmailEditText, Added NameEditText, Removed PasswordEditText #1106 --- .../keychain/ui/widget/EmailEditText.java | 21 ++++ .../keychain/ui/widget/NameEditText.java | 64 +++++++++++ .../keychain/ui/widget/PasswordEditText.java | 101 ------------------ 3 files changed, 85 insertions(+), 101 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java 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 697f5a61e..e7ef788d8 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 @@ -25,6 +25,7 @@ import android.text.InputType; import android.text.TextWatcher; import android.util.AttributeSet; import android.util.Patterns; +import android.view.inputmethod.EditorInfo; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; @@ -41,6 +42,8 @@ public class EmailEditText extends AutoCompleteTextView { emailEditText = this; this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.addTextChangedListener(textWatcher); + removeFlag(); + makeAdapter(); } public EmailEditText(Context context, AttributeSet attrs) { @@ -48,6 +51,8 @@ public class EmailEditText extends AutoCompleteTextView { emailEditText = this; this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.addTextChangedListener(textWatcher); + removeFlag(); + makeAdapter(); } public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) { @@ -55,6 +60,8 @@ public class EmailEditText extends AutoCompleteTextView { emailEditText = this; this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.addTextChangedListener(textWatcher); + removeFlag(); + makeAdapter(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @@ -63,6 +70,8 @@ public class EmailEditText extends AutoCompleteTextView { emailEditText = this; this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.addTextChangedListener(textWatcher); + removeFlag(); + makeAdapter(); } TextWatcher textWatcher = new TextWatcher() { @@ -94,4 +103,16 @@ public class EmailEditText extends AutoCompleteTextView { } } }; + + private void makeAdapter() { + this.setThreshold(1); // Start working from first character + this.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, + ContactHelper.getPossibleUserEmails(getContext()))); + } + + private void removeFlag() { + int inputType = getInputType(); + inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE; + setRawInputType(inputType); + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java new file mode 100644 index 000000000..c7dfa6359 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java @@ -0,0 +1,64 @@ +/* + * 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; +import android.content.Context; +import android.os.Build; +import android.util.AttributeSet; +import android.view.inputmethod.EditorInfo; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; + +import org.sufficientlysecure.keychain.util.ContactHelper; + +public class NameEditText extends AutoCompleteTextView { + public NameEditText(Context context) { + super(context); + removeFlag(); + } + + public NameEditText(Context context, AttributeSet attrs) { + super(context, attrs); + removeFlag(); + } + + public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + removeFlag(); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public NameEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + removeFlag(); + } + + private void removeFlag() { + int inputType = getInputType(); + inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE; + setRawInputType(inputType); + } + + private void makeAdapter() { + this.setThreshold(1); // Start working from first character + this.setAdapter(new ArrayAdapter<>( + getContext(), android.R.layout.simple_spinner_dropdown_item, + ContactHelper.getPossibleUserNames(getContext()))); + } +} 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 deleted file mode 100644 index 04c48922b..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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; -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; - } -} From c55353e2b80faca6886293f744a48753b6435f71 Mon Sep 17 00:00:00 2001 From: chipset95 Date: Mon, 9 Mar 2015 18:12:44 +0530 Subject: [PATCH 2/2] Implemented NameEditText --- .../keychain/ui/CreateKeyInputFragment.java | 26 ++-------- .../ui/dialog/AddUserIdDialogFragment.java | 25 ++------- .../AutoCorrectAutoCompleteTextView.java | 51 ------------------- .../keychain/ui/widget/NameEditText.java | 4 ++ .../main/res/layout/add_user_id_dialog.xml | 2 +- .../res/layout/create_key_input_fragment.xml | 2 +- 6 files changed, 12 insertions(+), 98 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java 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 ecc609212..05408e21e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java @@ -24,22 +24,20 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; 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.NameEditText; import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText; -import org.sufficientlysecure.keychain.util.ContactHelper; public class CreateKeyInputFragment extends Fragment { public static final String ARG_NAME = "name"; public static final String ARG_EMAIL = "email"; CreateKeyActivity mCreateKeyActivity; - AutoCompleteTextView mNameEdit; + NameEditText mNameEdit; EmailEditText mEmailEdit; PassphraseEditText mPassphraseEdit; EditText mPassphraseEditAgain; @@ -98,7 +96,7 @@ public class CreateKeyInputFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.create_key_input_fragment, container, false); - mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_name); + mNameEdit = (NameEditText) view.findViewById(R.id.create_key_name); mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase); mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); @@ -116,24 +114,6 @@ public class CreateKeyInputFragment extends Fragment { } else if (name != null) { mEmailEdit.requestFocus(); } - - mEmailEdit.setThreshold(1); // Start working from first character - mEmailEdit.setAdapter( - new ArrayAdapter<> - (getActivity(), android.R.layout.simple_spinner_dropdown_item, - ContactHelper.getPossibleUserEmails(getActivity()) - ) - ); - - - mNameEdit.setThreshold(1); // Start working from first character - mNameEdit.setAdapter( - new ArrayAdapter<> - (getActivity(), android.R.layout.simple_spinner_dropdown_item, - ContactHelper.getPossibleUserNames(getActivity()) - ) - ); - mCreateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { 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 ee4af8cbe..5dd675fd3 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 @@ -33,8 +33,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -44,7 +42,7 @@ 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.ui.widget.NameEditText; import org.sufficientlysecure.keychain.util.Log; public class AddUserIdDialogFragment extends DialogFragment implements OnEditorActionListener { @@ -57,7 +55,7 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA public static final String MESSAGE_DATA_USER_ID = "user_id"; private Messenger mMessenger; - private AutoCompleteTextView mName; + private NameEditText mName; private EmailEditText mEmail; private EditText mComment; @@ -81,11 +79,6 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA mMessenger = getArguments().getParcelable(ARG_MESSENGER); String predefinedName = getArguments().getString(ARG_NAME); - ArrayAdapter autoCompleteEmailAdapter = new ArrayAdapter<> - (getActivity(), android.R.layout.simple_spinner_dropdown_item, - ContactHelper.getPossibleUserEmails(getActivity()) - ); - CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.edit_key_action_add_identity); @@ -94,16 +87,12 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA View view = inflater.inflate(R.layout.add_user_id_dialog, null); alert.setView(view); - mName = (AutoCompleteTextView) view.findViewById(R.id.add_user_id_name); + mName = (NameEditText) view.findViewById(R.id.add_user_id_name); mEmail = (EmailEditText) view.findViewById(R.id.add_user_id_address); mComment = (EditText) view.findViewById(R.id.add_user_id_comment); mName.setText(predefinedName); - - mEmail.setThreshold(1); // Start working from first character - mEmail.setAdapter(autoCompleteEmailAdapter); - alert.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { @@ -118,14 +107,6 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA } }); - mName.setThreshold(1); // Start working from first character - mName.setAdapter( - new ArrayAdapter<> - (getActivity(), android.R.layout.simple_spinner_dropdown_item, - ContactHelper.getPossibleUserNames(getActivity()) - ) - ); - alert.setNegativeButton(android.R.string.cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java deleted file mode 100644 index ed373a938..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.content.Context; -import android.util.AttributeSet; -import android.view.inputmethod.EditorInfo; -import android.widget.AutoCompleteTextView; - -/** - * Hack to re-enable keyboard auto correction in AutoCompleteTextView. - * From http://stackoverflow.com/a/22512858 - */ -public class AutoCorrectAutoCompleteTextView extends AutoCompleteTextView { - - public AutoCorrectAutoCompleteTextView(Context context) { - super(context); - removeFlag(); - } - - public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs) { - super(context, attrs); - removeFlag(); - } - - public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - removeFlag(); - } - - private void removeFlag() { - int inputType = getInputType(); - inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE; - setRawInputType(inputType); - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java index c7dfa6359..895cd45ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java @@ -31,22 +31,26 @@ public class NameEditText extends AutoCompleteTextView { public NameEditText(Context context) { super(context); removeFlag(); + makeAdapter(); } public NameEditText(Context context, AttributeSet attrs) { super(context, attrs); removeFlag(); + makeAdapter(); } public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); removeFlag(); + makeAdapter(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public NameEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); removeFlag(); + makeAdapter(); } private void removeFlag() { diff --git a/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml b/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml index c1b97b02c..ffb7493f6 100644 --- a/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml +++ b/OpenKeychain/src/main/res/layout/add_user_id_dialog.xml @@ -16,7 +16,7 @@ android:imeOptions="actionNext" android:textAppearance="?android:attr/textAppearanceMedium" /> - -