Search in sources :

Example 6 with FormatResult

use of com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult in project connect-sdk-client-android by Ingenico-ePayments.

the class MaskTest method testMaskingTwoCharactersInclCursor.

@Test
public void testMaskingTwoCharactersInclCursor() {
    StringFormatter formatter = new StringFormatter();
    FormatResult maskedValue = formatter.applyMask(maskExpiryDate, maskTestString2, emptyString, 1);
    assertEquals("12-", maskedValue.getFormattedResult());
    assertTrue(maskedValue.getCursorIndex() == 3);
}
Also used : StringFormatter(com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter) FormatResult(com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult) Test(org.junit.Test)

Example 7 with FormatResult

use of com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult in project connect-sdk-client-android by Ingenico-ePayments.

the class MaskTest method testApplyMaskWithTextWatcherBeforeTextChangedInformationCreditCardNumberREMOVED.

@Test
public void testApplyMaskWithTextWatcherBeforeTextChangedInformationCreditCardNumberREMOVED() {
    StringFormatter formatter = new StringFormatter();
    FormatResult maskResult;
    // *** Test removing the entire entered String ***
    // Test removing a single character
    maskResult = formatter.applyMask(maskCardNumber, "", "1", 0, 1, 0);
    validateFormatResult(maskResult, "", 0);
    // Test removing two characters
    maskResult = formatter.applyMask(maskCardNumber, "", "12", 0, 2, 0);
    validateFormatResult(maskResult, "", 0);
    // Test removing six characters
    maskResult = formatter.applyMask(maskCardNumber, "", "1234 56", 0, 7, 0);
    validateFormatResult(maskResult, "", 0);
    // *** Test removing the first character of a String ***
    // Test removing only the first character
    maskResult = formatter.applyMask(maskCardNumber, "23", "123", 0, 1, 0);
    validateFormatResult(maskResult, "23", 0);
    // Test removing only the first character in a String containing a mask character
    maskResult = formatter.applyMask(maskCardNumber, "234 56", "1234 56", 0, 1, 0);
    validateFormatResult(maskResult, "2345 6", 0);
    // Test removing only the first character in a String containing multiple mask characters
    maskResult = formatter.applyMask(maskCardNumber, "234 5678 9012 3456 789", "1234 5678 9012 3456 789", 0, 1, 0);
    validateFormatResult(maskResult, "2345 6789 0123 4567 89", 0);
    // Test removing the first two characters
    maskResult = formatter.applyMask(maskCardNumber, "3", "123", 0, 2, 0);
    validateFormatResult(maskResult, "3", 0);
    // Test removing the first two characters in a String that contains mask characters
    maskResult = formatter.applyMask(maskCardNumber, "34 5678 ", "1234 5678 ", 0, 2, 0);
    validateFormatResult(maskResult, "3456 78", 0);
    // *** Test removing characters from the end of the String ***
    // Test remove single character from the end of a String
    maskResult = formatter.applyMask(maskCardNumber, "12", "123", 2, 1, 0);
    validateFormatResult(maskResult, "12", 2);
    // Test remove two characters from the end of a String
    maskResult = formatter.applyMask(maskCardNumber, "1", "123", 1, 2, 0);
    validateFormatResult(maskResult, "1", 1);
    // Test remove a character from the end of a String "across" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "1234", "1234 ", 4, 1, 0);
    validateFormatResult(maskResult, "1234 ", 4);
    // Test remove multiple characters from the end of a String "across" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "123", "1234 5", 3, 3, 0);
    validateFormatResult(maskResult, "123", 3);
    // Test remove multiple characters from the end of a String, ending "behind" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "1234", "1234 56", 4, 3, 0);
    validateFormatResult(maskResult, "1234 ", 4);
    // Test remove multiple characters from the end of a String, ending "before" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "1234 ", "1234 56", 5, 2, 0);
    validateFormatResult(maskResult, "1234 ", 5);
    // Test remove 19 characters from the end of a String "across" multiple mask characters
    maskResult = formatter.applyMask(maskCardNumber, "123", "1234 5678 9012 3456 78", 3, 19, 0);
    validateFormatResult(maskResult, "123", 3);
    // Test remove 18 characters from the end of a String "across" multiple mask characters, ending "behind" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "1234", "1234 5678 9012 3456 78", 4, 18, 0);
    validateFormatResult(maskResult, "1234 ", 4);
    // Test remove 17 characters from the end of a String "across" multiple mask characters, ending "before" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "1234 ", "1234 5678 9012 3456 78", 5, 17, 0);
    validateFormatResult(maskResult, "1234 ", 5);
    // *** Test remove characters within the string ***
    // Test removing a single character in a String of only 3 characters
    maskResult = formatter.applyMask(maskCardNumber, "13", "123", 1, 1, 0);
    validateFormatResult(maskResult, "13", 1);
    // Test removing a single character in a String of 4 characters
    maskResult = formatter.applyMask(maskCardNumber, "134", "1234 ", 1, 1, 0);
    validateFormatResult(maskResult, "134", 1);
    // Test removing a single character that is before a mask character
    maskResult = formatter.applyMask(maskCardNumber, "123 ", "1234 ", 3, 1, 0);
    validateFormatResult(maskResult, "123", 3);
    // Test removing multiple characters before a mask character
    maskResult = formatter.applyMask(maskCardNumber, "12 ", "1234 ", 2, 2, 0);
    validateFormatResult(maskResult, "12", 2);
    // Test removing multiple characters inside a longer String, "across" a mask character
    maskResult = formatter.applyMask(maskCardNumber, "12378 9", "1234 5678 9", 3, 4, 0);
    validateFormatResult(maskResult, "1237 89", 3);
    // Test removing a single character with the cursor after a mask character
    maskResult = formatter.applyMask(maskCardNumber, "123456", "1234 56", 4, 1, 0);
    validateFormatResult(maskResult, "1234 56", 4);
}
Also used : StringFormatter(com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter) FormatResult(com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult) Test(org.junit.Test)

