CardForm extends LinearLayout implements OnCardTypeChangedListener, OnFocusChangeListener, OnClickListener,
        OnEditorActionListener, TextWatcher { public void setup(AppCompatActivity activity) { activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); boolean cardHolderNameVisible = mCardholderNameStatus != FIELD_DISABLED; boolean isDarkBackground = ViewUtils.isDarkBackground(activity); mCardholderNameIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_cardholder_name_dark: R.drawable.bt_ic_cardholder_name); mCardNumberIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_card_dark : R.drawable.bt_ic_card); mPostalCodeIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_postal_code_dark : R.drawable.bt_ic_postal_code); mMobileNumberIcon.setImageResource(isDarkBackground? R.drawable.bt_ic_mobile_number_dark : R.drawable.bt_ic_mobile_number); setViewVisibility(mCardholderNameIcon, cardHolderNameVisible); setFieldVisibility(mCardholderName, cardHolderNameVisible); setViewVisibility(mCardNumberIcon, mCardNumberRequired); setFieldVisibility(mCardNumber, mCardNumberRequired); setFieldVisibility(mExpiration, mExpirationRequired); setFieldVisibility(mCvv, mCvvRequired); setViewVisibility(mPostalCodeIcon, mPostalCodeRequired); setFieldVisibility(mPostalCode, mPostalCodeRequired); setViewVisibility(mMobileNumberIcon, mMobileNumberRequired); setFieldVisibility(mCountryCode, mMobileNumberRequired); setFieldVisibility(mMobileNumber, mMobileNumberRequired); setViewVisibility(mMobileNumberExplanation, mMobileNumberRequired); setViewVisibility(mSaveCardCheckBox, mSaveCardCheckBoxVisible); TextInputEditText editText; for (int i = 0; i < mVisibleEditTexts.size(); i++) { editText = mVisibleEditTexts.get(i); if (i == mVisibleEditTexts.size() - 1) { editText.setImeOptions(EditorInfo.IME_ACTION_GO); editText.setImeActionLabel(mActionLabel, EditorInfo.IME_ACTION_GO); editText.setOnEditorActionListener(this); } else { editText.setImeOptions(EditorInfo.IME_ACTION_NEXT); editText.setImeActionLabel(null, EditorInfo.IME_ACTION_NONE); editText.setOnEditorActionListener(null); } } mSaveCardCheckBox.setInitiallyChecked(mSaveCardCheckBoxChecked); setVisibility(VISIBLE); } CardForm(Context context);  CardForm(Context context, AttributeSet attrs);  CardForm(Context context, AttributeSet attrs, int defStyleAttr); @TargetApi(VERSION_CODES.LOLLIPOP)  CardForm(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); CardForm cardRequired(boolean required); CardForm expirationRequired(boolean required); CardForm cvvRequired(boolean required); CardForm cardholderName(@FieldStatus int cardHolderNameStatus); CardForm postalCodeRequired(boolean required); CardForm mobileNumberRequired(boolean required); CardForm actionLabel(String actionLabel); CardForm mobileNumberExplanation(String mobileNumberExplanation); CardForm maskCardNumber(boolean mask); CardForm maskCvv(boolean mask); CardForm saveCardCheckBoxVisible(boolean visible); CardForm saveCardCheckBoxChecked(boolean checked); void setup(AppCompatActivity activity); void setCardholderNameIcon(@DrawableRes int res); void setCardNumberIcon(@DrawableRes int res); void setPostalCodeIcon(@DrawableRes int res); void setMobileNumberIcon(@DrawableRes int res); void setOnCardFormValidListener(OnCardFormValidListener listener); void setOnCardFormSubmitListener(OnCardFormSubmitListener listener); void setOnFormFieldFocusedListener(OnCardFormFieldFocusedListener listener); void setOnCardTypeChangedListener(OnCardTypeChangedListener listener); void setEnabled(boolean enabled); boolean isValid(); void validate(); CardholderNameEditText getCardholderNameEditText(); CardEditText getCardEditText(); ExpirationDateEditText getExpirationDateEditText(); CvvEditText getCvvEditText(); PostalCodeEditText getPostalCodeEditText(); CountryCodeEditText getCountryCodeEditText(); MobileNumberEditText getMobileNumberEditText(); void setCardholderNameError(String errorMessage); void setCardNumberError(String errorMessage); void setExpirationError(String errorMessage); void setCvvError(String errorMessage); void setPostalCodeError(String errorMessage); void setCountryCodeError(String errorMessage); void setMobileNumberError(String errorMessage); void closeSoftKeyboard(); String getCardholderName(); String getCardNumber(); String getExpirationMonth(); String getExpirationYear(); String getCvv(); String getPostalCode(); String getCountryCode(); String getMobileNumber(); boolean isSaveCardCheckBoxChecked(); @Override void onCardTypeChanged(CardType cardType); @Override void onFocusChange(View v, boolean hasFocus); @Override void onClick(View v); @Override void afterTextChanged(Editable s); @Override boolean onEditorAction(TextView v, int actionId, KeyEvent event); @Override void beforeTextChanged(CharSequence s, int start, int count, int after); @Override void onTextChanged(CharSequence s, int start, int before, int count); static final int FIELD_DISABLED; static final int FIELD_OPTIONAL; static final int FIELD_REQUIRED; }
@Test public void setup_setsFlagSecure() { Window window = mock(Window.class); mActivity = spy(mActivity); when(mActivity.getWindow()).thenReturn(window); mCardForm.setup(mActivity); verify(window).setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); }