A customised EditText view serving the purpose of taking numeric One Time Password from a user. With stunning animation, and high customizability.

Overview

PassCodeText

Android Arsenal

A customised EditText view serving the purpose of taking numeric One Time Password from a user. With stunning animation, and high customizability.

Demo with underline Dark theme demo Error animation Hint usage

Packed with features

  • Add custom character limit.
  • Animation supported on wrong input
  • Use your own color scheme.
  • Do not allow user changing cursor position for smooth functioning.
  • Hint is supported!

How to integrate the library in your app?

Step 1: Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.swapnil1104:OtpEditText:{current_lib_ver}'
}

Step 3. Add OtpEditText to your layout file

<com.broooapps.otpedittext2.OtpEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:cursorVisible="false"
    android:digits="0123456789"
    android:inputType="number"
    android:maxLength="6"
    android:padding="8dp"
    android:textSize="30sp"
    app:oev_primary_color="@color/red"
    app:oev_secondary_color="@color/light_gray"
    />

Usage

GetOtpValue() method usage

String otpValue = otpEditText.getOtpValue();
if (otpValue != null) {
    textDisplay.setText("Entered Value: " + otpEditText.getOtpValue());
}

This method when invoked, will either return the OTP value, in case this is invoked before the user inputs the desired length of characters, a shake animation will be triggered implicitly.

How to customize the view.

Trigger Error Animation

To trigger error animation for incorrect input, or any other use case, use.

OtpEditText otpEditText;
....
otpEditText = findViewById(R.id.oev_view);
....
//Invalid input, animation triggered
otpEditText.triggerErrorAnimation();

Setting desired length for the OTP(One time password code)

To set custom length of the OtpEditText, use

android:maxLength="{your length}"

This will automatically generate the right amount of boxes for user to input the code in.

Setting primary custom color

The primary color signifies the boundary of the box that requires input from user. To change that use,

app:oev_primary_color="@color/{your_color}"

Setting secondary custom color

The secondary color signifies the boundary of the boxes that do not require input from user. To change that use,

app:oev_secondary_color="@color/{your_color}"

Using multiple style options.

There are 4 style options that are available within the library for now.

  • rounded box
  • square box
  • underline
  • rounded underline

To use any of these styles, please add app:oev_box_style="@string\{box_style_input}" attribue. I have provided string resources for simpler usage.

    <string name="style_square">square_box</string>
    <string name="style_rounded">rounded_box</string>
    <string name="style_underline">underline</string>
    <string name="style_rounded_underline">rounded_underline</string>

Suppose you want the rounded underline option to be displayed. Then, please add: app:oev_box_style="@string/style_rounded_underline" in the OtpEditText xml code.

Masking input characters with Asterisk.

Functionality to mask the input with any special character has been introduced. To mask the input;

app:oev_mask_input="true" 

xml property must be introduced in the XML layout file.

Masking with any other special character.

To mask input with any character other than * you can do the following;

app:oev_mask_character="ø"

P.S. Please note that, in case of masking with a special character other than *, specify string with length one, otherwise the input string will be truncated to length 1.

OnComplete callback for the View

To implement an OnComplete callback, use setOnCompleteListener setter method and pass on an interface implementation. eg:

editText.setOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(String value) {
            Toast.makeText(MainActivity.this, "Completed " + value, Toast.LENGTH_SHORT).show();
        }
    });

This callback will be triggered when the number of characters is equal to the android:maxLength value.

For optimum usage; Please note.

  • Specify android:textSize according to your needs.
  • Specify android:padding according to your needs, there are no paddings drawn by default.
  • Specify android:layout_height according to the textSize you've provided. The view will try to center the text with a vertical biasing of 0.6f.
Comments
  • Attribute hint is not applied well

    Attribute hint is not applied well

    Describe the bug I've added below text in xml file but the hint text does not appear. android:hint="12345"

    To Reproduce Set hint text in OtpEditText

    Expected behavior The hint text '12345' should be shown.

    bug good first issue 
    opened by ShangOh 3
  • Pls Migrate to Android X

    Pls Migrate to Android X

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    enhancement 
    opened by josephvijayandroiddev 2
  • False triggering of OnCompleteListener

    False triggering of OnCompleteListener

    Describe the bug Redundant triggering of OnCompleteListener. It happens on first number click if OtpEditText is filled with all numbers.

    Preconditions

    1. Setup OtpEditText with: android:clickable="false" android:cursorVisible="false" android:inputType="number" android:maxLength="6" android:textSize="@dimen/font_size_30" android:textStyle="bold" android:digits="0123456789"
    2. Set OnCompleteListener with log message "OnCompleteListener triggered"

    To Reproduce Steps to reproduce the behavior:

    1. Go to screen with OtpEditText
    2. Click on 'OtpEditText'
    3. enter 6 numbers (you can see "OnCompleteListener triggered" log message)
    4. Click on 1 number of OtpEditText

    Actual behavior TWO row of "OnCompleteListener triggered" logging message is displayed

    Expected behavior ONE row of "OnCompleteListener triggered" logging message is displayed

    Smartphone (please complete the following information):

    • Device: [Emulator Nexus 5X]
    • OS: [Android]
    • Version [9.0]

    Thank you for you work!

    opened by sanya5791 2
  • !mHintText.isEmpty() causes a crash

    !mHintText.isEmpty() causes a crash

    Hi, it is a useful widget. but must add android:hint="" to the xml file, or application will crash. java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.isEmpty()' on a null object reference at com.broooapps.otpedittext2.OtpEditText.onDraw(OtpEditText.java:231)

    bug 
    opened by greatflag 1
  • Doesnt' pars integer from resources

    Doesnt' pars integer from resources

    Describe the bug Doesn't parse android:maxLength="@integer/one_time_password_length" but use default value

    Preconditions set integer value in res folder 6

    To Reproduce Steps to reproduce the behavior:

    1. setup OtpEditText with android:maxLength="@integer/one_time_password_length"
    2. Display OtpEditText

    Actual Behavior OtpEditText displays default 4 sections

    Expected behavior OtpEditText displays 6 sections

    Thank you for your work!

    bug good first issue 
    opened by sanya5791 1
