CompactCreditInput
A compact credit card input field that combines the number date and cvv into a single field
Features
- Automatic card number formatting
- Realtime date validation
- Card type logo based on typed number
- Lifecycle automatic disposal support
- Keyboard events handling
- Auto-fill compatible
- Copy & Paste support
Installation
Add JitPack to your repositories
repositories {
maven { url "https://jitpack.io" }
}
And then add the dependency to your dependencies
dependencies {
implementation "com.github.10bis:compactCreditInput:$latest_version"
}
Usage
Add the view to your layout file
<com.tenbis.library.views.CompactCreditCardInput
android:id="@+id/compact_credit_card_input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You can further customize the field in your layout file by changing
card_backgroundcard_number_background_colorcard_date_background_colorcard_cvv_background_colorlabel_textlabel_text_colorlabel_text_fonttext_fonttext_colorhint_colorcard_number_hintcard_date_hintcard_cvv_hint
Or in your code
cardBackgroundcardNumberBackgroundColorcardDateBackgroundColorcardCvvBackgroundColorlabelTextlabelTextColorlabelTextFonttextFonttextColorhintColorcardNumberHintcardDateHintcardCvvHint
Events
The library notifies when a change occur using the OnCreditCardStateChanged interface
Once all fields have valid inputs
onCreditCardValid(creditCard: CreditCard)Once a valid card number is entered
onCreditCardNumberValid(creditCardNumber: String)Once a valid expiration date is entered
onCreditCardExpirationDateValid(month: Int, year: Int)Once a valid cvv is entered
onCreditCardCvvValid(cvv: String)Once the card type is found
onCreditCardTypeFound(cardType: CardType)Once one of the fields is invalid
onInvalidCardTyped()
You can subscribe to events by calling
compactCreditCardInput.addOnCreditCardStateChangedListener(OnCreditCardStateChanged)
You can unsubscribe from events by calling
compactCreditCardInput.removeOnCreditCardStateChangedListener(OnCreditCardStateChanged)
Cleaning up
The library can clean it self automatically when it has an attached Lifecycle
You can attach your lifecycle by calling
compactCreditCardInput.attachLifecycle(Lifecycle)
If you don't want to attach the lifecycle just call
compactCreditCardInput.onDestroy()
When your'e done with the field
Contributing
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Gil Goldzweig Goldbuam - Initial work - Gil Goldzweig Goldbaum
See also the list of contributors who participated in this project.
Changelog
Please read CHANGELOG for details on what changes we're made
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE.md file for details
