mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-15 13:25:06 -05:00
Cleanup new widgets
This commit is contained in:
parent
d8c4867825
commit
bd1705410a
@ -35,43 +35,33 @@ import org.sufficientlysecure.keychain.util.ContactHelper;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
public class EmailEditText extends AutoCompleteTextView {
|
public class EmailEditText extends AutoCompleteTextView {
|
||||||
EmailEditText emailEditText;
|
|
||||||
|
|
||||||
public EmailEditText(Context context) {
|
public EmailEditText(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
emailEditText = this;
|
init();
|
||||||
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
|
||||||
this.addTextChangedListener(textWatcher);
|
|
||||||
removeFlag();
|
|
||||||
makeAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmailEditText(Context context, AttributeSet attrs) {
|
public EmailEditText(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
emailEditText = this;
|
init();
|
||||||
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) {
|
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
emailEditText = this;
|
init();
|
||||||
this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
|
||||||
this.addTextChangedListener(textWatcher);
|
|
||||||
removeFlag();
|
|
||||||
makeAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
emailEditText = this;
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
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();
|
removeFlag();
|
||||||
makeAdapter();
|
initAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWatcher textWatcher = new TextWatcher() {
|
TextWatcher textWatcher = new TextWatcher() {
|
||||||
@ -91,25 +81,29 @@ public class EmailEditText extends AutoCompleteTextView {
|
|||||||
if (email.length() > 0) {
|
if (email.length() > 0) {
|
||||||
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
|
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
|
||||||
if (emailMatcher.matches()) {
|
if (emailMatcher.matches()) {
|
||||||
emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||||
R.drawable.uid_mail_ok, 0);
|
R.drawable.uid_mail_ok, 0);
|
||||||
} else {
|
} else {
|
||||||
emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||||
R.drawable.uid_mail_bad, 0);
|
R.drawable.uid_mail_bad, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// remove drawable if email is empty
|
// remove drawable if email is empty
|
||||||
emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void makeAdapter() {
|
private void initAdapter() {
|
||||||
this.setThreshold(1); // Start working from first character
|
setThreshold(1); // Start working from first character
|
||||||
this.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item,
|
setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item,
|
||||||
ContactHelper.getPossibleUserEmails(getContext())));
|
ContactHelper.getPossibleUserEmails(getContext())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hack to re-enable keyboard auto correction in AutoCompleteTextView.
|
||||||
|
* From http://stackoverflow.com/a/22512858
|
||||||
|
*/
|
||||||
private void removeFlag() {
|
private void removeFlag() {
|
||||||
int inputType = getInputType();
|
int inputType = getInputType();
|
||||||
inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
|
inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
|
||||||
|
@ -30,39 +30,44 @@ import org.sufficientlysecure.keychain.util.ContactHelper;
|
|||||||
public class NameEditText extends AutoCompleteTextView {
|
public class NameEditText extends AutoCompleteTextView {
|
||||||
public NameEditText(Context context) {
|
public NameEditText(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
removeFlag();
|
init();
|
||||||
makeAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NameEditText(Context context, AttributeSet attrs) {
|
public NameEditText(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
removeFlag();
|
init();
|
||||||
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();
|
init();
|
||||||
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();
|
init();
|
||||||
makeAdapter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
removeFlag();
|
||||||
|
initAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initAdapter() {
|
||||||
|
setThreshold(1); // Start working from first character
|
||||||
|
setAdapter(new ArrayAdapter<>(
|
||||||
|
getContext(), android.R.layout.simple_spinner_dropdown_item,
|
||||||
|
ContactHelper.getPossibleUserNames(getContext())));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hack to re-enable keyboard auto correction in AutoCompleteTextView.
|
||||||
|
* From http://stackoverflow.com/a/22512858
|
||||||
|
*/
|
||||||
private void removeFlag() {
|
private void removeFlag() {
|
||||||
int inputType = getInputType();
|
int inputType = getInputType();
|
||||||
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())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,10 @@ public class PassphraseEditText extends EditText {
|
|||||||
|
|
||||||
public PassphraseEditText(Context context, AttributeSet attrs) {
|
public PassphraseEditText(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
init(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context, AttributeSet attrs) {
|
||||||
mPasswordBarHeight = (int) (8 * getResources().getDisplayMetrics().density);
|
mPasswordBarHeight = (int) (8 * getResources().getDisplayMetrics().density);
|
||||||
mPasswordBarWidth = (int) (50 * getResources().getDisplayMetrics().density);
|
mPasswordBarWidth = (int) (50 * getResources().getDisplayMetrics().density);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user