aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-03-09 12:51:00 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2015-03-09 12:51:00 +0100
commit7ac4f63ea367eaa4d560b04a211ed936da920685 (patch)
tree2e5067afbb36ca93e92b46c4d72c9c0c589eddd3 /OpenKeychain/src/main/java/org
parent4f11fb5a2f08ecf5fb81c86d590d04387cd1cd9a (diff)
parent820005bc378ba91a9851902b651dfff7836c9bbf (diff)
downloadopen-keychain-7ac4f63ea367eaa4d560b04a211ed936da920685.tar.gz
open-keychain-7ac4f63ea367eaa4d560b04a211ed936da920685.tar.bz2
open-keychain-7ac4f63ea367eaa4d560b04a211ed936da920685.zip
Merge pull request #1111 from adithyaphilip/passphrase-strength-indicator
Passphrase strength indicator
Diffstat (limited to 'OpenKeychain/src/main/java/org')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java93
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java10
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java84
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/passwordstrengthindicator/PasswordStrengthView.java8
4 files changed, 131 insertions, 64 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java
index b496d40fd..ecc609212 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyInputFragment.java
@@ -31,24 +31,20 @@ import android.widget.EditText;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
import org.sufficientlysecure.keychain.ui.widget.EmailEditText;
-import org.sufficientlysecure.keychain.ui.widget.PasswordEditText;
-import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView;
+import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
import org.sufficientlysecure.keychain.util.ContactHelper;
public class CreateKeyInputFragment extends Fragment {
+ public static final String ARG_NAME = "name";
+ public static final String ARG_EMAIL = "email";
CreateKeyActivity mCreateKeyActivity;
-
- PasswordStrengthView mPassphraseStrengthView;
AutoCompleteTextView mNameEdit;
EmailEditText mEmailEdit;
- PasswordEditText mPassphraseEdit;
+ PassphraseEditText mPassphraseEdit;
EditText mPassphraseEditAgain;
View mCreateButton;
- public static final String ARG_NAME = "name";
- public static final String ARG_EMAIL = "email";
-
/**
* Creates new instance of this fragment
*/
@@ -64,15 +60,47 @@ public class CreateKeyInputFragment extends Fragment {
return frag;
}
+ /**
+ * Checks if text of given EditText is not empty. If it is empty an error is
+ * set and the EditText gets the focus.
+ *
+ * @param context
+ * @param editText
+ * @return true if EditText is not empty
+ */
+ private static boolean isEditTextNotEmpty(Context context, EditText editText) {
+ boolean output = true;
+ if (editText.getText().toString().length() == 0) {
+ editText.setError(context.getString(R.string.create_key_empty));
+ editText.requestFocus();
+ output = false;
+ } else {
+ editText.setError(null);
+ }
+
+ return output;
+ }
+
+ private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) {
+ boolean output = true;
+ if (!editText1.getText().toString().equals(editText2.getText().toString())) {
+ editText2.setError(context.getString(R.string.create_key_passphrases_not_equal));
+ editText2.requestFocus();
+ output = false;
+ } else {
+ editText2.setError(null);
+ }
+
+ return output;
+ }
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.create_key_input_fragment, container, false);
- mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id
- .create_key_passphrase_strength);
mNameEdit = (AutoCompleteTextView) view.findViewById(R.id.create_key_name);
+ mPassphraseEdit = (PassphraseEditText) view.findViewById(R.id.create_key_passphrase);
mEmailEdit = (EmailEditText) view.findViewById(R.id.create_key_email);
- mPassphraseEdit = (PasswordEditText) view.findViewById(R.id.create_key_passphrase);
mPassphraseEditAgain = (EditText) view.findViewById(R.id.create_key_passphrase_again);
mCreateButton = view.findViewById(R.id.create_key_button);
@@ -106,15 +134,6 @@ public class CreateKeyInputFragment extends Fragment {
)
);
- // Edit text padding doesn't work via xml (http://code.google.com/p/android/issues/detail?id=77982)
- // so we set the right padding programmatically.
- mPassphraseEdit.setPadding(mPassphraseEdit.getPaddingLeft(),
- mPassphraseEdit.getPaddingTop(),
- (int) (56 * getResources().getDisplayMetrics().density),
- mPassphraseEdit.getPaddingBottom());
-
- mPassphraseEdit.setPasswordStrengthView(mPassphraseStrengthView);
-
mCreateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -165,38 +184,4 @@ public class CreateKeyInputFragment extends Fragment {
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
- /**
- * Checks if text of given EditText is not empty. If it is empty an error is
- * set and the EditText gets the focus.
- *
- * @param context
- * @param editText
- * @return true if EditText is not empty
- */
- private static boolean isEditTextNotEmpty(Context context, EditText editText) {
- boolean output = true;
- if (editText.getText().toString().length() == 0) {
- editText.setError(context.getString(R.string.create_key_empty));
- editText.requestFocus();
- output = false;
- } else {
- editText.setError(null);
- }
-
- return output;
- }
-
- private static boolean areEditTextsEqual(Context context, EditText editText1, EditText editText2) {
- boolean output = true;
- if (!editText1.getText().toString().equals(editText2.getText().toString())) {
- editText2.setError(context.getString(R.string.create_key_passphrases_not_equal));
- editText2.requestFocus();
- output = false;
- } else {
- editText2.setError(null);
- }
-
- return output;
- }
-
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java
index 9e1f21f60..b34dc2edc 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/SetPassphraseDialogFragment.java
@@ -43,8 +43,7 @@ import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.ui.widget.PasswordEditText;
-import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView;
+import org.sufficientlysecure.keychain.ui.widget.PassphraseEditText;
import org.sufficientlysecure.keychain.util.Log;
public class SetPassphraseDialogFragment extends DialogFragment implements OnEditorActionListener {
@@ -57,10 +56,9 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
public static final String MESSAGE_NEW_PASSPHRASE = "new_passphrase";
private Messenger mMessenger;
- private PasswordEditText mPassphraseEditText;
+ private PassphraseEditText mPassphraseEditText;
private EditText mPassphraseAgainEditText;
private CheckBox mNoPassphraseCheckBox;
- private PasswordStrengthView mPassphraseStrengthView;
/**
* Creates new instance of this dialog fragment
@@ -100,11 +98,9 @@ public class SetPassphraseDialogFragment extends DialogFragment implements OnEdi
View view = inflater.inflate(R.layout.passphrase_repeat_dialog, null);
alert.setView(view);
- mPassphraseEditText = (PasswordEditText) view.findViewById(R.id.passphrase_passphrase);
+ mPassphraseEditText = (PassphraseEditText) view.findViewById(R.id.passphrase_passphrase);
mPassphraseAgainEditText = (EditText) view.findViewById(R.id.passphrase_passphrase_again);
mNoPassphraseCheckBox = (CheckBox) view.findViewById(R.id.passphrase_no_passphrase);
- mPassphraseStrengthView = (PasswordStrengthView) view.findViewById(R.id.passphrase_repeat_passphrase_strength);
- mPassphraseEditText.setPasswordStrengthView(mPassphraseStrengthView);
if (TextUtils.isEmpty(oldPassphrase)) {
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..11d9e8fd0
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PassphraseEditText.java
@@ -0,0 +1,84 @@
+/*
+ * 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);
+ 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/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,