@@ -5,7 +5,9 @@ import android.graphics.Typeface
55import android.graphics.drawable.DrawableContainer.DrawableContainerState
66import android.graphics.drawable.GradientDrawable
77import android.graphics.drawable.StateListDrawable
8+ import android.text.Editable
89import android.text.InputFilter
10+ import android.text.TextWatcher
911import android.text.method.HideReturnsTransformationMethod
1012import android.text.method.PasswordTransformationMethod
1113import 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