added PassphraseEditText

This commit is contained in:
Adithya Abraham Philip 2015-03-06 21:05:54 +05:30
parent 443feef27a
commit c5093433f5
3 changed files with 92 additions and 31 deletions

View File

@ -20,6 +20,8 @@ package org.sufficientlysecure.keychain.ui;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -32,6 +34,7 @@ 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.PassphraseEditText;
import org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthView;
import org.sufficientlysecure.keychain.util.ContactHelper;
@ -39,10 +42,9 @@ public class CreateKeyInputFragment extends Fragment {
CreateKeyActivity mCreateKeyActivity;
PasswordStrengthView mPassphraseStrengthView;
AutoCompleteTextView mNameEdit;
EmailEditText mEmailEdit;
PasswordEditText mPassphraseEdit;
PassphraseEditText mPassphraseEdit;
EditText mPassphraseEditAgain;
View mCreateButton;
@ -68,11 +70,9 @@ public class CreateKeyInputFragment extends Fragment {
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 +106,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) {

View File

@ -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;
/**
* Created by abraham on 6/3/15.
*/
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);
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);
}
}

View File

@ -58,34 +58,20 @@
android:layout_height="wrap_content"
android:text="@string/label_passphrase" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<org.sufficientlysecure.keychain.ui.widget.PasswordEditText
<org.sufficientlysecure.keychain.ui.widget.PassphraseEditText
android:id="@+id/create_key_passphrase"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:hint="@string/label_passphrase"
android:ems="10"
android:layout_gravity="center_horizontal" />
<org.sufficientlysecure.keychain.ui.widget.passwordstrengthindicator.PasswordStrengthBarView
android:id="@+id/create_key_passphrase_strength"
android:layout_width="48dp"
android:layout_height="8dp"
android:layout_gravity="end|center_vertical"
custom:strength="medium"
android:layout_gravity="center_horizontal"
custom:showGuides="false"
custom:color_fail="@color/android_red_light"
custom:color_weak="@color/android_orange_light"
custom:color_strong="@color/android_green_light" />
</FrameLayout>
<EditText
android:id="@+id/create_key_passphrase_again"
android:layout_width="match_parent"