Java Code Examples for org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressField#COUNTRY

The following examples show how to use org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressField#COUNTRY . 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
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Calculate the label for this profile. The label's format depends on the country and
    // language code for the profile.
    PersonalDataManager pmd = PersonalDataManager.getInstance();
    profile.setLabel(pmd.getGetAddressLabelForPaymentRequest(profile));

    // Save the edited autofill profile.
    pmd.setProfile(profile);
}
 
Example 2
Source File: AddressEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Adds text fields to the editor model based on the country and language code of the profile
 * that's being edited.
 */
private void addAddressTextFieldsToEditor(
        EditorModel container, String countryCode, String languageCode) {
    mAddressUiComponents = mAutofillProfileBridge.getAddressUiComponents(countryCode,
            languageCode);

    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);

        // The country field is a dropdown, so there's no need to add a text field for it.
        if (component.id == AddressField.COUNTRY) continue;

        EditorFieldModel field = mAddressFields.get(component.id);
        // Labels depend on country, e.g., state is called province in some countries. These are
        // already localized.
        field.setLabel(component.label);
        field.setIsFullLine(component.isFullLine);

        // Libaddressinput formats do not always require the full name (RECIPIENT), but
        // PaymentRequest does.
        if (component.isRequired || component.id == AddressField.RECIPIENT) {
            field.setRequiredErrorMessage(mContext.getString(
                    R.string.payments_address_field_required_validation_message));
        } else {
            field.setRequiredErrorMessage(null);
        }

        container.addField(field);
    }
}
 
Example 3
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 4
Source File: AddressEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Calculate the label for this profile. The label's format depends on the country and
    // language code for the profile.
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    // TODO(crbug.com/666048): New billing address label is wrong.
    profile.setLabel(pdm.getAddressLabelForPaymentRequest(profile));

    // Save the edited autofill profile locally.
    profile.setGUID(pdm.setProfileToLocal(profile));
    profile.setIsLocal(true);
}
 
Example 5
Source File: AddressEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Adds text fields to the editor model based on the country and language code of the profile
 * that's being edited.
 */
private void addAddressTextFieldsToEditor(
        EditorModel container, String countryCode, String languageCode) {
    mAddressUiComponents = mAutofillProfileBridge.getAddressUiComponents(countryCode,
            languageCode);

    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);

        // The country field is a dropdown, so there's no need to add a text field for it.
        if (component.id == AddressField.COUNTRY) continue;

        EditorFieldModel field = mAddressFields.get(component.id);
        // Labels depend on country, e.g., state is called province in some countries. These are
        // already localized.
        field.setLabel(component.label);
        field.setIsFullLine(component.isFullLine);

        // Libaddressinput formats do not always require the full name (RECIPIENT), but
        // PaymentRequest does.
        if (component.isRequired || component.id == AddressField.RECIPIENT) {
            field.setRequiredErrorMessage(mContext.getString(
                    R.string.payments_field_required_validation_message));
        } else {
            field.setRequiredErrorMessage(null);
        }

        container.addField(field);
    }
}
 
Example 6
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;
}
 
Example 7
Source File: AddressEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Saves the edited profile on disk. */
private void commitChanges(AutofillProfile profile) {
    // Country code and phone number are always required and are always collected from the
    // editor model.
    profile.setCountryCode(mCountryField.getValue().toString());
    profile.setPhoneNumber(mPhoneField.getValue().toString());

    // Autofill profile bridge normalizes the language code for the autofill profile.
    profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());

    // Collect data from all visible fields and store it in the autofill profile.
    Set<Integer> visibleFields = new HashSet<>();
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);
        visibleFields.add(component.id);
        if (component.id != AddressField.COUNTRY) {
            setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
        }
    }

    // Clear the fields that are hidden from the user interface, so
    // AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        if (!visibleFields.contains(entry.getKey())) {
            setProfileField(profile, entry.getKey(), "");
        }
    }

    // Save the edited autofill profile locally.
    profile.setGUID(PersonalDataManager.getInstance().setProfileToLocal(mProfile));
    profile.setIsLocal(true);
}