aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-10 00:57:23 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-10 00:57:23 +0100
commit4db86fdabe80cffba13b5e18e1576b5d8de39e8d (patch)
tree80ca70fdd019824c65fc3b73740b1311cecc257e /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget
parentf76f84dfb2e406dd613be04dabd9432ffd0f9c4b (diff)
parente3547b497932a1c0219c11d586858754c82d19da (diff)
downloadopen-keychain-4db86fdabe80cffba13b5e18e1576b5d8de39e8d.tar.gz
open-keychain-4db86fdabe80cffba13b5e18e1576b5d8de39e8d.tar.bz2
open-keychain-4db86fdabe80cffba13b5e18e1576b5d8de39e8d.zip
Merge remote-tracking branch 'development' into linked-identities
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.java43
-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)44
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java88
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordEditText.java101
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java8
5 files changed, 155 insertions, 129 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..1bdec7b84 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;
@@ -34,35 +35,33 @@ import org.sufficientlysecure.keychain.util.ContactHelper;
import java.util.regex.Matcher;
public class EmailEditText extends AutoCompleteTextView {
- EmailEditText emailEditText;
public EmailEditText(Context context) {
super(context);
- emailEditText = this;
- this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
- this.addTextChangedListener(textWatcher);
+ init();
}
public EmailEditText(Context context, AttributeSet attrs) {
super(context, attrs);
- emailEditText = this;
- this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
- this.addTextChangedListener(textWatcher);
+ init();
}
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- emailEditText = this;
- this.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
- this.addTextChangedListener(textWatcher);
+ init();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public EmailEditText(Context context, AttributeSet attrs, int defStyleAttr, int 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.addTextChangedListener(textWatcher);
+ removeFlag();
+ initAdapter();
}
TextWatcher textWatcher = new TextWatcher() {
@@ -82,16 +81,32 @@ public class EmailEditText extends AutoCompleteTextView {
if (email.length() > 0) {
Matcher emailMatcher = Patterns.EMAIL_ADDRESS.matcher(email);
if (emailMatcher.matches()) {
- emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0,
+ EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_ok, 0);
} else {
- emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0,
+ EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.uid_mail_bad, 0);
}
} else {
// remove drawable if email is empty
- emailEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
+ EmailEditText.this.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
}
};
+
+ private void initAdapter() {
+ setThreshold(1); // Start working from first character
+ setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item,
+ ContactHelper.getPossibleUserEmails(getContext())));
+ }
+
+ /**
+ * Hack to re-enable keyboard auto correction in AutoCompleteTextView.
+ * From http://stackoverflow.com/a/22512858
+ */
+ 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..f086c5696 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,32 +17,54 @@
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();
+ init();
}
- public AutoCorrectAutoCompleteTextView(Context context, AttributeSet attrs) {
+ public NameEditText(Context context, AttributeSet attrs) {
super(context, attrs);
- removeFlag();
+ init();
+ }
+
+ public NameEditText(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init();
}
- 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);
+ init();
+ }
+
+ 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() {
int inputType = getInputType();
inputType &= ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java
new file mode 100644
index 000000000..377f701d1
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java
@@ -0,0 +1,88 @@
+/*
+ * 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.graphics.Canvas;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.widget.EditText;
+
+import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthBarView;
+
+public class PassphraseEditText extends EditText {
+
+ PasswordStrengthBarView mPasswordStrengthBarView;
+ int mPasswordBarWidth;
+ int mPasswordBarHeight;
+ float barGap;
+
+ public PassphraseEditText(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context, attrs);
+ }
+
+ private void init(Context context, AttributeSet attrs) {
+ mPasswordBarHeight = (int) (8 * getResources().getDisplayMetrics().density);
+ mPasswordBarWidth = (int) (50 * getResources().getDisplayMetrics().density);
+
+ barGap = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
+ getContext().getResources().getDisplayMetrics());
+
+ this.setPadding(getPaddingLeft(), getPaddingTop(),
+ getPaddingRight() + (int) barGap + mPasswordBarWidth, getPaddingBottom());
+
+ mPasswordStrengthBarView = new PasswordStrengthBarView(context, attrs);
+ mPasswordStrengthBarView.setShowGuides(false);
+
+ this.addTextChangedListener(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) {
+ mPasswordStrengthBarView.setPassword(s.toString());
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ }
+ });
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ mPasswordStrengthBarView.layout(0, 0, mPasswordBarWidth, mPasswordBarHeight);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ float translateX = getScrollX() + canvas.getWidth() - mPasswordBarWidth;
+ float translateY = (canvas.getHeight() - mPasswordBarHeight) / 2;
+ canvas.translate(translateX, translateY);
+ mPasswordStrengthBarView.draw(canvas);
+ canvas.translate(-translateX, -translateY);
+ }
+} \ No newline at end of file
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 <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.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;
- }
-}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java
index d7270ff58..bc5018497 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java
@@ -56,9 +56,6 @@ import org.sufficientlysecure.keychain.R;
*/
public class PasswordStrengthView extends View {
- protected static final int COLOR_FAIL = Color.parseColor("#e74c3c");
- protected static final int COLOR_WEAK = Color.parseColor("#e67e22");
- protected static final int COLOR_STRONG = Color.parseColor("#2ecc71");
protected int mMinWidth;
protected int mMinHeight;
@@ -100,6 +97,11 @@ public class PasswordStrengthView extends View {
public PasswordStrengthView(Context context, AttributeSet attrs) {
super(context, attrs);
+
+ int COLOR_FAIL = context.getResources().getColor(R.color.android_red_light);
+ int COLOR_WEAK = context.getResources().getColor(R.color.android_orange_light);
+ int COLOR_STRONG = context.getResources().getColor(R.color.android_green_light);
+
TypedArray style = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.PasswordStrengthView,