Example 8 with FormatResult

use of com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult in project connect-sdk-client-android by Ingenico-ePayments.

the class StringFormatter method determineFormatResultREPLACED.

private FormatResult determineFormatResultREPLACED(String mask, String value, String oldValue, int numAddedCharacters, int previousCursorIndex) {
    FormatResult intermediateResult = determineFormatResultREMOVED(mask, value, previousCursorIndex);
    FormatResult finalResult = determineFormatResultADDED(mask, intermediateResult.getFormattedResult(), oldValue, numAddedCharacters, previousCursorIndex);
    return finalResult;
}
Also used : FormatResult(com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult)

Example 9 with FormatResult

use of com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult in project connect-sdk-client-android by Ingenico-ePayments.

the class FieldInputTextWatcher method afterTextChanged.

@Override
public void afterTextChanged(Editable s) {
    // Do nothing if the entered string is the same
    if (!s.toString().equals(previousEnteredValue)) {
        // Set the previousEnteredValue
        previousEnteredValue = s.toString();
        // Format the input if addMask == true
        if (addMask) {
            // Mask the input
            Integer cursorIndex = editText.getSelectionStart();
            FormatResult applyMaskResult = inputDataPersister.getMaskedValue(paymentProductFieldId, s.toString(), oldValue, start, count, after);
            // Render the FormatResult
            if (applyMaskResult != null) {
                // replace text with mask result
                if (!applyMaskResult.getFormattedResult().equals(s.toString())) {
                    editText.removeTextChangedListener(this);
                    editText.setText(applyMaskResult.getFormattedResult());
                    editText.addTextChangedListener(this);
                }
                // Set cursorIndex
                if (applyMaskResult.getCursorIndex() != null) {
                    editText.setSelection(applyMaskResult.getCursorIndex());
                } else {
                    editText.setSelection(cursorIndex);
                }
            }
        }
        // Save state of field
        inputDataPersister.setValue(paymentProductFieldId, editText.getText().toString());
    }
}
Also used : FormatResult(com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult)

Aggregations

FormatResult (com.globalcollect.gateway.sdk.client.android.sdk.model.FormatResult)9 StringFormatter (com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter)6 Test (org.junit.Test)6 InvalidParameterException (java.security.InvalidParameterException)1