Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Commit 5beb1e1

Browse files
committed
bug fixed
1 parent e2f7504 commit 5beb1e1

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

VerifyCodeEditText/src/main/java/com/jakode/verifycodeedittext/VerifyCodeEditText.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class VerifyCodeEditText(context: Context, attrs: AttributeSet?, defStyleAttr: I
3434
stringBuilder = StringBuilder(value)
3535
resetCodeShowView()
3636
}
37-
private var textSize = 0f
38-
private var textColor = 0
39-
private var textFontRes = 0
37+
private var mTextSize = 0f
38+
private var mTextColor = 0
39+
private var mTextFontRes = 0
4040

4141
// Icon
4242
private var bottomSelectedIcon: Drawable? = null
@@ -80,11 +80,11 @@ class VerifyCodeEditText(context: Context, attrs: AttributeSet?, defStyleAttr: I
8080
private fun setupField(attrs: AttributeSet?, defStyleAttr: Int) {
8181
val typedArray: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.VerifyCodeEditText, defStyleAttr, 0)
8282
// Text Size
83-
textSize = typedArray.getDimensionPixelSize(R.styleable.VerifyCodeEditText_TextSize, resources.getDimensionPixelSize(R.dimen.text_size)).toFloat()
83+
mTextSize = typedArray.getDimensionPixelSize(R.styleable.VerifyCodeEditText_TextSize, resources.getDimensionPixelSize(R.dimen.text_size)).toFloat()
8484
// Text Color
85-
textColor = typedArray.getColor(R.styleable.VerifyCodeEditText_TextColor, getColorFromRes(R.color.text_color))
85+
mTextColor = typedArray.getColor(R.styleable.VerifyCodeEditText_TextColor, getColorFromRes(R.color.text_color))
8686
// Text Font
87-
textFontRes = typedArray.getResourceId(R.styleable.VerifyCodeEditText_TextFont, Int.MIN_VALUE)
87+
mTextFontRes = typedArray.getResourceId(R.styleable.VerifyCodeEditText_TextFont, Int.MIN_VALUE)
8888
// Bottom UnSelected Icon
8989
bottomUnSelectedIcon = typedArray.getDrawable(R.styleable.VerifyCodeEditText_BottomUnSelectedIcon)
9090
if (bottomUnSelectedIcon == null) {
@@ -113,12 +113,12 @@ class VerifyCodeEditText(context: Context, attrs: AttributeSet?, defStyleAttr: I
113113

114114
private fun getUnderLineIcon(index: Int): TextView {
115115
return TextView(context).apply {
116-
textSize = textSize
116+
textSize = mTextSize
117117
gravity = Gravity.CENTER
118-
if (textFontRes != Int.MIN_VALUE) {
119-
typeface = ResourcesCompat.getFont(context, textFontRes)
118+
if (mTextFontRes != Int.MIN_VALUE) {
119+
typeface = ResourcesCompat.getFont(context, mTextFontRes)
120120
}
121-
setTextColor(textColor)
121+
setTextColor(mTextColor)
122122
val padding: Int = itemCenterSpaceSize / 2
123123
setPadding(padding, 0, padding, 0)
124124
}.also {
@@ -148,16 +148,16 @@ class VerifyCodeEditText(context: Context, attrs: AttributeSet?, defStyleAttr: I
148148
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
149149
if (!::stringBuilder.isInitialized) stringBuilder = StringBuilder()
150150
// KeyCode 67 is Delete button
151-
if (keyCode == 67 && stringBuilder.isNotEmpty()) {
151+
if (keyCode == KeyEvent.KEYCODE_DEL && stringBuilder.isNotEmpty()) {
152152
stringBuilder.deleteCharAt(stringBuilder.length - 1)
153153
resetCodeShowView()
154-
} else if (keyCode in 7..16 && stringBuilder.length < viewList.size) {
155-
// KeyCode 7..16 is 0..9 number button
156-
stringBuilder.append(keyCode - 7)
154+
} else if (event?.number?.toInt() in 48..57 && stringBuilder.length < viewList.size) {
155+
// ascii code 48..57 is 0..9 number
156+
stringBuilder.append(event?.number)
157157
resetCodeShowView()
158158
}
159159
// KeyCOde 66 is Enter button
160-
if (stringBuilder.length >= viewList.size || keyCode == 66) {
160+
if (stringBuilder.length >= viewList.size || keyCode == KeyEvent.KEYCODE_ENTER) {
161161
// Close Keyboard
162162
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
163163
imm.hideSoftInputFromWindow(windowToken, 0)
@@ -234,9 +234,9 @@ class VerifyCodeEditText(context: Context, attrs: AttributeSet?, defStyleAttr: I
234234
fun build(context: Context): VerifyCodeEditText {
235235
return VerifyCodeEditText(context).apply {
236236
textHolder?.apply {
237-
textSize = size
238-
textColor = color
239-
textFontRes = fontRes
237+
mTextSize = size
238+
mTextColor = color
239+
mTextFontRes = fontRes
240240
}
241241
bottomIconHolder?.apply {
242242
bottomSelectedIcon = selectedIcon

0 commit comments

Comments
 (0)