Giter Site home page Giter Site logo

decoro's Introduction

Maven Central

Decoro

Android library designed for automatic formatting of text input by custom rules.

Installation

Add to the build.gradle of your app module:

dependencies {
    compile 'ru.tinkoff.decoro:decoro:$latestVersion'
}

Usage

String formatting

In examples below the content of the String text will be formatted according to a mask.

Example 1. Using predefined mask
Mask mask = new MaskImpl(PredefinedSlots.RUS_PHONE_NUMBER, true);
mask.insertFront("9995554433");
System.out.println(mask.toString()); // +7 (999) 555-44-33
Using custom mask

Example 2:

Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___");
Mask mask = MaskImpl.createTerminated(slots); // 'terminated' mask
mask.insertFront("9995554433");
System.out.println(mask.toString()); // 999 555

Example 3:

Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___");
Mask mask = MaskImpl.createNonTeminated(slots); // 'non-terminated' mask
mask.insertFront("9995554433");
System.out.println(mask.toString()); // 999 5554433

Formatting "on the fly"

In examples below all the user's text input to EditText will be formatted according to a mask.

Example 4. Using predefined mask
MaskImpl mask = MaskImpl.createTerminated(PredefinedSlots.CARD_NUMBER_USUAL);
FormatWatcher watcher = new MaskFormatWatcher(mask);
watcher.installOn(editText); // install on any TextView

sample static

Masks available out of the box:
PredefinedSlots.SINGLE_SLOT                   // Any character
PredefinedSlots.RUS_PHONE_NUMBER              // Russian phone number formatted as +7 (___) ___-__-__ (digits only)
PredefinedSlots.RUS_PASSPORT                  // Series and number of russian passport formatted as ____ ______  (digits only)
PredefinedSlots.CARD_NUMBER_STANDARD          // Credit card number formatted as ____ ____ ____ ____ (digits only)
PredefinedSlots.CARD_NUMBER_STANDARD_MASKABLE // Credit card number formatted as ____ ____ ____ ____ (digits and chars 'X', 'x', '*')
PredefinedSlots.CARD_NUMBER_MAESTRO           // Credit card number formatted as ________ ____ (digits only)
PredefinedSlots.CARD_NUMBER_MAESTRO_MASKABLE  // Credit card number formatted as ________ ____ (digits and chars 'X', 'x', '*')
Example 5. Using custom mask
Slot[] slots = new UnderscoreDigitSlotsParser().parseSlots("___ ___ ___");
FormatWatcher formatWatcher = new MaskFormatWatcher(MaskImpl.createTerminated(slots));
formatWatcher.installOn(editText); // install on any TextView

sample static

Migration

In version 1.1.0 class FormatWatcherImpl was renamed to DescriptorFormatWatcher. Also this version introduced MaskFormatWatcher that offers more clean API than DescriptorFormatWatcher.

References

More examples and details can be found in our wiki (in Russian yet).

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.