Code Monkey home page Code Monkey logo

codeedittext's Introduction

CodeEditText

License Platform API Release

Presentation

This is the source code of an Android library: -=:[ CodeEditText ]:=-

๐Ÿ“ƒ Check also the Medium article about it!

ATTENTION: this project is not maintained anymore, but there's a NEW, BETTER ONE!
Checkout CodeTextField: completely redesigned using Jetpack Compose, with less limitations and way more options!


Why would you need it?

"Input codes easily, numbers or alphabetical, long or short, visible or masked, shown as you like!"

Introducing a fancy and highly customizable EditText, redesigned for codes input.

What you got:

  • chose the max length
  • use it with any inputType
  • you can mask your input AND choose the character you want to mask it
  • customize the layout as you like
  • horizontal scroll with auto-focus while typing
  • and much more!

Demo 1 Demo 2

Demo 3 Demo 4


How to use it?

Step 1. add the JitPack repository to your ROOT build.gradle at the end of repositories:

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

Step 2. add the dependency:

    implementation 'com.github.lukelorusso:CodeEditText:1.1.1'

That's it!

Now you can add the view to your layout:

<com.lukelorusso.codeedittext.CodeEditText
        android:id="@+id/cetMyCode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

maybe add some attributes... here you got some, we'll discuss them later

        ...
        android:inputType="text"
        android:maxLength="6"
        android:text="09af"
        app:cet_codeMaskChar="#"
        app:cet_codePlaceholder="โ€ข"
        app:cet_maskTheCode="true"
        app:cet_scrollDurationInMillis="300"
        ...

All of them can be also set programmatically.

For Java projects

Someone experienced this InflateException. For those guys, it's worth noticing that this is a KOTLIN library! The reason why you're getting an InvocationTargetException is because, in case you're still on Java, you also have to specify:

implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.+'
// or one of the -jre7, -jre8 stdlib depending on your config
// put the most up-to-date version

on your app module's build.gradle.

Another solution is just to... migrate to Kotlin guys!


Customization

Attributes

To set your code programmatically:

cetMyCode.text = "1234"

...and the same thing for the maxLength:

cetMyCode.maxLength = 6

If the input layout is too big for the screen, it will become scrollable and will automatically focus on the portion of the code where the user is typing.

To change the duration of the scrolling effect (in milliseconds):

cetMyCode.scrollDurationInMillis = 300

The default inputType for the EditText is "number". Do you need another one?

cetMyCode.inputType = InputType.TYPE_CLASS_TEXT // choosing a password type will not mask the input

To mask the input (the "password" scenario) just set this boolean:

cetMyCode.maskTheCode = true

If you don't like dots:

cetMyCode.codeMaskChar = '#' // or whatever other Char you like :)

You can also specify a placeholder for the empty char:

cetMyCode.codePlaceholder = 'โ€ข' // or whatever other Char you like :)

Callbacks

For your convenience, here's how you intercept the code:

cetMyCode.setOnCodeChangedListener { (code, completed) ->
    // the code has changed
    if (completed) {
        // the code has been fully entered (code.length == maxLength)
    }
}

Design

As an example, you can find a custom item_code_edit_text.xml inside the res/layout folder of codeedittext-example project.

This is the layout of a single character and it's ENTIRELY CUSTOMIZABLE! You can modify it as you wish; just remember to keep the TextView's id unchanged ๐Ÿ˜‰

Just copy it to your res/layout folder and start to change dimensions, text's size, colors or even add more stuff... it's all up to you!


Explore!

Feel free to checkout and launch the example app ๐ŸŽก

Also, see where using this library has been the perfect choice:

Swissquote Trading
Swissquote Trading

Knave
Knave


Copyright

Make with ๐Ÿ’š by Luca Lorusso, licensed under Apache License 2.0
Thanks for the help to Lopez Mikhael

codeedittext's People

Contributors

lukelorusso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.