Skip to content

Commit

Permalink
add number field to use instead of getText
Browse files Browse the repository at this point in the history
  • Loading branch information
Masoud Ashrafzadeh committed Feb 26, 2020
1 parent f5dfbf0 commit 01a5114
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.appcompat.widget.AppCompatEditText
import androidx.core.content.ContextCompat
import java.util.*


@Suppress("DEPRECATION_ERROR")
class CardEntry : AppCompatEditText {

var maxLength = 16 // default length
Expand Down Expand Up @@ -73,7 +73,7 @@ class CardEntry : AppCompatEditText {
get() = text?.replace(Regex(" "), "") ?: ""
val spaces: String
get() = " ".repeat(spaceCount)
val chunkedText: String
private val chunkedText: String
get() {
return rawText.getChunked()
}
Expand Down Expand Up @@ -124,6 +124,22 @@ class CardEntry : AppCompatEditText {
})
}

@Deprecated("Use numbers instead", replaceWith = ReplaceWith("numbers"), level = DeprecationLevel.ERROR)
override fun getText(): Editable? {
return super.getText()

}

/**
* Returns only numbers of the string which user has been inputted
*
* **Note: strongly recommended to use this method instead of [getText]**
**/
val numbers: String
get() {
return rawText
}

constructor(context: Context) : super(context) {
init(context, null)
}
Expand Down Expand Up @@ -265,8 +281,8 @@ class CardEntry : AppCompatEditText {
override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean {
if (beforeLength == 1 && afterLength == 0) {
// backspace
return (sendKeyEvent( KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
and sendKeyEvent( KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)))
return (sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
and sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)))
}
return super.deleteSurroundingText(beforeLength, afterLength)
}
Expand Down

0 comments on commit 01a5114

Please sign in to comment.