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

The following examples show how to use org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent. 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: 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 #4
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 #5
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);
}
 
Example #6
Source File: AddressEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Adds fields to the editor model based on the country and language code of
 * the profile that's being edited.
 */
private void addAddressFieldsToEditor(
        String countryCode, String languageCode, String[] adminAreas) {
    mAddressUiComponents =
            mAutofillProfileBridge.getAddressUiComponents(countryCode, languageCode);
    // In terms of order, country must be the first field.
    mEditor.addField(mCountryField);
    for (int i = 0; i < mAddressUiComponents.size(); i++) {
        AddressUiComponent component = mAddressUiComponents.get(i);

        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 || component.id == AddressField.LOCALITY
                || component.id == AddressField.DEPENDENT_LOCALITY);

        if (component.id == AddressField.ADMIN_AREA && field.isDropdownField()) {
            field.setDropdownKeyValues(
                    mAutofillProfileBridge.getAdminAreaDropdownList(adminAreas));
        }

        // 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);
        }
        mEditor.addField(field);
    }
    // Phone number must be the last field.
    mEditor.addField(mPhoneField);
}
 
Example #7
Source File: AutofillProfileEditor.java    From delion with Apache License 2.0 4 votes vote down vote up
private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) {
    // Save field text so we can restore it after updating the fields for the current country,
    // and reset mAddressFields.
    String[] fieldText = new String[mAddressFields.length];
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null) {
            fieldText[i] = mAddressFields[i].getEditText().getText().toString();
            mAddressFields[i] = null;
        }
    }

    // Remove all address form fields.
    mWidgetRoot.removeAllViews();

    // Get address fields for the selected country.
    List<AddressUiComponent> fields = mAutofillProfileBridge.getAddressUiComponents(
            mCountryCodes.get(countryCodeIndex),
            mLanguageCodeString);
    if (!mUseSavedProfileLanguage) {
        mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode();
    }

    // Create form fields and focus the first field if autoFocusFirstField is true.
    boolean firstField = true;
    for (AddressUiComponent field : fields) {
        CompatibilityTextInputLayout fieldFloatLabel =
                (CompatibilityTextInputLayout) mInflater.inflate(
                        R.layout.preference_address_float_label_layout, mWidgetRoot, false);
        fieldFloatLabel.setHint(field.label);

        EditText fieldEditText = fieldFloatLabel.getEditText();
        fieldEditText.setContentDescription(field.label);
        fieldEditText.addTextChangedListener(this);
        if (field.id == AddressField.STREET_ADDRESS) {
            fieldEditText.setSingleLine(false);
        }

        mAddressFields[field.id] = fieldFloatLabel;
        mWidgetRoot.addView(fieldFloatLabel);

        if (firstField && autoFocusFirstField) {
            fieldEditText.requestFocus();
            firstField = false;
        }
    }

    // Add back saved field text.
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null && fieldText[i] != null
                && !TextUtils.isEmpty(fieldText[i])) {
            mAddressFields[i].getEditText().setText(fieldText[i]);
        }
    }
}
 
Example #8
Source File: AutofillProfileEditor.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) {
    // Save field text so we can restore it after updating the fields for the current country,
    // and reset mAddressFields.
    String[] fieldText = new String[mAddressFields.length];
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null) {
            fieldText[i] = mAddressFields[i].getEditText().getText().toString();
            mAddressFields[i] = null;
        }
    }

    // Remove all address form fields.
    mWidgetRoot.removeAllViews();

    // Get address fields for the selected country.
    List<AddressUiComponent> fields = mAutofillProfileBridge.getAddressUiComponents(
            mCountryCodes.get(countryCodeIndex),
            mLanguageCodeString);
    if (!mUseSavedProfileLanguage) {
        mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode();
    }

    // Create form fields and focus the first field if autoFocusFirstField is true.
    boolean firstField = true;
    for (AddressUiComponent field : fields) {
        CompatibilityTextInputLayout fieldFloatLabel =
                (CompatibilityTextInputLayout) mInflater.inflate(
                        R.layout.preference_address_float_label_layout, mWidgetRoot, false);
        fieldFloatLabel.setHint(field.label);

        EditText fieldEditText = fieldFloatLabel.getEditText();
        fieldEditText.addTextChangedListener(this);
        if (field.id == AddressField.STREET_ADDRESS) {
            fieldEditText.setSingleLine(false);
        }

        mAddressFields[field.id] = fieldFloatLabel;
        mWidgetRoot.addView(fieldFloatLabel);

        if (firstField && autoFocusFirstField) {
            fieldEditText.requestFocus();
            firstField = false;
        }
    }

    // Add back saved field text.
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null && fieldText[i] != null
                && !TextUtils.isEmpty(fieldText[i])) {
            mAddressFields[i].getEditText().setText(fieldText[i]);
        }
    }
}
 
Example #9
Source File: AutofillProfileEditor.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void resetFormFields(int countryCodeIndex, boolean autoFocusFirstField) {
    // Save field text so we can restore it after updating the fields for the current country,
    // and reset mAddressFields.
    String[] fieldText = new String[mAddressFields.length];
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null) {
            fieldText[i] = mAddressFields[i].getEditText().getText().toString();
            mAddressFields[i] = null;
        }
    }

    // Remove all address form fields.
    mWidgetRoot.removeAllViews();

    // Get address fields for the selected country.
    List<AddressUiComponent> fields = mAutofillProfileBridge.getAddressUiComponents(
            mCountryCodes.get(countryCodeIndex),
            mLanguageCodeString);
    if (!mUseSavedProfileLanguage) {
        mLanguageCodeString = mAutofillProfileBridge.getCurrentBestLanguageCode();
    }

    // Create form fields and focus the first field if autoFocusFirstField is true.
    boolean firstField = true;
    for (AddressUiComponent field : fields) {
        CompatibilityTextInputLayout fieldFloatLabel =
                (CompatibilityTextInputLayout) mInflater.inflate(
                        R.layout.preference_address_float_label_layout, mWidgetRoot, false);
        fieldFloatLabel.setHint(field.label);

        EditText fieldEditText = fieldFloatLabel.getEditText();
        fieldEditText.addTextChangedListener(this);
        if (field.id == AddressField.STREET_ADDRESS) {
            fieldEditText.setSingleLine(false);
        }

        mAddressFields[field.id] = fieldFloatLabel;
        mWidgetRoot.addView(fieldFloatLabel);

        if (firstField && autoFocusFirstField) {
            fieldEditText.requestFocus();
            firstField = false;
        }
    }

    // Add back saved field text.
    for (int i = 0; i < mAddressFields.length; i++) {
        if (mAddressFields[i] != null && fieldText[i] != null
                && !TextUtils.isEmpty(fieldText[i])) {
            mAddressFields[i].getEditText().setText(fieldText[i]);
        }
    }
}