Search in sources :

Example 1 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillServerProfilePreferences method onCreate.

@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    addPreferencesFromResource(R.xml.autofill_server_profile_preferences);
    getActivity().setTitle(R.string.autofill_edit_profile);
    // We know which card to display based on the GUID stuffed in
    // our extras by AutofillPreferences.
    Bundle extras = getArguments();
    if (extras != null) {
        mGUID = extras.getString(AutofillPreferences.AUTOFILL_GUID);
    }
    assert mGUID != null;
    AutofillProfile profile = PersonalDataManager.getInstance().getProfile(mGUID);
    if (profile == null) {
        getActivity().finish();
        return;
    }
    assert !profile.getIsLocal();
    Preference profileDescription = findPreference(PREF_SERVER_PROFILE_DESCRIPTION);
    profileDescription.setTitle(profile.getFullName());
    profileDescription.setSummary(profile.getStreetAddress());
    findPreference(PREF_SERVER_PROFILE_EDIT_LINK).setOnPreferenceClickListener(this);
}
Also used : Preference(android.preference.Preference) Bundle(android.os.Bundle) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 2 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillPreferences method rebuildProfileList.

// Always clears the list before building/rebuilding.
private void rebuildProfileList() {
    // Add an edit preference for each current Chrome profile.
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_PROFILES);
    profileCategory.removeAll();
    for (AutofillProfile profile : PersonalDataManager.getInstance().getProfilesForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(profile.getFullName());
        pref.setSummary(profile.getLabel());
        if (profile.getIsLocal()) {
            pref.setFragment(AutofillProfileEditor.class.getName());
        } else {
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
            pref.setFragment(AutofillServerProfilePreferences.class.getName());
        }
        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, profile.getGUID());
        profileCategory.addPreference(pref);
    }
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) Bundle(android.os.Bundle) PreferenceGroup(android.preference.PreferenceGroup) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 3 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AutofillProfileEditor method createAndPopulateEditFields.

private void createAndPopulateEditFields() {
    AutofillProfile profile = PersonalDataManager.getInstance().getProfile(mGUID);
    if (profile != null) {
        if (!TextUtils.isEmpty(profile.getPhoneNumber())) {
            mPhoneLabel.getEditText().setText(profile.getPhoneNumber());
        }
        if (!TextUtils.isEmpty(profile.getEmailAddress())) {
            mEmailLabel.getEditText().setText(profile.getEmailAddress());
        }
        mLanguageCodeString = profile.getLanguageCode();
        mUseSavedProfileLanguage = true;
        mCurrentCountryPos = mCountryCodes.indexOf(profile.getCountryCode());
        if (mCurrentCountryPos == -1) {
            // Use the default country code if profile code is invalid.
            mCurrentCountryPos = mCountryCodes.indexOf(AutofillProfileBridge.getDefaultCountryCode());
            if (mCurrentCountryPos == -1) {
                // Use the first item in country spinner if the default country code is
                // invalid.
                mCurrentCountryPos = 0;
            }
        }
        resetFormFields(mCurrentCountryPos, false);
        setFieldText(AddressField.ADMIN_AREA, profile.getRegion());
        setFieldText(AddressField.LOCALITY, profile.getLocality());
        setFieldText(AddressField.DEPENDENT_LOCALITY, profile.getDependentLocality());
        setFieldText(AddressField.SORTING_CODE, profile.getSortingCode());
        setFieldText(AddressField.POSTAL_CODE, profile.getPostalCode());
        setFieldText(AddressField.STREET_ADDRESS, profile.getStreetAddress());
        setFieldText(AddressField.ORGANIZATION, profile.getCompanyName());
        setFieldText(AddressField.RECIPIENT, profile.getFullName());
    } else {
        mCurrentCountryPos = mCountryCodes.indexOf(AutofillProfileBridge.getDefaultCountryCode());
        if (mCurrentCountryPos == -1) {
            // Use the first item in country spinner if the default country code is
            // invalid.
            mCurrentCountryPos = 0;
        }
        resetFormFields(mCurrentCountryPos, true);
    }
    mCountriesDropdown.setSelection(mCurrentCountryPos);
}
Also used : AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Example 4 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class AddressEditor method edit.

