public void clearAll() {
    creditCardText.setText("");
    expDateText.setText("");
    securityCodeText.setText("");
    zipCodeText.setText("");
    creditCardText.clearFocus();
    expDateText.clearFocus();
    securityCodeText.clearFocus();
    zipCodeText.clearFocus();

    scrollTo(0, 0);
  }
 @Override
 public void setOnFocusChangeListener(OnFocusChangeListener l) {
   creditCardText.setOnFocusChangeListener(l);
   expDateText.setOnFocusChangeListener(l);
   securityCodeText.setOnFocusChangeListener(l);
   zipCodeText.setOnFocusChangeListener(l);
 }
 public CreditCard getCreditCard() {
   return new CreditCard(
       creditCardText.getText().toString(),
       expDateText.getText().toString(),
       securityCodeText.getText().toString(),
       zipCodeText.getText().toString(),
       creditCardText.getType());
 }
  @SuppressWarnings("deprecation")
  public CreditCardEntry(
      Context context,
      boolean includeExp,
      boolean includeSecurity,
      boolean includeZip,
      AttributeSet attrs,
      int style) {
    super(context);

    this.context = context;

    TypedArray typedArray =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.CreditCardForm, 0, 0);
    textColor = typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK);
    typedArray.recycle();

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int width;

    if (android.os.Build.VERSION.SDK_INT < 13) {
      width = display.getWidth(); // deprecated
    } else {
      Point size = new Point();
      display.getSize(size);
      width = size.x;
    }

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER_VERTICAL;
    setLayoutParams(params);
    this.setHorizontalScrollBarEnabled(false);
    this.setOnTouchListener(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      container = new LinearLayout(context);
    } else {
      container = new LinearLayout(context);
    }
    container.setId(R.id.cc_entry_internal);
    container.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    container.setOrientation(LinearLayout.HORIZONTAL);

    creditCardText = new CreditCardText(context, attrs);
    creditCardText.setId(R.id.cc_card);
    creditCardText.setDelegate(this);
    creditCardText.setWidth(width);
    container.addView(creditCardText);
    includedFields.add(creditCardText);
    CreditEntryFieldBase currentField = creditCardText;

    textFourDigits = new TextView(context);
    textFourDigits.setTextSize(20);
    textFourDigits.setTextColor(textColor);
    container.addView(textFourDigits);

    expDateText = new ExpDateText(context, attrs);
    expDateText.setId(R.id.cc_exp);
    if (includeExp) {
      expDateText.setDelegate(this);
      container.addView(expDateText);
      nextFocusField.put(currentField, expDateText);
      prevFocusField.put(expDateText, currentField);
      currentField = expDateText;
      includedFields.add(currentField);
    }

    securityCodeText = new SecurityCodeText(context, attrs);
    securityCodeText.setId(R.id.cc_ccv);
    if (includeSecurity) {
      securityCodeText.setDelegate(this);
      if (!includeZip) {
        securityCodeText.setImeActionLabel("Done", EditorInfo.IME_ACTION_DONE);
      }

      securityCodeText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (EditorInfo.IME_ACTION_DONE == actionId) {
                onSecurityCodeValid();
                return true;
              }
              return false;
            }
          });
      container.addView(securityCodeText);
      nextFocusField.put(currentField, securityCodeText);
      prevFocusField.put(securityCodeText, currentField);
      currentField = securityCodeText;
      includedFields.add(currentField);
    }

    zipCodeText = new ZipCodeText(context, attrs);
    zipCodeText.setId(R.id.cc_zip);
    if (includeZip) {
      zipCodeText.setDelegate(this);
      container.addView(zipCodeText);
      zipCodeText.setImeActionLabel("DONE", EditorInfo.IME_ACTION_DONE);
      zipCodeText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (EditorInfo.IME_ACTION_DONE == actionId) {
                onZipCodeValid();
                return true;
              }
              return false;
            }
          });
      nextFocusField.put(currentField, zipCodeText);
      prevFocusField.put(zipCodeText, currentField);
      currentField = zipCodeText;
      includedFields.add(currentField);
    }

    nextFocusField.put(currentField, null);

    this.addView(container);

    // when the user taps the last 4 digits of the card, they probably want to edit it
    textFourDigits.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            focusOnField(creditCardText);
          }
        });
  }
 public void setZipCodeTextHint(String text) {
   zipCodeText.setHint(text);
 }
 public void setZipCodeTextHelper(String text) {
   zipCodeText.setHelperText(text);
 }