@Test public void updateSelectionIndex_whenAmEx_decreasesIndexWhenDeletingPastTheSpaces() { mCardNumberEditText.mCardBrand = Card.AMERICAN_EXPRESS; assertEquals(4, mCardNumberEditText.updateSelectionIndex(10, 5, 0)); assertEquals(11, mCardNumberEditText.updateSelectionIndex(13, 12, 0)); }
@VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; for (Integer gap : gapSet) { if (editActionStart <= gap && editActionStart + editActionAddition > gap) { gapsJumped++; } if (editActionAddition == 0 && editActionStart == gap + 1) { skipBack = true; } } newPosition = editActionStart + editActionAddition + gapsJumped; if (skipBack && newPosition > 0) { newPosition--; } return newPosition <= newLength ? newPosition : newLength; }
CardNumberEditText extends StripeEditText { @VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; for (Integer gap : gapSet) { if (editActionStart <= gap && editActionStart + editActionAddition > gap) { gapsJumped++; } if (editActionAddition == 0 && editActionStart == gap + 1) { skipBack = true; } } newPosition = editActionStart + editActionAddition + gapsJumped; if (skipBack && newPosition > 0) { newPosition--; } return newPosition <= newLength ? newPosition : newLength; } }
CardNumberEditText extends StripeEditText { @VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; for (Integer gap : gapSet) { if (editActionStart <= gap && editActionStart + editActionAddition > gap) { gapsJumped++; } if (editActionAddition == 0 && editActionStart == gap + 1) { skipBack = true; } } newPosition = editActionStart + editActionAddition + gapsJumped; if (skipBack && newPosition > 0) { newPosition--; } return newPosition <= newLength ? newPosition : newLength; } CardNumberEditText(Context context);  CardNumberEditText(Context context, AttributeSet attrs);  CardNumberEditText(Context context, AttributeSet attrs, int defStyleAttr); }
CardNumberEditText extends StripeEditText { @VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; for (Integer gap : gapSet) { if (editActionStart <= gap && editActionStart + editActionAddition > gap) { gapsJumped++; } if (editActionAddition == 0 && editActionStart == gap + 1) { skipBack = true; } } newPosition = editActionStart + editActionAddition + gapsJumped; if (skipBack && newPosition > 0) { newPosition--; } return newPosition <= newLength ? newPosition : newLength; } CardNumberEditText(Context context);  CardNumberEditText(Context context, AttributeSet attrs);  CardNumberEditText(Context context, AttributeSet attrs, int defStyleAttr); @NonNull @Card.CardBrand String getCardBrand(); @Nullable String getCardNumber(); int getLengthMax(); boolean isCardNumberValid(); }
CardNumberEditText extends StripeEditText { @VisibleForTesting int updateSelectionIndex( int newLength, int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; Set<Integer> gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; for (Integer gap : gapSet) { if (editActionStart <= gap && editActionStart + editActionAddition > gap) { gapsJumped++; } if (editActionAddition == 0 && editActionStart == gap + 1) { skipBack = true; } } newPosition = editActionStart + editActionAddition + gapsJumped; if (skipBack && newPosition > 0) { newPosition--; } return newPosition <= newLength ? newPosition : newLength; } CardNumberEditText(Context context);  CardNumberEditText(Context context, AttributeSet attrs);  CardNumberEditText(Context context, AttributeSet attrs, int defStyleAttr); @NonNull @Card.CardBrand String getCardBrand(); @Nullable String getCardNumber(); int getLengthMax(); boolean isCardNumberValid();  }