Search in sources :

Example 1 with DropdownKeyValue

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

the class CardEditor method buildMonthDropdownKeyValues.

/** Builds the key-value pairs for the month dropdown. */
private static List<DropdownKeyValue> buildMonthDropdownKeyValues(Calendar calendar) {
    List<DropdownKeyValue> result = new ArrayList<>();
    Locale locale = Locale.getDefault();
    SimpleDateFormat keyFormatter = new SimpleDateFormat("M", locale);
    SimpleDateFormat valueFormatter = new SimpleDateFormat("MMMM (MM)", locale);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    for (int month = 0; month < 12; month++) {
        calendar.set(Calendar.MONTH, month);
        Date date = calendar.getTime();
        result.add(new DropdownKeyValue(keyFormatter.format(date), valueFormatter.format(date)));
    }
    return result;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) DropdownKeyValue(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue)

Example 2 with DropdownKeyValue

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

the class AutofillProfileEditor method populateCountriesDropdown.

private void populateCountriesDropdown() {
    List<DropdownKeyValue> countries = AutofillProfileBridge.getSupportedCountries();
    mCountryCodes = new ArrayList<String>();
    for (DropdownKeyValue country : countries) {
        mCountryCodes.add(country.getKey());
    }
    ArrayAdapter<DropdownKeyValue> countriesAdapter = new ArrayAdapter<DropdownKeyValue>(getActivity(), android.R.layout.simple_spinner_item, countries);
    countriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCountriesDropdown.setAdapter(countriesAdapter);
}
Also used : ArrayAdapter(android.widget.ArrayAdapter) DropdownKeyValue(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue)

Example 3 with DropdownKeyValue

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

the class CardEditor method buildYearDropdownKeyValues.

/** Builds the key-value pairs for the year dropdown. */
private static List<DropdownKeyValue> buildYearDropdownKeyValues(Calendar calendar, String alwaysIncludedYear) {
    List<DropdownKeyValue> result = new ArrayList<>();
    int initialYear = calendar.get(Calendar.YEAR);
    boolean foundAlwaysIncludedYear = false;
    for (int year = initialYear; year < initialYear + 10; year++) {
        String yearString = Integer.toString(year);
        if (yearString.equals(alwaysIncludedYear))
            foundAlwaysIncludedYear = true;
        result.add(new DropdownKeyValue(yearString, yearString));
    }
    if (!foundAlwaysIncludedYear && !TextUtils.isEmpty(alwaysIncludedYear)) {
        result.add(0, new DropdownKeyValue(alwaysIncludedYear, alwaysIncludedYear));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DropdownKeyValue(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue)

Example 4 with DropdownKeyValue

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

the class CardEditor method addBillingAddressDropdown.

/**
     * Adds the billing address dropdown to the editor with the following items.
     *
     * | "select"           |
     * | complete address 1 |
     * | complete address 2 |
     *      ...
     * | complete address n |
     * | "add address"      |
     */
private void addBillingAddressDropdown(EditorModel editor, final CreditCard card) {
    final List<DropdownKeyValue> billingAddresses = new ArrayList<>();
    billingAddresses.add(new DropdownKeyValue(BILLING_ADDRESS_NONE, mContext.getString(R.string.select)));
    for (Map.Entry<String, AutofillProfile> address : mProfilesForBillingAddress.entrySet()) {
        // Key is profile GUID. Value is profile label.
        billingAddresses.add(new DropdownKeyValue(address.getKey(), address.getValue().getLabel()));
    }
    billingAddresses.add(new DropdownKeyValue(BILLING_ADDRESS_ADD_NEW, mContext.getString(R.string.autofill_create_profile)));
    // Don't cache the billing address dropdown, because the user may have added or removed
    // profiles.
    mBillingAddressField = EditorFieldModel.createDropdown(mContext.getString(R.string.autofill_credit_card_editor_billing_address), billingAddresses);
    // The billing address is required.
    mBillingAddressField.setRequiredErrorMessage(mContext.getString(R.string.payments_field_required_validation_message));
    mBillingAddressField.setDropdownCallback(new Callback<Pair<String, Runnable>>() {

        @Override
        public void onResult(final Pair<String, Runnable> eventData) {
            if (!BILLING_ADDRESS_ADD_NEW.equals(eventData.first)) {
                if (mObserverForTest != null) {
                    mObserverForTest.onPaymentRequestServiceBillingAddressChangeProcessed();
                }
                return;
            }
            mAddressEditor.edit(null, new Callback<AutofillAddress>() {

                @Override
                public void onResult(AutofillAddress billingAddress) {
                    if (billingAddress == null) {
                        // User has cancelled the address editor.
                        mBillingAddressField.setValue(null);
                    } else {
                        // User has added a new complete address. Add it to the top of the
                        // dropdown, under the "Select" prompt.
                        mProfilesForBillingAddress.put(billingAddress.getIdentifier(), billingAddress.getProfile());
                        billingAddresses.add(1, new DropdownKeyValue(billingAddress.getIdentifier(), billingAddress.getSublabel()));
                        mBillingAddressField.setDropdownKeyValues(billingAddresses);
                        mBillingAddressField.setValue(billingAddress.getIdentifier());
                    }
                    // Let the card editor UI re-read the model and re-create UI elements.
                    mHandler.post(eventData.second);
                }
            });
        }
    });
    if (mBillingAddressField.getDropdownKeys().contains(card.getBillingAddressId())) {
        mBillingAddressField.setValue(card.getBillingAddressId());
    }
    editor.addField(mBillingAddressField);
}
Also used : ArrayList(java.util.ArrayList) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) Callback(org.chromium.base.Callback) HashMap(java.util.HashMap) Map(java.util.Map) DropdownKeyValue(org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue) Pair(android.util.Pair)

Aggregations

DropdownKeyValue (org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue)4 ArrayList (java.util.ArrayList)3 Pair (android.util.Pair)1 ArrayAdapter (android.widget.ArrayAdapter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Callback (org.chromium.base.Callback)1 AutofillProfile (org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)1