/**
 * Builds and shows an editor model with the following fields.
 *
 * [ country dropdown   ] <----- country dropdown is always present.
 * [ an address field   ] \
 * [ an address field   ]  \
 *         ...               <-- field order, presence, required, and labels depend on country.
 * [ an address field   ]  /
 * [ an address field   ] /
 * [ phone number field ] <----- phone is always present and required.
 */
@Override
public void edit(@Nullable AutofillAddress toEdit, final Callback<AutofillAddress> callback) {
    super.edit(toEdit, callback);
    if (mAutofillProfileBridge == null)
        mAutofillProfileBridge = new AutofillProfileBridge();
    // If |toEdit| is null, we're creating a new autofill profile with the country code of the
    // default locale on this device.
    boolean isNewAddress = toEdit == null;
    // Ensure that |address| and |profile| are always not null.
    final AutofillAddress address = isNewAddress ? new AutofillAddress(mContext, new AutofillProfile()) : toEdit;
    final AutofillProfile profile = address.getProfile();
    // The title of the editor depends on whether we're adding a new address or editing an
    // existing address.
    final EditorModel editor = new EditorModel(isNewAddress ? mContext.getString(R.string.autofill_create_profile) : toEdit.getEditTitle());
    // The country dropdown is always present on the editor.
    if (mCountryField == null) {
        mCountryField = EditorFieldModel.createDropdown(mContext.getString(R.string.autofill_profile_editor_country), AutofillProfileBridge.getSupportedCountries(), null);
    }
    // Changing the country will update which fields are in the model. The actual fields are not
    // discarded, so their contents are preserved.
    mCountryField.setDropdownCallback(new Callback<Pair<String, Runnable>>() {

        @Override
        public void onResult(Pair<String, Runnable> eventData) {
            editor.removeAllFields();
            editor.addField(mCountryField);
            addAddressTextFieldsToEditor(editor, eventData.first, Locale.getDefault().getLanguage());
            editor.addField(mPhoneField);
            // Notify EditorView that the fields in the model have changed. EditorView should
            // re-read the model and update the UI accordingly.
            mHandler.post(eventData.second);
        }
    });
    // Country dropdown is cached, so the selected item needs to be updated for the new profile
    // that's being edited. This will not fire the dropdown callback.
    mCountryField.setValue(AutofillAddress.getCountryCode(profile));
    editor.addField(mCountryField);
    // and relabel the fields. The meaning of each field remains the same.
    if (mAddressFields.isEmpty()) {
        // City, dependent locality, and organization don't have any special formatting hints.
        mAddressFields.put(AddressField.LOCALITY, EditorFieldModel.createTextInput());
        mAddressFields.put(AddressField.DEPENDENT_LOCALITY, EditorFieldModel.createTextInput());
        mAddressFields.put(AddressField.ORGANIZATION, EditorFieldModel.createTextInput());
        // State should be formatted in all capitals.
        mAddressFields.put(AddressField.ADMIN_AREA, EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_REGION));
        // Sorting code and postal code (a.k.a. ZIP code) should show both letters and digits on
        // the keyboard, if possible.
        mAddressFields.put(AddressField.SORTING_CODE, EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC));
        mAddressFields.put(AddressField.POSTAL_CODE, EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC));
        // Street line field can contain \n to indicate line breaks.
        mAddressFields.put(AddressField.STREET_ADDRESS, EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_STREET_LINES));
        // Android has special formatting rules for names.
        mAddressFields.put(AddressField.RECIPIENT, EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME));
    }
    // that's being edited.
    for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
        entry.getValue().setValue(AutofillAddress.getProfileField(profile, entry.getKey()));
    }
    // Both country code and language code dictate which fields should be added to the editor.
    // For example, "US" will not add dependent locality to the editor. A "JP" address will
    // start with a person's full name or a with a prefecture name, depending on whether the
    // language code is "ja-Latn" or "ja".
    addAddressTextFieldsToEditor(editor, profile.getCountryCode(), profile.getLanguageCode());
    // Phone number is present and required for all countries.
    if (mPhoneField == null) {
        mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE, mContext.getString(R.string.autofill_profile_editor_phone_number), mPhoneNumbers, getPhoneValidator(), null, mContext.getString(R.string.payments_field_required_validation_message), mContext.getString(R.string.payments_phone_invalid_validation_message), null);
    }
    // Phone number field is cached, so its value needs to be updated for every new profile
    // that's being edited.
    mPhoneField.setValue(profile.getPhoneNumber());
    editor.addField(mPhoneField);
    // If the user clicks [Cancel], send a null address back to the caller.
    editor.setCancelCallback(new Runnable() {

        @Override
        public void run() {
            callback.onResult(null);
        }
    });
    // If the user clicks [Done], save changes on disk, mark the address "complete," and send it
    // back to the caller.
    editor.setDoneCallback(new Runnable() {

        @Override
        public void run() {
            commitChanges(profile);
            address.completeAddress(profile);
            callback.onResult(address);
        }
    });
    mEditorView.show(editor);
}
Also used : EditorModel(org.chromium.chrome.browser.payments.ui.EditorModel) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) EditorFieldModel(org.chromium.chrome.browser.payments.ui.EditorFieldModel) HashMap(java.util.HashMap) Map(java.util.Map) AutofillProfileBridge(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge) Pair(android.util.Pair)

