Android Open Source - CreditCardEntry Exp Date 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  w  w.  ja  v  a 2s. c o m*/
import android.content.Context;
import android.text.Editable;
import android.util.AttributeSet;
import android.util.Log;

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

public class ExpDateText extends CreditEntryFieldBase {

  String previousString;

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

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

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

  public void init() {
    super.init();
    setHint("MM/YY");
  }

  /* TextWatcher Implementation Methods */
  public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
    previousString = s.toString();
  }

  public void afterTextChanged(Editable s) {
    String updatedString = s.toString();

    // if delete occured do not format
    if (updatedString.length() > previousString.length()) {
      this.removeTextChangedListener(this);
      String formatted = CreditCardUtil
          .formatExpirationDate(s.toString());
      Log.i("CreditCardText", formatted);
      this.setText(formatted);
      this.setSelection(formatted.length());
      this.addTextChangedListener(this);
      
      if(formatted.length() == 5)
      {
        delegate.onExpirationDateValid();
        setValid(true);
      }
      else if(formatted.length() < updatedString.length())
      {
        delegate.onBadInput(this);
        setValid(false);
      }
    }
  }

  @Override
  public String helperText() {
    return context.getString(R.string.ExpirationDateHelp);
  }
}




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