Merge pull request #1112 from chipset95/issue-1106-imp

Improved EmailEditText, Added NameEditText, Removed PasswordEditText #1106
This commit is contained in:
Dominik Schürmann 2015-03-09 16:08:45 +01:00
commit d8c4867825
6 changed files with 55 additions and 56 deletions

View File

@ -24,22 +24,20 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText; import android.widget.EditText;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
import org.sufficientlysecure.keychain.ui.widget.EmailEditText; 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.ui.widget.PassphraseEditText;
import org.sufficientlysecure.keychain.util.ContactHelper;
public class CreateKeyInputFragment extends Fragment { public class CreateKeyInputFragment extends Fragment {
public static final String ARG_NAME = "name"; public static final String ARG_NAME = "name";
public static final String ARG_EMAIL = "email"; public static final String ARG_EMAIL = "email";
CreateKeyActivity mCreateKeyActivity; CreateKeyActivity mCreateKeyActivity;
AutoCompleteTextView mNameEdit; NameEditText mNameEdit;
EmailEditText mEmailEdit; EmailEditText mEmailEdit;
PassphraseEditText mPassphraseEdit; PassphraseEditText mPassphraseEdit;
EditText mPassphraseEditAgain; EditText mPassphraseEditAgain;
@ -98,7 +96,7 @@ public class CreateKeyInputFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.create_key_input_fragment, container, false); 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); mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase);
mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email); mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email);
mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again); mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again);
@ -116,24 +114,6 @@ public class CreateKeyInputFragment extends Fragment {
} else if (name != null) { } else if (name != null) {
mEmailEdit.requestFocus(); 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() { mCreateButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {

View File

@ -33,8 +33,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -44,7 +42,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.ui.widget.EmailEditText; 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; import org.sufficientlysecure.keychain.util.Log;
public class AddUserIdDialogFragment extends DialogFragment implements OnEditorActionListener { 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"; public static final String MESSAGE_DATA_USER_ID = "user_id";
private Messenger mMessenger; private Messenger mMessenger;
private AutoCompleteTextView mName; private NameEditText mName;
private EmailEditText mEmail; private EmailEditText mEmail;
private EditText mComment; private EditText mComment;
@ -81,11 +79,6 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA
mMessenger = getArguments().getParcelable(ARG_MESSENGER); mMessenger = getArguments().getParcelable(ARG_MESSENGER);
String predefinedName = getArguments().getString(ARG_NAME); String predefinedName = getArguments().getString(ARG_NAME);
ArrayAdapter<String> autoCompleteEmailAdapter = new ArrayAdapter<>
(getActivity(), android.R.layout.simple_spinner_dropdown_item,
ContactHelper.getPossibleUserEmails(getActivity())
);
CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);
alert.setTitle(R.string.edit_key_action_add_identity); 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); View view = inflater.inflate(R.layout.add_user_id_dialog, null);
alert.setView(view); 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); mEmail = (EmailEditText) view.findViewById(R.id.add_user_id_address);
mComment = (EditText) view.findViewById(R.id.add_user_id_comment); mComment = (EditText) view.findViewById(R.id.add_user_id_comment);
mName.setText(predefinedName); mName.setText(predefinedName);
mEmail.setThreshold(1); // Start working from first character
mEmail.setAdapter(autoCompleteEmailAdapter);
alert.setPositiveButton(android.R.string.ok, new OnClickListener() { alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { 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() { alert.setNegativeButton(android.R.string.cancel, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {

View File

@ -25,6 +25,7 @@ import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Patterns; import android.util.Patterns;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
@ -41,6 +42,8 @@ public class EmailEditText extends AutoCompleteTextView {
emailEditText = this; emailEditText = this;
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
this.addTextChangedListener(textWatcher); this.addTextChangedListener(textWatcher);
removeFlag();
makeAdapter();
} }
public EmailEditText(Context context, AttributeSet attrs) { public EmailEditText(Context context, AttributeSet attrs) {
@ -48,6 +51,8 @@ public class EmailEditText extends AutoCompleteTextView {
emailEditText = this; emailEditText = this;
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
this.addTextChangedListener(textWatcher); this.addTextChangedListener(textWatcher);
removeFlag();
makeAdapter();
} }
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) { public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) {
@ -55,6 +60,8 @@ public class EmailEditText extends AutoCompleteTextView {
emailEditText = this; emailEditText = this;
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
this.addTextChangedListener(textWatcher); this.addTextChangedListener(textWatcher);
removeFlag();
makeAdapter();
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
@ -63,6 +70,8 @@ public class EmailEditText extends AutoCompleteTextView {
emailEditText = this; emailEditText = this;
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
this.addTextChangedListener(textWatcher); this.addTextChangedListener(textWatcher);
removeFlag();
makeAdapter();
} }
TextWatcher textWatcher = new TextWatcher() { 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);
}
} }

View File

@ -17,30 +17,40 @@
package org.sufficientlysecure.keychain.ui.widget; package org.sufficientlysecure.keychain.ui.widget;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
/** import org.sufficientlysecure.keychain.util.ContactHelper;
* Hack to re-enable keyboard auto correction in AutoCompleteTextView.
* From http://stackoverflow.com/a/22512858
*/
public class AutoCorrectAutoCompleteTextView extends AutoCompleteTextView {
public AutoCorrectAutoCompleteTextView(Context context) { public class NameEditText extends AutoCompleteTextView {
public NameEditText(Context context) {
super(context); super(context);
removeFlag(); removeFlag();
makeAdapter();
} }
public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs) { public NameEditText(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
removeFlag(); removeFlag();
makeAdapter();
} }
public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) { public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyle); super(context, attrs, defStyleAttr);
removeFlag(); 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() { private void removeFlag() {
@ -48,4 +58,11 @@ public class AutoCorrectAutoCompleteTextView extends AutoCompleteTextView {
inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE; inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
setRawInputType(inputType); 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())));
}
} }

View File

@ -16,7 +16,7 @@
android:imeOptions="actionNext" android:imeOptions="actionNext"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<org.sufficientlysecure.keychain.ui.widget.AutoCorrectAutoCompleteTextView <org.sufficientlysecure.keychain.ui.widget.NameEditText
android:id="@+id/add_user_id_name" android:id="@+id/add_user_id_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -32,7 +32,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/label_user_id" /> android:text="@string/label_user_id" />
<org.sufficientlysecure.keychain.ui.widget.AutoCorrectAutoCompleteTextView <org.sufficientlysecure.keychain.ui.widget.NameEditText
android:id="@+id/create_key_name" android:id="@+id/create_key_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"