Example 5 with AutofillProfile

use of org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile in project AndroidChromium by JackyAndroid.

the class ContactEditor method edit.

@Override
public void edit(@Nullable AutofillContact toEdit, final Callback<AutofillContact> callback) {
    super.edit(toEdit, callback);
    final AutofillContact contact = toEdit == null ? new AutofillContact(new AutofillProfile(), null, null, null, false) : toEdit;
    final EditorFieldModel nameField = mRequestPayerName ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME, mContext.getString(R.string.payments_name_field_in_contact_details), mPayerNames, null, null, mContext.getString(R.string.payments_field_required_validation_message), null, contact.getPayerName()) : null;
    final EditorFieldModel phoneField = mRequestPayerPhone ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE, mContext.getString(R.string.autofill_profile_editor_phone_number), mPhoneNumbers, getPhoneValidator(), null, mContext.getString(R.string.payments_field_required_validation_message), mContext.getString(R.string.payments_phone_invalid_validation_message), contact.getPayerPhone()) : null;
    final EditorFieldModel emailField = mRequestPayerEmail ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_EMAIL, mContext.getString(R.string.autofill_profile_editor_email_address), mEmailAddresses, getEmailValidator(), null, mContext.getString(R.string.payments_field_required_validation_message), mContext.getString(R.string.payments_email_invalid_validation_message), contact.getPayerEmail()) : null;
    EditorModel editor = new EditorModel(mContext.getString(toEdit == null ? R.string.payments_add_contact_details_label : R.string.payments_edit_contact_details_label));
    if (nameField != null)
        editor.addField(nameField);
    if (phoneField != null)
        editor.addField(phoneField);
    if (emailField != null)
        editor.addField(emailField);
    editor.setCancelCallback(new Runnable() {

        @Override
        public void run() {
            callback.onResult(null);
        }
    });
    editor.setDoneCallback(new Runnable() {

        @Override
        public void run() {
            String name = null;
            String phone = null;
            String email = null;
            AutofillProfile profile = contact.getProfile();
            if (nameField != null) {
                name = nameField.getValue().toString();
                profile.setFullName(name);
            }
            if (phoneField != null) {
                phone = phoneField.getValue().toString();
                profile.setPhoneNumber(phone);
            }
            if (emailField != null) {
                email = emailField.getValue().toString();
                profile.setEmailAddress(email);
            }
            profile.setGUID(PersonalDataManager.getInstance().setProfileToLocal(profile));
            profile.setIsLocal(true);
            contact.completeContact(profile.getGUID(), name, phone, email);
            callback.onResult(contact);
        }
    });
    mEditorView.show(editor);
}
Also used : EditorFieldModel(org.chromium.chrome.browser.payments.ui.EditorFieldModel) EditorModel(org.chromium.chrome.browser.payments.ui.EditorModel) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)

Aggregations

AutofillProfile (org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)10 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 Preference (android.preference.Preference)2 PersonalDataManager (org.chromium.chrome.browser.autofill.PersonalDataManager)2 CreditCard (org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)2 EditorFieldModel (org.chromium.chrome.browser.payments.ui.EditorFieldModel)2 EditorModel (org.chromium.chrome.browser.payments.ui.EditorModel)2 PreferenceGroup (android.preference.PreferenceGroup)1 Pair (android.util.Pair)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 PaymentRequestUI (org.chromium.chrome.browser.payments.ui.PaymentRequestUI)1 SectionInformation (org.chromium.chrome.browser.payments.ui.SectionInformation)1 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)1 AutofillProfileBridge (org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge)1