Android Open Source - CreditCardEntry Security Code Text






From Project

Back to project page CreditCardEntry.

License

The source code is released under:

MIT License

If you think the Android project CreditCardEntry listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.devmarvel.creditcardentry.fields;
/*from  w ww .  j a va  2 s.  c  om*/
import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.util.AttributeSet;

import com.devmarvel.creditcardentry.R;
import com.devmarvel.creditcardentry.internal.CreditCardUtil;
import com.devmarvel.creditcardentry.internal.CreditCardUtil.CardType;

public class SecurityCodeText extends CreditEntryFieldBase {

  private CardType type;
  
  private int length;

  public SecurityCodeText(Context context) {
    super(context);
    init();
  }

  public SecurityCodeText(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  public SecurityCodeText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
  }

  public void init() {
    super.init();
    setHint("CVV");
  }

  /* TextWatcher Implementation Methods */
  public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
  }

  public void afterTextChanged(Editable s) {

    if (type != null) {
      String number = s.toString();

      if (number.length() == length) {
        delegate.onSecurityCodeValid();
        setValid(true);
      }
      else
      {
        setValid(false);
      }
    } else {
      this.removeTextChangedListener(this);
      this.setText("");
      this.addTextChangedListener(this);
    }

  }

  public CardType getType() {
    return type;
  }

  public void setType(CardType type) {
    this.type = type;
    this.length = CreditCardUtil.securityCodeValid(type);
    
    setFilters(new InputFilter[] { new InputFilter.LengthFilter(length) });
  }
  
  @Override
  public String helperText() {
    return context.getString(R.string.SecurityCodeHelp);
  }
}




Java Source Code List

com.devmarvel.creditcardentry.fields.CreditCardText.java
com.devmarvel.creditcardentry.fields.CreditEntryFieldBase.java
com.devmarvel.creditcardentry.fields.ExpDateText.java
com.devmarvel.creditcardentry.fields.SecurityCodeText.java
com.devmarvel.creditcardentry.fields.ZipCodeText.java
com.devmarvel.creditcardentry.internal.CreditCardEntry.java
com.devmarvel.creditcardentry.internal.CreditCardUtil.java
com.devmarvel.creditcardentry.internal.FlipAnimator.java
com.devmarvel.creditcardentry.library.CreditCardForm.java
com.devmarvel.creditcardentry.library.CreditCard.java
com.devmarvel.creditcardentrydemo.MainActivity.java