org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressField Java Examples
The following examples show how to use
org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.AddressField.
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: AutofillProfileEditor.java From delion with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); mInflater = inflater; mAddressFields = new CompatibilityTextInputLayout[AddressField.NUM_FIELDS]; mPhoneText = (EditText) v.findViewById(R.id.phone_number_edit); mPhoneLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.phone_number_label); mEmailText = (EditText) v.findViewById(R.id.email_address_edit); mEmailLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.email_address_label); mWidgetRoot = (ViewGroup) v.findViewById(R.id.autofill_profile_widget_root); mCountriesDropdown = (Spinner) v.findViewById(R.id.countries); mAutofillProfileBridge = new AutofillProfileBridge(); populateCountriesDropdown(); createAndPopulateEditFields(); initializeButtons(v); return v; }
Example #2
Source File: AutofillProfileEditor.java From 365browser with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); mInflater = inflater; mAddressFields = new CompatibilityTextInputLayout[AddressField.NUM_FIELDS]; mPhoneText = (EditText) v.findViewById(R.id.phone_number_edit); mPhoneLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.phone_number_label); mEmailText = (EditText) v.findViewById(R.id.email_address_edit); mEmailLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.email_address_label); mWidgetRoot = (ViewGroup) v.findViewById(R.id.autofill_profile_widget_root); mCountriesDropdown = (Spinner) v.findViewById(R.id.spinner); TextView countriesLabel = (TextView) v.findViewById(R.id.spinner_label); countriesLabel.setText(v.getContext().getString(R.string.autofill_profile_editor_country)); mAutofillProfileBridge = new AutofillProfileBridge(); populateCountriesDropdown(); createAndPopulateEditFields(); initializeButtons(v); return v; }
Example #3
Source File: AutofillProfileEditor.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); mInflater = inflater; mAddressFields = new CompatibilityTextInputLayout[AddressField.NUM_FIELDS]; mPhoneText = (EditText) v.findViewById(R.id.phone_number_edit); mPhoneLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.phone_number_label); mEmailText = (EditText) v.findViewById(R.id.email_address_edit); mEmailLabel = (CompatibilityTextInputLayout) v.findViewById(R.id.email_address_label); mWidgetRoot = (ViewGroup) v.findViewById(R.id.autofill_profile_widget_root); mCountriesDropdown = (Spinner) v.findViewById(R.id.spinner); TextView countriesLabel = (TextView) v.findViewById(R.id.spinner_label); countriesLabel.setText(v.getContext().getString(R.string.autofill_profile_editor_country)); mAutofillProfileBridge = new AutofillProfileBridge(); populateCountriesDropdown(); createAndPopulateEditFields(); initializeButtons(v); return v; }
Example #4
Source File: AddressEditor.java From delion with Apache License 2.0 | 5 votes |
/** * 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 #5
Source File: AutofillProfileEditor.java From 365browser with Apache License 2.0 | 5 votes |
@Override protected boolean saveEntry() { AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID, AutofillAndPaymentsPreferences.SETTINGS_ORIGIN, true /* isLocal */, getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION), getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA), getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY), getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE), mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(), mEmailText.getText().toString(), mLanguageCodeString); PersonalDataManager.getInstance().setProfile(profile); return true; }
Example #6
Source File: AddressEditor.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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: AddressEditor.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onSubKeysReceived(String[] adminAreas) { if (mAdminAreasLoaded) return; mAdminAreasLoaded = true; // If Chrome can't get admin areas from the server or there is no admin area on the server, // then use the text field. // Otherwise, use the dropdown list. if (adminAreas == null || adminAreas.length == 0) { mAddressFields.put(AddressField.ADMIN_AREA, EditorFieldModel.createTextInput()); } else { mAddressFields.put(AddressField.ADMIN_AREA, EditorFieldModel.createDropdown()); } // Admin areas need to be fetched in two cases: // 1. Initial loading of the form. // 2. When the selected country is changed in the form. // mRecentlySelectedCountry is not null if and only if it's the second case if (mRecentlySelectedCountry != null) { dismissProgressDialog(); // 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". addAddressFieldsToEditor( mRecentlySelectedCountry, Locale.getDefault().getLanguage(), adminAreas); // Notify EditorDialog that the fields in the model have changed. EditorDialog should // re-read the model and update the UI accordingly. mHandler.post(mCountryChangeCallback); } else { // This should be called when all required fields are put in mAddressField. setAddressFieldValuesFromCache(); addAddressFieldsToEditor( mProfile.getCountryCode(), mProfile.getLanguageCode(), adminAreas); mEditorDialog.show(mEditor); } }
Example #8
Source File: AddressEditor.java From 365browser with Apache License 2.0 | 5 votes |
/** 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 #9
Source File: AutofillAddress.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 #10
Source File: AutofillProfileEditor.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override protected boolean saveEntry() { AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID, AutofillPreferences.SETTINGS_ORIGIN, true /* isLocal */, getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION), getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA), getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY), getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE), mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(), mEmailText.getText().toString(), mLanguageCodeString); PersonalDataManager.getInstance().setProfile(profile); return true; }
Example #11
Source File: AddressEditor.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * 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 #12
Source File: AddressEditor.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** 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 #13
Source File: AutofillAddress.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * 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 #14
Source File: AutofillProfileEditor.java From delion with Apache License 2.0 | 5 votes |
@Override protected void saveEntry() { AutofillProfile profile = new PersonalDataManager.AutofillProfile(mGUID, AutofillPreferences.SETTINGS_ORIGIN, true /* isLocal */, getFieldText(AddressField.RECIPIENT), getFieldText(AddressField.ORGANIZATION), getFieldText(AddressField.STREET_ADDRESS), getFieldText(AddressField.ADMIN_AREA), getFieldText(AddressField.LOCALITY), getFieldText(AddressField.DEPENDENT_LOCALITY), getFieldText(AddressField.POSTAL_CODE), getFieldText(AddressField.SORTING_CODE), mCountryCodes.get(mCurrentCountryPos), mPhoneText.getText().toString(), mEmailText.getText().toString(), mLanguageCodeString); PersonalDataManager.getInstance().setProfile(profile); }
Example #15
Source File: AddressEditor.java From delion with Apache License 2.0 | 5 votes |
/** 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 #16
Source File: AutofillProfileEditor.java From AndroidChromium with Apache License 2.0 | 4 votes |
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); }
Example #17
Source File: AutofillProfileEditor.java From AndroidChromium with Apache License 2.0 | 4 votes |
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 #18
Source File: AutofillProfileEditor.java From delion with Apache License 2.0 | 4 votes |
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 #19
Source File: AutofillProfileEditor.java From delion with Apache License 2.0 | 4 votes |
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); }
Example #20
Source File: AutofillProfileEditor.java From 365browser with Apache License 2.0 | 4 votes |
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); }
Example #21
Source File: AutofillProfileEditor.java From 365browser with Apache License 2.0 | 4 votes |
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]); } } }