Merge pull request #641 from jsoberg/#638-PasswordConfirmationMethod
#638 - Convert all password views with confirmation field to share toggle state
This commit is contained in:
commit
0ea8ef6a27
9 changed files with 46 additions and 39 deletions
|
@ -54,6 +54,7 @@ import com.heinrichreimersoftware.materialintro.slide.FragmentSlide;
|
||||||
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide;
|
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide;
|
||||||
|
|
||||||
import org.shadowice.flocke.andotp.R;
|
import org.shadowice.flocke.andotp.R;
|
||||||
|
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Constants;
|
import org.shadowice.flocke.andotp.Utilities.Constants;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Settings;
|
import org.shadowice.flocke.andotp.Utilities.Settings;
|
||||||
import org.shadowice.flocke.andotp.Utilities.UIHelper;
|
import org.shadowice.flocke.andotp.Utilities.UIHelper;
|
||||||
|
@ -380,7 +381,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
|
|
||||||
setPasswordTransformationMethod();
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
|
|
||||||
minLength = Constants.AUTH_MIN_PASSWORD_LENGTH;
|
minLength = Constants.AUTH_MIN_PASSWORD_LENGTH;
|
||||||
lengthWarning = getString(R.string.settings_label_short_password, minLength);
|
lengthWarning = getString(R.string.settings_label_short_password, minLength);
|
||||||
|
@ -390,33 +391,6 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
focusOnPasswordInput();
|
focusOnPasswordInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPasswordTransformationMethod() {
|
|
||||||
passwordLayout.setEndIconOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
boolean wasShowingPassword = passwordInput.getTransformationMethod() instanceof PasswordTransformationMethod;
|
|
||||||
// Dispatch password visibility change to both password and confirm inputs
|
|
||||||
dispatchPasswordVisibilityChange(passwordInput, wasShowingPassword);
|
|
||||||
dispatchPasswordVisibilityChange(passwordConfirm, wasShowingPassword);
|
|
||||||
passwordLayout.refreshDrawableState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
passwordInput.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
||||||
passwordConfirm.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dispatchPasswordVisibilityChange(EditText editText, boolean wasShowingPassword) {
|
|
||||||
final int selection = editText.getSelectionEnd();
|
|
||||||
if (wasShowingPassword) {
|
|
||||||
editText.setTransformationMethod(null);
|
|
||||||
} else {
|
|
||||||
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
||||||
}
|
|
||||||
if (selection >= 0) {
|
|
||||||
editText.setSelection(selection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void focusOnPasswordInput() {
|
private void focusOnPasswordInput() {
|
||||||
if (getIntroActivity().getCurrentSlidePosition() == slidePos) {
|
if (getIntroActivity().getCurrentSlidePosition() == slidePos) {
|
||||||
passwordInput.requestFocus();
|
passwordInput.requestFocus();
|
||||||
|
@ -433,7 +407,7 @@ public class IntroScreenActivity extends IntroActivity {
|
||||||
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
|
|
||||||
setPasswordTransformationMethod();
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
|
|
||||||
minLength = Constants.AUTH_MIN_PIN_LENGTH;
|
minLength = Constants.AUTH_MIN_PIN_LENGTH;
|
||||||
lengthWarning = getString(R.string.settings_label_short_pin, minLength);
|
lengthWarning = getString(R.string.settings_label_short_pin, minLength);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import org.shadowice.flocke.andotp.R;
|
import org.shadowice.flocke.andotp.R;
|
||||||
|
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Tools;
|
import org.shadowice.flocke.andotp.Utilities.Tools;
|
||||||
|
|
||||||
public class PasswordEntryDialog extends AppCompatDialog
|
public class PasswordEntryDialog extends AppCompatDialog
|
||||||
|
@ -42,6 +43,7 @@ public class PasswordEntryDialog extends AppCompatDialog
|
||||||
TextInputLayout passwordLayout = findViewById(R.id.passwordInputLayout);
|
TextInputLayout passwordLayout = findViewById(R.id.passwordInputLayout);
|
||||||
passwordInput = findViewById(R.id.passwordInput);
|
passwordInput = findViewById(R.id.passwordInput);
|
||||||
passwordConfirm = findViewById(R.id.passwordConfirm);
|
passwordConfirm = findViewById(R.id.passwordConfirm);
|
||||||
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
|
|
||||||
if (blockAccessibility) {
|
if (blockAccessibility) {
|
||||||
passwordLayout.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
|
passwordLayout.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
|
||||||
|
|
|
@ -46,6 +46,7 @@ import com.google.android.material.textfield.TextInputEditText;
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
import org.shadowice.flocke.andotp.R;
|
import org.shadowice.flocke.andotp.R;
|
||||||
|
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Constants;
|
import org.shadowice.flocke.andotp.Utilities.Constants;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Settings;
|
import org.shadowice.flocke.andotp.Utilities.Settings;
|
||||||
import org.shadowice.flocke.andotp.Utilities.UIHelper;
|
import org.shadowice.flocke.andotp.Utilities.UIHelper;
|
||||||
|
@ -256,8 +257,7 @@ public class CredentialsPreference extends DialogPreference
|
||||||
passwordLayout.setHint(getContext().getString(R.string.settings_hint_password));
|
passwordLayout.setHint(getContext().getString(R.string.settings_hint_password));
|
||||||
passwordConfirm.setHint(R.string.settings_hint_password_confirm);
|
passwordConfirm.setHint(R.string.settings_hint_password_confirm);
|
||||||
|
|
||||||
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
||||||
|
|
||||||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
||||||
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
||||||
|
@ -278,8 +278,7 @@ public class CredentialsPreference extends DialogPreference
|
||||||
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
|
|
||||||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
|
||||||
|
|
||||||
minLength = Constants.AUTH_MIN_PIN_LENGTH;
|
minLength = Constants.AUTH_MIN_PIN_LENGTH;
|
||||||
toShortWarning.setText(getContext().getString(R.string.settings_label_short_pin, minLength));
|
toShortWarning.setText(getContext().getString(R.string.settings_label_short_pin, minLength));
|
||||||
|
|
|
@ -40,6 +40,7 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import org.shadowice.flocke.andotp.R;
|
import org.shadowice.flocke.andotp.R;
|
||||||
|
import org.shadowice.flocke.andotp.Utilities.ConfirmedPasswordTransformationHelper;
|
||||||
import org.shadowice.flocke.andotp.Utilities.Constants;
|
import org.shadowice.flocke.andotp.Utilities.Constants;
|
||||||
import org.shadowice.flocke.andotp.Utilities.EncryptionHelper;
|
import org.shadowice.flocke.andotp.Utilities.EncryptionHelper;
|
||||||
import org.shadowice.flocke.andotp.Utilities.KeyStoreHelper;
|
import org.shadowice.flocke.andotp.Utilities.KeyStoreHelper;
|
||||||
|
@ -135,8 +136,7 @@ public class PasswordEncryptedPreference extends DialogPreference
|
||||||
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
|
||||||
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
|
||||||
|
|
||||||
passwordConfirm.addTextChangedListener(this);
|
passwordConfirm.addTextChangedListener(this);
|
||||||
passwordInput.addTextChangedListener(this);
|
passwordInput.addTextChangedListener(this);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.shadowice.flocke.andotp.Utilities;
|
||||||
|
|
||||||
|
import android.text.method.PasswordTransformationMethod;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
|
public final class ConfirmedPasswordTransformationHelper {
|
||||||
|
|
||||||
|
/** Sets up the specified password views for a toggleable obscure/view password text transformation. */
|
||||||
|
public static void setup(TextInputLayout passwordLayout, TextInputEditText passwordInput, EditText passwordConfirmInput) {
|
||||||
|
passwordLayout.setEndIconOnClickListener(v -> {
|
||||||
|
boolean wasShowingPassword = passwordInput.getTransformationMethod() instanceof PasswordTransformationMethod;
|
||||||
|
// Dispatch password visibility change to both password and confirm inputs
|
||||||
|
dispatchPasswordVisibilityChange(passwordInput, wasShowingPassword);
|
||||||
|
dispatchPasswordVisibilityChange(passwordConfirmInput, wasShowingPassword);
|
||||||
|
passwordLayout.refreshDrawableState();
|
||||||
|
});
|
||||||
|
passwordInput.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||||
|
passwordConfirmInput.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dispatchPasswordVisibilityChange(EditText editText, boolean wasShowingPassword) {
|
||||||
|
final int selection = editText.getSelectionEnd();
|
||||||
|
PasswordTransformationMethod newMethod = wasShowingPassword ? null : PasswordTransformationMethod.getInstance();
|
||||||
|
editText.setTransformationMethod(newMethod);
|
||||||
|
if (selection >= 0) {
|
||||||
|
editText.setSelection(selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/settings_hint_password"
|
android:hint="@string/settings_hint_password"
|
||||||
app:passwordToggleEnabled="true" >
|
app:endIconMode="password_toggle" >
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/passwordEdit"
|
android:id="@+id/passwordEdit"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/settings_hint_password"
|
android:hint="@string/settings_hint_password"
|
||||||
app:passwordToggleEnabled="true" >
|
app:endIconMode="password_toggle" >
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/passwordEdit"
|
android:id="@+id/passwordEdit"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/auth_hint_password"
|
android:hint="@string/auth_hint_password"
|
||||||
app:passwordToggleEnabled="true" >
|
app:endIconMode="password_toggle" >
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/passwordEdit"
|
android:id="@+id/passwordEdit"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/dialog_label_enter_password"
|
android:hint="@string/dialog_label_enter_password"
|
||||||
app:passwordToggleEnabled="true" >
|
app:endIconMode="password_toggle" >
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/passwordInput"
|
android:id="@+id/passwordInput"
|
||||||
|
|
Loading…
Reference in a new issue