Giter Site home page Giter Site logo

us1415 / android-card-form Goto Github PK

View Code? Open in Web Editor NEW

This project forked from braintree/android-card-form

0.0 1.0 0.0 1.05 MB

A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.

License: MIT License

Java 99.77% Shell 0.23%

android-card-form's Introduction

Card Form

Card Form is a ready made card form layout that can be included in your app making it easy to accept credit and debit cards.

Build Status

Adding It To Your Project

In your build.gradle:

dependencies {
    compile 'com.braintreepayments:card-form:3.0.2'
}

Usage

Card Form is a LinearLayout that you can add to your layout:

<com.braintreepayments.cardform.view.CardForm
    android:id="@+id/card_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

To initialize the view and change which fields are required for the user to enter, use the required field methods and CardForm#setup(Activity activity).

CardForm cardForm = (CardForm) findViewById(R.id.card_form);
cardForm.cardRequired(true)
        .expirationRequired(true)
        .cvvRequired(true)
        .postalCodeRequired(true)
        .mobileNumberRequired(true)
        .mobileNumberExplanation("SMS is required on this number")
        .actionLabel("Purchase")
        .setup(activity);

To access the values in the form, there are getters for each field:

cardForm.getCardNumber();
cardForm.getExpirationMonth();
cardForm.getExpirationYear();
cardForm.getCvv();
cardForm.getPostalCode();
cardForm.getCountryCode();
cardForm.getMobileNumber();

To check if CardForm is valid call CardForm#isValid(). To validate each required field and show the user which fields are incorrect, call CardForm#validate().

To set custom error messages on a field call CardForm#setCardNumberError(String) on the given field.

Additionally CardForm has 4 available listeners:

  • CardForm#setOnCardFormValidListener called when the form changes state from valid to invalid or invalid to valid.
  • CardForm#setOnCardFormSubmitListener called when the form should be submitted.
  • CardForm#setOnFormFieldFocusedListener called when a field in the form is focused.
  • CardForm#setOnCardTypeChangedListener called when the CardType in the form changes.

card.io

The card form is compatible with card.io.

To use card.io, add the dependency in your build.gradle:

dependencies {
    compile 'io.card:android-sdk:[5.3.0,6.0.0)'
}

Check if card.io is available for use:

cardForm.isCardScanningAvailable();

Scan a card:

cardForm.scanCard(activity);

Example

Styling

The card form uses the Android Design Support Library for styling and floating labels. All card form inputs use the colorAccent theme attribute, when present, to set their focused color. For more information on the colorAccent attribute, see Using the Material Theme. Additional styling, such as the error color (textErrorColor) can be set in your theme and will be picked up by the card form.

The included sample app has examples with a light theme and dark theme.

Note: Any Activity using the card form must use a style that is a Theme.AppCompat theme or descendant (defines android.support.v7.appcompat.R.attr.colorPrimary). This is a requirement of the Android Design Support Library. If this is a problem in your usage of the card form, please file an issue and we will look further into workarounds for this.

License

Card Form is open source and available under the MIT license. See the LICENSE file for more info.

android-card-form's People

Contributors

braintreeps avatar lkorth avatar

Watchers

 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.