Implemented NameEditText

This commit is contained in:
chipset95 2015-03-09 18:12:44 +05:30
parent e2c502a511
commit c55353e2b8
6 changed files with 12 additions and 98 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

@ -1,51 +0,0 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@ -31,22 +31,26 @@ public class NameEditText extends AutoCompleteTextView {
public NameEditText(Context context) { public NameEditText(Context context) {
super(context); super(context);
removeFlag(); removeFlag();
makeAdapter();
} }
public NameEditText(Context context, AttributeSet attrs) { public NameEditText(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
removeFlag(); removeFlag();
makeAdapter();
} }
public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) { public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
removeFlag(); removeFlag();
makeAdapter();
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NameEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public NameEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
removeFlag(); removeFlag();
makeAdapter();
} }
private void removeFlag() { private void removeFlag() {

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"