@Override public void onCardNumberComplete() { scrollRight(); if (mCardInputListener != null) { mCardInputListener.onCardComplete(); } } });
@Override public void onExpiryDateComplete() { mCvcNumberEditText.requestFocus(); if (mCardInputListener != null) { mCardInputListener.onExpirationComplete(); } } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { scrollRight(); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_EXPIRY); } } } });
@Test public void onDeleteFromCvcDate_whenEmpty_shiftsFocusToExpiryAndDeletesDigit() { // This test will be invalid if run between 2080 and 2112. Please update the code. assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2080); mCardInputWidget.setCardInputListener(mCardInputListener); mCardNumberEditText.setText(VALID_VISA_WITH_SPACES); verify(mCardInputListener).onCardComplete(); verify(mCardInputListener).onFocusChange(FOCUS_EXPIRY); mExpiryEditText.append("12"); mExpiryEditText.append("79"); verify(mCardInputListener).onExpirationComplete(); verify(mCardInputListener).onFocusChange(FOCUS_CVC); assertTrue(mCvcEditText.hasFocus()); // Clearing already-verified data. reset(mCardInputListener); ViewTestUtils.sendDeleteKeyEvent(mCvcEditText); verify(mCardInputListener).onFocusChange(FOCUS_EXPIRY); assertEquals(R.id.et_cvc_number, mOnGlobalFocusChangeListener.getOldFocusId()); assertEquals(R.id.et_expiry_date, mOnGlobalFocusChangeListener.getNewFocusId()); String expectedResult = "12/7"; assertEquals(expectedResult, mExpiryEditText.getText().toString()); assertEquals(expectedResult.length(), mExpiryEditText.getSelectionStart()); }
@Test public void onCompleteCardNumber_whenValid_shiftsFocusToExpiryDate() { mCardMultilineWidget.setCardInputListener(mFullCardListener); mNoZipCardMultilineWidget.setCardInputListener(mNoZipCardListener); mFullGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); verify(mFullCardListener, times(1)).onCardComplete(); verify(mFullCardListener, times(1)).onFocusChange(FOCUS_EXPIRY); assertTrue(mFullGroup.expiryDateEditText.hasFocus()); mNoZipGroup.cardNumberEditText.setText(VALID_AMEX_WITH_SPACES); verify(mNoZipCardListener, times(1)).onCardComplete(); verify(mNoZipCardListener, times(1)).onFocusChange(FOCUS_EXPIRY); assertTrue(mNoZipGroup.expiryDateEditText.hasFocus()); }
@Test public void onCompleteExpiry_whenValid_shiftsFocusToCvc() { mCardMultilineWidget.setCardInputListener(mFullCardListener); mNoZipCardMultilineWidget.setCardInputListener(mNoZipCardListener); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); verify(mFullCardListener, times(1)).onExpirationComplete(); verify(mFullCardListener, times(1)).onFocusChange(FOCUS_CVC); assertTrue(mFullGroup.cvcEditText.hasFocus()); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); verify(mNoZipCardListener, times(1)).onExpirationComplete(); verify(mNoZipCardListener, times(1)).onFocusChange(FOCUS_CVC); assertTrue(mNoZipGroup.cvcEditText.hasFocus()); }
@Test public void onCompleteCvc_whenValid_shiftsFocusOnlyIfPostalCodeShown() { mCardMultilineWidget.setCardInputListener(mFullCardListener); mNoZipCardMultilineWidget.setCardInputListener(mNoZipCardListener); mFullGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); mFullGroup.cvcEditText.append("123"); verify(mFullCardListener, times(1)).onCvcComplete(); verify(mFullCardListener, times(1)).onFocusChange(FOCUS_POSTAL); assertTrue(mFullGroup.postalCodeEditText.hasFocus()); mNoZipGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); mNoZipGroup.cvcEditText.append("123"); verify(mNoZipCardListener, times(1)).onCvcComplete(); verify(mNoZipCardListener, times(0)).onFocusChange(FOCUS_POSTAL); assertTrue(mNoZipGroup.cvcEditText.hasFocus()); }
@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); } });
@Override public void onTextChanged(String text) { if (isPostalCodeMaximalLength(true, text) && mCardInputListener != null) { mCardInputListener.onPostalCodeComplete(); } mPostalCodeEditText.setShouldShowError(false); } });
@Test public void onCompleteCardNumber_whenValid_shiftsFocusToExpiryDate() { mCardInputWidget.setCardInputListener(mCardInputListener); mCardNumberEditText.setText(VALID_VISA_WITH_SPACES); verify(mCardInputListener, times(1)).onCardComplete(); verify(mCardInputListener, times(1)).onFocusChange(FOCUS_EXPIRY); assertEquals(R.id.et_card_number, mOnGlobalFocusChangeListener.getOldFocusId()); assertEquals(R.id.et_expiry_date, mOnGlobalFocusChangeListener.getNewFocusId()); }
@Override public void onTextChanged(String text) { if (mCardInputListener != null && ViewUtils.isCvcMaximalLength (mCardNumberEditText.getCardBrand(), text)) { mCardInputListener.onCvcComplete(); } updateIconCvc(mCardNumberEditText.getCardBrand(), mCvcNumberEditText.hasFocus(), text); } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { scrollLeft(); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_CARD); } } } });
@Override public void onCardNumberComplete() { mExpiryDateEditText.requestFocus(); if (mCardInputListener != null) { mCardInputListener.onCardComplete(); } } });
@Override public void onExpiryDateComplete() { mCvcEditText.requestFocus(); if (mCardInputListener != null) { mCardInputListener.onExpirationComplete(); } } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { scrollRight(); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_CVC); } } updateIconCvc( mCardNumberEditText.getCardBrand(), hasFocus, mCvcNumberEditText.getText().toString()); } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mExpiryDateEditText.setHintDelayed( R.string.expiry_date_hint, COMMON_HINT_DELAY); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_EXPIRY); } } else { mExpiryDateEditText.setHint(""); } } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mCardNumberEditText.setHintDelayed( R.string.card_number_hint, CARD_NUMBER_HINT_DELAY); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_CARD); } } else { mCardNumberEditText.setHint(""); } } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (!mShouldShowPostalCode) { return; } if (hasFocus) { mPostalCodeEditText.setHintDelayed(R.string.zip_helper, COMMON_HINT_DELAY); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_POSTAL); } } else { mPostalCodeEditText.setHint(""); } } });
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { flipToCvcIconIfNotFinished(); @StringRes int helperText = getCvcHelperText(); mCvcEditText.setHintDelayed(helperText, COMMON_HINT_DELAY); if (mCardInputListener != null) { mCardInputListener.onFocusChange(FOCUS_CVC); } } else { updateBrand(mCardBrand); mCvcEditText.setHint(""); } } });
@Test public void deleteWhenEmpty_fromPostalCode_shiftsToCvc() { mCardMultilineWidget.setCardInputListener(mFullCardListener); mFullGroup.cardNumberEditText.setText(VALID_DINERS_CLUB_WITH_SPACES); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); mFullGroup.cvcEditText.append("123"); reset(mFullCardListener); ViewTestUtils.sendDeleteKeyEvent(mFullGroup.postalCodeEditText); verify(mFullCardListener, times(1)).onFocusChange(FOCUS_CVC); assertEquals("12", mFullGroup.cvcEditText.getText().toString()); }