Search in sources :

Example 1 with AddressUiComponent

use of org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent in project AndroidChromium by JackyAndroid.

the class AutofillProfileEditor method resetFormFields.

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]);
        }
    }
}
Also used : EditText(android.widget.EditText) AddressUiComponent(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent) CompatibilityTextInputLayout(org.chromium.chrome.browser.widget.CompatibilityTextInputLayout)

Example 2 with AddressUiComponent

use of org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent in project AndroidChromium by JackyAndroid.

the class AddressEditor method commitChanges.

/**
 * 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());
        }
    }
    // 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);
}
Also used : EditorFieldModel(org.chromium.chrome.browser.payments.ui.EditorFieldModel) AddressUiComponent(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with AddressUiComponent

use of org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent in project AndroidChromium by JackyAndroid.

the class AddressEditor method addAddressTextFieldsToEditor.

/**
 * 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);
        // 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);
    }
}
Also used : EditorFieldModel(org.chromium.chrome.browser.payments.ui.EditorFieldModel) AddressUiComponent(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent)

Aggregations

AddressUiComponent (org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressUiComponent)3 EditorFieldModel (org.chromium.chrome.browser.payments.ui.EditorFieldModel)2 EditText (android.widget.EditText)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 PersonalDataManager (org.chromium.chrome.browser.autofill.PersonalDataManager)1 CompatibilityTextInputLayout (org.chromium.chrome.browser.widget.CompatibilityTextInputLayout)1