Open Mygod opened 6 years ago
I'll look into it.
Technically it'd be possible to add a checkbox to the dialog that shows "Show password" (or whatever the dev sets).
Would this work?
Sample (this is 28.0.0.0-rc01, so don't mind the message styling):
Hidden | Visible |
---|---|
I just modified EditTextPreferenceDialogFragmentCompat
's onAddEditTextToDialogView(...)
:
protected void onAddEditTextToDialogView(View dialogView, final EditText editText) {
View oldEditText = dialogView.findViewById(android.R.id.edit);
if (oldEditText != null) {
ViewGroup container = (ViewGroup) (oldEditText.getParent());
if (container != null) {
container.removeView(oldEditText);
container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int inputType = editText.getInputType();
AppCompatCheckBox chkBox = new AppCompatCheckBox(container.getContext());
chkBox.setText("Show password");
chkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final int selStart = editText.getSelectionStart();
final int selEnd = editText.getSelectionEnd();
if (isChecked) {
editText.setInputType(inputType | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
editText.setInputType(inputType);
}
editText.setSelection(selStart, selEnd);
}
});
container.addView(chkBox, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
}
I prefer the solution in #182 or using Google's material design library. This checkbox looks kinda retro.
If you insist on using this solution, I would suggest these changes:
oldEditText
.I don't know what you mean by "This allows for implementing an EditTextPreference as in Android 9.0's Wi-Fi AP configuration." I opened Pie in the emulator and it shows this screen when adding a new network:
Could you send me a screenshot of the screen in question? The emulator's AP has no security settings, so cannot see what it looks like.
Oops. Sorry for being unclear, I was referring to Wi-Fi Hotspot settings.
Wouldn't it just work if the user set the inputType
attribute (or at least as a flag) to textVisiblePassword
? Forcing visible passwords on the users seems a bit odd to me.
Hmm yeah I guess that works too. I didn't know that flag was a thing.
I think, as an extra, the "Show password" checkbox could be placed in the dialog with an attribute, like pref_showPasswordCheckbox="true"
. I only need to find translations for "Show checkbox" in this case.
Or, the other option would be to enable it by setting the text for it, like pref_showPasswordText="@string/show_pass_string"
.
Why not use app:passwordToggleEnabled
?
Hmm okay I don't see an easy way to inflate and use a TextInputLayout
given the current code structure. Ideally I'd like something like this: https://github.com/shadowsocks/shadowsocks-android/pull/1948 (but without that huge layout file, the part that duplicates support lib)
Reopening this...
The problem is that it needs the material components package which is huge. On the other hand, the checkbox solution needs no extra dependencies.
I'm thinking about an option that allows user to pass in edittext layout file, like app:pref_editTextLayout="@layout/material_password_toggle"
. What do you think?
There is an easy way to do this but it requires Google's material design library. What do you think?
UPDATE: There is another way, which is to always show password, like Wi-Fi AP settings in Android Pie.