diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EmailEditText.java | 21 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java (renamed from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java) | 35 |
2 files changed, 47 insertions, 9 deletions
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/AutoCorrectAutoCompleteTextView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java index ed373a938..895cd45ec 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/AutoCorrectAutoCompleteTextView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NameEditText.java @@ -17,30 +17,40 @@ 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; -/** - * Hack to re-enable keyboard auto correction in AutoCompleteTextView. - * From http://stackoverflow.com/a/22512858 - */ -public class AutoCorrectAutoCompleteTextView extends AutoCompleteTextView { +import org.sufficientlysecure.keychain.util.ContactHelper; - public AutoCorrectAutoCompleteTextView(Context context) { +public class NameEditText extends AutoCompleteTextView { + public NameEditText(Context context) { super(context); removeFlag(); + makeAdapter(); } - public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs) { + 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(); } - public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); + @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() { @@ -48,4 +58,11 @@ public class AutoCorrectAutoCompleteTextView extends AutoCompleteTextView { 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()))); + } } |