Releases(1.0.2-rc)
Owner
Swapnil Tiwari
@Flipkart @BroooApps
Swapnil Tiwari
💳 Bank Card View is a simple and elegant card view with Flip animation.

Visualização de cartão bancário ?? Bank Card View é uma visualização de cartão simples e elegante com animação Flip. Versões Selecione a língua : Engl

Geovani Amaral 9 Aug 26, 2022
DrawBox: a multi-purpose tool to draw anything on canvas, written completely on jetpack compose

DrawBox DrawBox is a multi-purpose tool to draw anything on canvas, written comp

Akshay Sharma 172 Dec 30, 2022
Thirty-one different easing animation interpolators for Android.

EasingInterpolator Thirty-one different easing animation interpolators for Android. It does not use the standard 4 param ease signature. Instead it us

Masayuki Suda 1.1k Dec 28, 2022
Android Animation Easing Functions. Let's make animation more real!

Android Easing Functions This project is originally from my another project, AndroidViewAnimation, which is an animation collection, to help you make

代码家 2.5k Jan 4, 2023
FilePicker is a small and fast file selector library that is constantly evolving with the goal of rapid integration, high customization, and configurability~

Android File Picker ??️ 中文简体 Well, it doesn't have a name like Rocky, Cosmos or Fish. Android File Picker, like its name, is a local file selector fra

null 786 Jan 6, 2023
User onboarding library with smooth animation of objects and background colors

SlidingTutorial Cleveroad introduces Sliding Tutorial Library for Flutter Hey guys, hope you haven’t started developing a tutorial for your Flutter ap

Cleveroad 127 Dec 31, 2022
Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API

What is Postman? Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API Usage P

Cafer Mert Ceyhan 129 Dec 24, 2022
FadingToolbar is an animation library which fades out your footer view in a ScrollView/RecyclerView and fades in a toolbar title

FadingToolbar is an animation library which fades out your footer view in a ScrollView/RecyclerView and fades in a toolbar title (analogue of the LargeTitle animation in iOS)

Hanna 9 Nov 3, 2022
Cute view animation collection.

Android View Animations One day, I saw an iOS library, which is a view shaker, it's very beautiful. I think Android also need one, and should be bette

代码家 12.2k Jan 1, 2023
Customizable bounce animation for any view like in Clash Royale app

Bounceview-Android Customizable bounce animation for any view updation Getting Started In your build.gradle dependencies { implementation 'hari.bo

Hariprasanth S 149 Nov 18, 2022
Deprecated in favour of https://developer.android.com/reference/android/support/v4/view/animation/PathInterpolatorCompat.html

Deprecated: use https://developer.android.com/reference/android/support/v4/view/animation/PathInterpolatorCompat.html instead. android-cubic-bezier-in

Codesoup 161 Jan 1, 2023
Animation View to Highlight particular Views 🎯 for Android

TargetView Animation View to Highlight particular Views ?? for Android, it can be Used with Views that you see important (Like CountDownTimer), And al

Anas Altair 53 Aug 7, 2021
Android Library to create Lottie animation view dialog easily with a lot of customization

LottieDialog Android Library to create Lottie animation view dialog easily with a lot of customization Why you should use Lottie Dialog You have no li

Amr Hesham 39 Oct 7, 2022
Android Library to create Lottie animation view dialog easily with a lot of customization

Android Library to create Lottie animation view dialog easily with a lot of customization

Amr Hesham 39 Oct 7, 2022
Chandrasekar Kuppusamy 799 Nov 14, 2022
A view pager indicator view to deal with a large amount of pages.

Attention I'm not going to support this anymore. Just use a better solution, e.g. this one Indefinite-Pager-Indicator BubblePagerIndicator A view page

Bogdan Kornev 134 Aug 18, 2022
FPSAnimator is very easy animation library for Android TextureView and SurfaceView.

FPSAnimator A simple but powerful Tween / SpriteSheet / ParabolicMotion / animation library for Android TextureView and SurfaceView. Features The cont

Masayuki Suda 756 Dec 30, 2022
ActSwitchAnimTool make the Animation easy to implements, and it compat the version of Android 4.0 or above.

ActSwitchAnimTool As well as we know, Android 5.0 has been support more Animation(just like ViewAnimationUtils~). Maybe some developers can implements

Acropolis 573 Nov 23, 2022
This library provides easy ways to add onboarding or pager screens with different animation and indicators.

WalkThroughAndroid Make amazing OnBoarding Screens easily for your app with different colorful animations, fonts, styles, and many more. Customize you

MindInventory 33 Sep 9, 2022