Fixes #580 - Set an endIconClickListener, and set password/confirm transformation methods accordingly

Begin using `endIconMode` instead of the deprecated `passwordToggleEnabled` for the password field's TextInputLayout
This commit is contained in:
Joshua Soberg 2020-06-06 11:56:51 -04:00
parent 1929e5bdc1
commit 5e40bb3ea3
2 changed files with 30 additions and 5 deletions

View file

@ -371,8 +371,7 @@ public class IntroScreenActivity extends IntroActivity {
passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
setPasswordTransformationMethod();
minLength = Constants.AUTH_MIN_PASSWORD_LENGTH;
lengthWarning = getString(R.string.settings_label_short_password, minLength);
@ -392,8 +391,7 @@ public class IntroScreenActivity extends IntroActivity {
passwordInput.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());
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
setPasswordTransformationMethod();
minLength = Constants.AUTH_MIN_PIN_LENGTH;
lengthWarning = getString(R.string.settings_label_short_pin, minLength);
@ -418,6 +416,33 @@ public class IntroScreenActivity extends IntroActivity {
updateNavigation();
}
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);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}

View file

@ -64,7 +64,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_hint_password"
app:passwordToggleEnabled="true" >
app:endIconMode="password_toggle" >
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/introPasswordEdit"