Skip to content

Instantly share code, notes, and snippets.

@vtthach
Created August 22, 2017 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtthach/e1f789f2a9fc37dcaf107f71904c52b0 to your computer and use it in GitHub Desktop.
Save vtthach/e1f789f2a9fc37dcaf107f71904c52b0 to your computer and use it in GitHub Desktop.
EditText - HiddenPassTransformationMethod
public class LoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// example of usage
((TextView) findViewById(R.id.password)).setTransformationMethod(new HiddenPassTransformationMethod());
}
private class HiddenPassTransformationMethod implements TransformationMethod {
private char DOT = '\u2022';
@Override
public CharSequence getTransformation(final CharSequence charSequence, final View view) {
return new PassCharSequence(charSequence);
}
@Override
public void onFocusChanged(final View view, final CharSequence charSequence, final boolean b, final int i,
final Rect rect) {
//nothing to do here
}
private class PassCharSequence implements CharSequence {
private final CharSequence charSequence;
public PassCharSequence(final CharSequence charSequence) {
this.charSequence = charSequence;
}
@Override
public char charAt(final int index) {
return DOT;
}
@Override
public int length() {
return charSequence.length();
}
@Override
public CharSequence subSequence(final int start, final int end) {
return new PassCharSequence(charSequence.subSequence(start, end));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment