Skip to content

Commit 750692f

Browse files
Merge pull request #28 from SimformSolutionsPvtLtd/bugfix/add_text_change_listener
bugfix : #24 addTextChangeListener LGTM.
2 parents e874cd1 + 835bf24 commit 750692f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

customedittextoutlinedborder/src/main/java/com/simform/customcomponent/SSCustomEdittextOutlinedBorder.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import android.graphics.Typeface
55
import android.graphics.drawable.DrawableContainer.DrawableContainerState
66
import android.graphics.drawable.GradientDrawable
77
import android.graphics.drawable.StateListDrawable
8+
import android.text.Editable
89
import android.text.InputFilter
10+
import android.text.TextWatcher
911
import android.text.method.HideReturnsTransformationMethod
1012
import android.text.method.PasswordTransformationMethod
1113
import android.util.AttributeSet
@@ -32,6 +34,7 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
3234
private var borderColor = ContextCompat.getColor(context, R.color.color_warm_grey)
3335
private var borderErrorColor = ContextCompat.getColor(context, R.color.color_error)
3436
private var borderWidth = 1
37+
private var onTextChangeListener: OnTextChangeListener? = null
3538

3639
val getTextValue: String
3740
get() {
@@ -67,6 +70,7 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
6770
setIsErrorEnable(isErrorEnable)
6871
setIsToggleEnable(isToggleEnable)
6972
setPasswordToggleClick()
73+
setTextChangeListeners()
7074
setStyle(inputType, maxLine, minLine, maxLength)
7175
setTitleBackGroundColor(titleBgColor)
7276
setEditTextBackGroundColor(editTextBgColor)
@@ -128,6 +132,32 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
128132
}
129133
}
130134

135+
interface OnTextChangeListener {
136+
fun beforeTextChange(s: CharSequence?, start: Int, count: Int, after: Int)
137+
fun onTextChange(s: CharSequence?, start: Int, count: Int, after: Int)
138+
fun afterTextChange(s: Editable?)
139+
}
140+
141+
fun setOnTextChangeListener(onTextChangeListener: OnTextChangeListener?) {
142+
this.onTextChangeListener = onTextChangeListener
143+
}
144+
145+
private fun setTextChangeListeners() {
146+
editText.addTextChangedListener(object : TextWatcher {
147+
override fun afterTextChanged(s: Editable?) {
148+
onTextChangeListener?.afterTextChange(s)
149+
}
150+
151+
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
152+
onTextChangeListener?.beforeTextChange(s, start, count, after)
153+
}
154+
155+
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
156+
onTextChangeListener?.onTextChange(s, start, before, count)
157+
}
158+
})
159+
}
160+
131161
private fun setTitleColor(@ColorInt colorID: Int) {
132162
lableTitle.setTextColor(colorID)
133163
}

0 commit comments

Comments
 (0)