From 01a5114ac6c910cf0717854c95bcc7dcbfa88f4a Mon Sep 17 00:00:00 2001 From: Masoud Ashrafzadeh Date: Wed, 26 Feb 2020 15:33:52 +0330 Subject: [PATCH] add number field to use instead of getText --- .../java/com/sma6871/cardentry/CardEntry.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt b/cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt index dc4226f..b1326d5 100644 --- a/cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt +++ b/cardentry/src/main/java/com/sma6871/cardentry/CardEntry.kt @@ -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 @@ -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() } @@ -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) } @@ -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) }