Last active
April 2, 2020 07:21
-
-
Save fugogugo/ab4df8cc28d7a91834a2794a3b4226e3 to your computer and use it in GitHub Desktop.
kotlin version of EditText custom PaswordTranformationMethod that will make last character visible, taken from this stack overflow https://stackoverflow.com/a/15569637/616280
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add your package here | |
import android.text.method.PasswordTransformationMethod | |
import android.view.View | |
/** | |
* make edittext masked except last character | |
* source : https://stackoverflow.com/a/15569637/616280 | |
*/ | |
object PasswordTransformLastVisible : PasswordTransformationMethod() { | |
override fun getTransformation(source: CharSequence?, view: View?): CharSequence { | |
return PasswordCharSequence(source!!) | |
} | |
class PasswordCharSequence(private val source: CharSequence) : CharSequence { | |
override val length = source.length | |
override fun get(index: Int): Char { | |
return if (index != source.lastIndex) '•' else source[index] | |
} | |
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence { | |
return source.subSequence(startIndex, endIndex) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment