org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddressEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given profile can be sent to the merchant as-is without editing first. If
 * the country code is not set or invalid, but all fields for the default locale's country code
 * are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress() will
 * use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param profile The profile to check.
 * @return Whether the profile is complete.
 */
public boolean isProfileComplete(@Nullable AutofillProfile profile) {
    if (profile == null || TextUtils.isEmpty(profile.getFullName())
            || !getPhoneValidator().isValid(profile.getPhoneNumber())) {
        return false;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int i = 0; i < requiredFields.size(); i++) {
        if (TextUtils.isEmpty(getProfileField(profile, requiredFields.get(i)))) return false;
    }

    return true;
}
 
Example #2
Source File: AutofillAddress.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Checks address completion status in the given profile.
 *
 * If the country code is not set or invalid, but all fields for the default locale's country
 * code are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress()
 * will use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param  profile The autofill profile containing the address information.
 * @return int     The completion status.
 */
@CompletionStatus
public static int checkAddressCompletionStatus(AutofillProfile profile) {
    int invalidFieldsCount = 0;
    int completionStatus = COMPLETE;

    if (!PhoneNumberUtils.isGlobalPhoneNumber(
                PhoneNumberUtils.stripSeparators(profile.getPhoneNumber().toString()))) {
        completionStatus = INVALID_PHONE_NUMBER;
        invalidFieldsCount++;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int fieldId : requiredFields) {
        if (fieldId == AddressField.RECIPIENT || fieldId == AddressField.COUNTRY) continue;
        if (!TextUtils.isEmpty(getProfileField(profile, fieldId))) continue;
        completionStatus = INVALID_ADDRESS;
        invalidFieldsCount++;
        break;
    }

    if (TextUtils.isEmpty(profile.getFullName())) {
        completionStatus = INVALID_RECIPIENT;
        invalidFieldsCount++;
    }

    if (invalidFieldsCount > 1) {
        completionStatus = INVALID_MULTIPLE_FIELDS;
    }

    return completionStatus;
}
 
Example #3
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks address completion status in the given profile.
 *
 * If the country code is not set or invalid, but all fields for the default locale's country
 * code are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress()
 * will use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param  profile The autofill profile containing the address information.
 * @return int     The completion status.
 */
@CompletionStatus
public static int checkAddressCompletionStatus(
        AutofillProfile profile, @CompletenessCheckType int checkType) {
    int invalidFieldsCount = 0;
    int completionStatus = COMPLETE;

    if (checkType != IGNORE_PHONE_COMPLETENESS_CHECK
            && !PhoneNumberUtils.isGlobalPhoneNumber(
                       PhoneNumberUtils.stripSeparators(profile.getPhoneNumber().toString()))) {
        completionStatus = INVALID_PHONE_NUMBER;
        invalidFieldsCount++;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int fieldId : requiredFields) {
        if (fieldId == AddressField.RECIPIENT || fieldId == AddressField.COUNTRY) continue;
        if (!TextUtils.isEmpty(getProfileField(profile, fieldId))) continue;
        completionStatus = INVALID_ADDRESS;
        invalidFieldsCount++;
        break;
    }

    if (TextUtils.isEmpty(profile.getFullName())) {
        completionStatus = INVALID_RECIPIENT;
        invalidFieldsCount++;
    }

    if (invalidFieldsCount > 1) {
        completionStatus = INVALID_MULTIPLE_FIELDS;
    }

    return completionStatus;
}