4

I'm using an onPreferenceChangeListener attached to my EditTextPreference that shows the value of the preference in the summary. Here's what it looks like:

public boolean onPreferenceChange(Preference prePreference, Object objValue) {
    if (prePreference instanceof EditTextPreference) {
        //TODO: Check if password type and show chacraters
        prePreference.setSummary(objValue.toString());
    }
    return true;
}

If the field is a masked password field, I'd like to show the default password mask characters in the the summary. Here's an example of a masked field:

    <EditTextPreference
        android:inputType="textPassword"
        android:key="password"
        android:title="@string/password" />
Mridang Agarwalla
  • 40,471
  • 69
  • 211
  • 366
  • Just to be clear, what you want is the method to get the system's mask character(i.e., '.' by default)? – J Jiang Jan 27 '14 at 08:19

3 Answers3

9

Something like:

EditText edit = ((EditTextPreference) prePreference).getEditText();
String pref = edit.getTransformationMethod().getTransformation(objValue.toString(), edit).toString();
prePreference.setSummary(pref);
FunkTheMonk
  • 10,861
  • 1
  • 29
  • 37
1

Easier yet, don't call the generated bindPreferenceSummaryToValue (which in turn calls setSummary) for the password preference.

Note that you shouldn't be storing passwords in the preferences, but instead prompt from a password when you need it, obtain a token from the service, and store the token instead.

lionello
  • 492
  • 8
  • 11
0

Why don't you check the text size and put the characters in the textview for each integer in text size? Or did I misunderstand you?

Or take a look at this link:

Hide password/viewpassword

Community
  • 1
  • 1
Remi
  • 1,261
  • 1
  • 16
  • 50