From fe98d7f0cc98a380dc571103eef93789156b40e3 Mon Sep 17 00:00:00 2001 From: Kevin Schildhorn Date: Sun, 7 Aug 2022 08:55:42 -0400 Subject: [PATCH] Fixing Issues (underscore cursor and out of bounds index) --- README.md | 9 +++++-- .../otpview/sample/MainActivity.kt | 3 +++ app/src/main/res/layout/activity_main.xml | 22 ++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ build.gradle | 4 +-- .../com/kevinschildhorn/otpview/OTPView.kt | 25 ++++++++++++++++--- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index efd014e..3ef59ac 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ implementation 'com.github.KevinSchildhorn:OTPView:0.2.2' | otp_itemWidth | dimension | width of each item | 44dp | | otp_itemHeight | dimension | height of each item | 44dp | | otp_cursorColor | color | color of the cursor | Black | +| otp_underscoreCursor (Experimental) | boolean | if true will show '_' instead of '|' for the cursor | false | +| otp_customCursor | drawable | custom drawable for the cursor, overrides otp_underscoreCursor | null | | otp_allcaps | boolean | all caps(if fails set input type) | false | | otp_marginBetween | dimension | margin between each item horizontally | 8dp | | otp_isPassword | boolean | sets previously entered items as hidden | false | @@ -69,9 +71,12 @@ otp_view.setOnFinishListener { } ``` * `fun setOnCharacterUpdatedListener(func: (Boolean) -> Unit)` - listener callback for when a character was updated. Returns whether or not it was filled. -* `fun setText(str:String)` - Fills in as much of the text into the items as possible, with one character for each item. Overflow characters are discarded -* `fun clearText(showKeyboard: Boolean)` - Clears all the text, also has the option to hide or show the keyboard on the first item +* `fun setText(str:String)` - Fills in as much of the text into the items as possible, with one character for each item. Overflow characters are discarded. +* `fun clearText(showKeyboard: Boolean)` - Clears all the text, also has the option to hide or show the keyboard on the first item. + +* `fun copyText(showKeyboard: Boolean)` - Copies text from OTP View. +* `fun pasteText(showKeyboard: Boolean)` - Pastes text from OTP View, paste menu item should be overridden from Activity. * `fun fitToWidth(width: Int)` - Fits the entire view to the width entered. Made so that you can dynamically resize the view. * `fun isFilled(): Boolean` - Returns whether or not all the fields have been filled. diff --git a/app/src/main/java/com/kevinschildhorn/otpview/sample/MainActivity.kt b/app/src/main/java/com/kevinschildhorn/otpview/sample/MainActivity.kt index 237551f..f956fc5 100644 --- a/app/src/main/java/com/kevinschildhorn/otpview/sample/MainActivity.kt +++ b/app/src/main/java/com/kevinschildhorn/otpview/sample/MainActivity.kt @@ -35,6 +35,9 @@ class MainActivity : AppCompatActivity() { fill_button.setOnClickListener { otp_view.setText("ABCDEF_EXTRA") } + paste_button.setOnClickListener { + otp_view.pasteText() + } continue_button.setOnClickListener { Toast.makeText(this, otp_view.getStringFromFields(), Toast.LENGTH_LONG).show() diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ba98a1d..fc74b38 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -44,6 +44,28 @@ app:layout_constraintTop_toTopOf="parent" /> + + +