decoro

Android library for text formatting

License

License

GroupId

GroupId

ru.tinkoff.decoro
ArtifactId

ArtifactId

decoro
Last Version

Last Version

1.5.0
Release Date

Release Date

Type

Type

aar
Description

Description

decoro
Android library for text formatting
Project URL

Project URL

https://github.com/TinkoffCreditSystems/decoro
Source Code Management

Source Code Management

https://github.com/TinkoffCreditSystems/decoro

Download decoro

How to add to project

<!-- https://jarcasting.com/artifacts/ru.tinkoff.decoro/decoro/ -->
<dependency>
    <groupId>ru.tinkoff.decoro</groupId>
    <artifactId>decoro</artifactId>
    <version>1.5.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/ru.tinkoff.decoro/decoro/
implementation 'ru.tinkoff.decoro:decoro:1.5.0'
// https://jarcasting.com/artifacts/ru.tinkoff.decoro/decoro/
implementation ("ru.tinkoff.decoro:decoro:1.5.0")
'ru.tinkoff.decoro:decoro:aar:1.5.0'
<dependency org="ru.tinkoff.decoro" name="decoro" rev="1.5.0">
  <artifact name="decoro" type="aar" />
</dependency>
@Grapes(
@Grab(group='ru.tinkoff.decoro', module='decoro', version='1.5.0')
)
libraryDependencies += "ru.tinkoff.decoro" % "decoro" % "1.5.0"
[ru.tinkoff.decoro/decoro "1.5.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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).

ru.tinkoff.decoro

Tinkoff.ru

Online financial ecosystem

Versions

Version
1.5.0
1.4.1
1.4.0
1.3.5
1.3.4
1.3.2
1.3.1
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0