alphamu / PinEntryEditText

An EditText that looks like a pin entry field. It is highly customisable and even animated text.
Apache License 2.0
670 stars 137 forks source link

Show / Hide Masked Characters #4

Closed randiw closed 5 years ago

randiw commented 7 years ago

Thank you for the library, this is a great example. And you also provide the detailed how-to in your blog.

I think it would be great if you can provide method to show or hide the masked characters. Currently your library cannot use PasswordTransformationMethod.

alphamu commented 7 years ago

That's right, basically, the library works by overriding the default draw for a widget which is why that doesn't work. The simplest way to unmask and mask characters is to set and unset the mask filed.

alphamu commented 7 years ago

In the latest build of the code mMask is a protected field. If you extended the widget to create a setMask method, you can set the mask to null when you want to unmask the field and call invalidate to update it. I'm not sure when I can get around to implementing a proper way to handle this in the code, I'll get back to you when I do.

randiw commented 7 years ago

so my solution for this is to create a private boolean field called isShowCharacters and then I have two methods: showCharacters and hideCharacters. With the boolean field it will change how the getFullText returns it characters.

private boolean isShowCharacters;

public void showCharacters() {
    isShowCharacters = true;
    invalidate();
}

public void hideCharacters() {
    isShowCharacters = false;
    invalidate();
}

private CharSequence getFullText() {
    if (mMask == null) {
        return getText();
    } else {
        if (isShowCharacters) {
            return getText();
        } else {
            return getMaskChars();
        }
    }
}

i still think using the PasswordTransformationMethod will the best approach, but for now this is sufficient.