@Override public void onTextChanged(String text) { if (isPostalCodeMaximalLength(true, text) && mCardInputListener != null) { mCardInputListener.onPostalCodeComplete(); } mPostalCodeEditText.setShouldShowError(false); } });
postalCodeValid = !mPostalCodeEditText.getText().toString().isEmpty(); mPostalCodeEditText.setShouldShowError(!postalCodeValid); mAddressEditText.setShouldShowError(requiredAddressLine1Empty); mCityEditText.setShouldShowError(requiredCityEmpty); mNameEditText.setShouldShowError(requiredNameEmpty); mStateEditText.setShouldShowError(requiredStateEmpty); mPhoneNumberEditText.setShouldShowError(requiredPhoneNumberEmpty);
@Override public void onTextChanged(String text) { if (ViewUtils.isCvcMaximalLength(mCardBrand, text)) { updateBrand(mCardBrand); if (mShouldShowPostalCode) { mPostalCodeEditText.requestFocus(); } if (mCardInputListener != null) { mCardInputListener.onCvcComplete(); } } else { flipToCvcIconIfNotFinished(); } mCvcEditText.setShouldShowError(false); } });
/** * Clear all entered data and hide all error messages. */ public void clear() { mCardNumberEditText.setText(""); mExpiryDateEditText.setText(""); mCvcEditText.setText(""); mPostalCodeEditText.setText(""); mCardNumberEditText.setShouldShowError(false); mExpiryDateEditText.setShouldShowError(false); mCvcEditText.setShouldShowError(false); mPostalCodeEditText.setShouldShowError(false); updateBrand(Card.UNKNOWN); }
/** * Validates all fields and shows error messages if appropriate. * * @return {@code true} if all shown fields are valid, {@code false} otherwise */ public boolean validateAllFields() { boolean cardNumberIsValid = CardUtils.isValidCardNumber(mCardNumberEditText.getCardNumber()); boolean expiryIsValid = mExpiryDateEditText.getValidDateFields() != null && mExpiryDateEditText.isDateValid(); boolean cvcIsValid = isCvcLengthValid(); mCardNumberEditText.setShouldShowError(!cardNumberIsValid); mExpiryDateEditText.setShouldShowError(!expiryIsValid); mCvcEditText.setShouldShowError(!cvcIsValid); boolean postalCodeIsValidOrGone; if (mShouldShowPostalCode) { postalCodeIsValidOrGone = isPostalCodeMaximalLength(true, mPostalCodeEditText.getText().toString()); mPostalCodeEditText.setShouldShowError(!postalCodeIsValidOrGone); } else { postalCodeIsValidOrGone = true; } return cardNumberIsValid && expiryIsValid && cvcIsValid && postalCodeIsValidOrGone; }
@Test public void setErrorColor_whenInError_overridesDefault() { // By default, the text color in this test activity is a light theme @ColorInt int blueError = 0x0000ff; mEditText.setErrorColor(blueError); mEditText.setShouldShowError(true); int currentColorInt = mEditText.getTextColors().getDefaultColor(); assertEquals(blueError, currentColorInt); } }