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

The following examples show how to use org.chromium.chrome.browser.preferences.autofill.AutofillProfileBridge.DropdownKeyValue. 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: CardEditor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #2
Source File: CardEditor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #3
Source File: CardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #4
Source File: CardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** 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("MM", 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;
}
 
Example #5
Source File: AutofillProfileEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void populateCountriesDropdown() {
    List<DropdownKeyValue> countries = AutofillProfileBridge.getSupportedCountries();
    mCountryCodes = new ArrayList<String>();

    for (DropdownKeyValue country : countries) {
        mCountryCodes.add(country.getKey());
    }

    ArrayAdapter<DropdownKeyValue> countriesAdapter =
            new DropdownFieldAdapter<DropdownKeyValue>(
                    getActivity(), android.R.layout.simple_spinner_item, countries);
    countriesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCountriesDropdown.setAdapter(countriesAdapter);
}
 
Example #6
Source File: EditorFieldModel.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a dropdown field model with a validator.
 *
 * @param label                The human-readable label for user to understand the type of data
 *                             that should be entered into this field.
 * @param dropdownKeyValues    The keyed values to display in the dropdown.
 * @param validator            The validator for the values in this field.
 * @param requiredErrorMessage The error message that indicates to the user that they
 *                             cannot leave this field empty.
 */
public static EditorFieldModel createDropdown(
        @Nullable CharSequence label, List<DropdownKeyValue> dropdownKeyValues,
        EditorFieldValidator validator, CharSequence invalidErrorMessage) {
    assert dropdownKeyValues != null;
    assert validator != null;
    assert invalidErrorMessage != null;
    EditorFieldModel result = createDropdown(label, dropdownKeyValues, null /* hint */);
    result.mValidator = validator;
    result.mInvalidErrorMessage = invalidErrorMessage;
    return result;
}
 
Example #7
Source File: EditorFieldModel.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a dropdown field model.
 *
 * @param label             The human-readable label for user to understand the type of data
 *                          that should be entered into this field.
 * @param dropdownKeyValues The keyed values to display in the dropdown.
 * @param hint              The optional hint to be displayed when no value is selected.
 */
public static EditorFieldModel createDropdown(
        @Nullable CharSequence label, List<DropdownKeyValue> dropdownKeyValues,
        @Nullable CharSequence hint) {
    assert dropdownKeyValues != null;
    EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN);
    result.mLabel = label;
    result.mHint = hint;
    result.setDropdownKeyValues(dropdownKeyValues);
    return result;
}
 
Example #8
Source File: EditorDropdownField.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static int getDropdownIndex(
        List<DropdownKeyValue> dropdownKeyValues, CharSequence value) {
    for (int i = 0; i < dropdownKeyValues.size(); i++) {
        if (dropdownKeyValues.get(i).getKey().equals(value)) return i;
    }
    return 0;
}
 
Example #9
Source File: EditorDropdownField.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static List<CharSequence> getDropdownValues(List<DropdownKeyValue> dropdownKeyValues) {
    List<CharSequence> dropdownValues = new ArrayList<CharSequence>();
    for (int i = 0; i < dropdownKeyValues.size(); i++) {
        dropdownValues.add(dropdownKeyValues.get(i).getValue());
    }
    return dropdownValues;
}
 
Example #10
Source File: AutofillProfileEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: EditorFieldModel.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a dropdown field model.
 *
 * @param label             The human-readable label for user to understand the type of data
 *                          that should be entered into this field.
 * @param dropdownKeyValues The keyed values to display in the dropdown.
 */
public EditorFieldModel(CharSequence label, List<DropdownKeyValue> dropdownKeyValues) {
    mInputTypeHint = INPUT_TYPE_HINT_DROPDOWN;
    mDropdownKeyValues = dropdownKeyValues;
    mSuggestions = null;
    mValidator = null;
    mInvalidErrorMessage = null;
    mLabel = label;
}
 
Example #12
Source File: EditorFieldModel.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a dropdown field model with a validator.
 *
 * @param label                The human-readable label for user to understand the type of data
 *                             that should be entered into this field.
 * @param dropdownKeyValues    The keyed values to display in the dropdown.
 * @param validator            The validator for the values in this field.
 * @param requiredErrorMessage The error message that indicates to the user that they
 *                             cannot leave this field empty.
 */
public static EditorFieldModel createDropdown(
        @Nullable CharSequence label, List<DropdownKeyValue> dropdownKeyValues,
        EditorFieldValidator validator, CharSequence invalidErrorMessage) {
    assert dropdownKeyValues != null;
    assert validator != null;
    assert invalidErrorMessage != null;
    EditorFieldModel result = createDropdown(label, dropdownKeyValues, null /* hint */);
    result.mValidator = validator;
    result.mInvalidErrorMessage = invalidErrorMessage;
    return result;
}
 
Example #13
Source File: EditorFieldModel.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a dropdown field model.
 *
 * @param label             The human-readable label for user to understand the type of data
 *                          that should be entered into this field.
 * @param dropdownKeyValues The keyed values to display in the dropdown.
 * @param hint              The optional hint to be displayed when no value is selected.
 */
public static EditorFieldModel createDropdown(
        @Nullable CharSequence label, List<DropdownKeyValue> dropdownKeyValues,
        @Nullable CharSequence hint) {
    assert dropdownKeyValues != null;
    EditorFieldModel result = new EditorFieldModel(INPUT_TYPE_HINT_DROPDOWN);
    result.mLabel = label;
    result.mDropdownKeyValues = dropdownKeyValues;
    result.mHint = hint;
    result.mDropdownKeys = new HashSet<>();
    for (int i = 0; i < result.mDropdownKeyValues.size(); i++) {
        result.mDropdownKeys.add(result.mDropdownKeyValues.get(i).getKey());
    }
    return result;
}
 
Example #14
Source File: EditorDropdownField.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private static int getDropdownIndex(
        List<DropdownKeyValue> dropdownKeyValues, CharSequence value) {
    for (int i = 0; i < dropdownKeyValues.size(); i++) {
        if (dropdownKeyValues.get(i).getKey().equals(value)) return i;
    }
    return 0;
}
 
Example #15
Source File: EditorFieldModel.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Updates the dropdown key values. */
public void setDropdownKeyValues(List<DropdownKeyValue> dropdownKeyValues) {
    assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
    mDropdownKeyValues = dropdownKeyValues;
    mDropdownKeys = new HashSet<>();
    for (int i = 0; i < mDropdownKeyValues.size(); i++) {
        mDropdownKeys.add(mDropdownKeyValues.get(i).getKey());
    }
    assert mDropdownKeyValues.size() == mDropdownKeys.size();
}
 
Example #16
Source File: AutofillProfileEditor.java    From delion with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: EditorFieldModel.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** @return The dropdown key-value pairs. */
public List<DropdownKeyValue> getDropdownKeyValues() {
    assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
    return mDropdownKeyValues;
}
 
Example #18
Source File: EditorFieldModel.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Updates the dropdown key values. */
public void setDropdownKeyValues(List<DropdownKeyValue> dropdownKeyValues) {
    assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
    mDropdownKeyValues = dropdownKeyValues;
}
 
Example #19
Source File: EditorFieldModel.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** @return The dropdown key-value pairs. */
public List<DropdownKeyValue> getDropdownKeyValues() {
    assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
    return mDropdownKeyValues;
}
 
Example #20
Source File: CardEditor.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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<>();

    for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
        billingAddresses.add(new DropdownKeyValue(mProfilesForBillingAddress.get(i).getGUID(),
                mProfilesForBillingAddress.get(i).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. Also pass the "Select" dropdown item as a hint to the dropdown constructor.
    mBillingAddressField = EditorFieldModel.createDropdown(
            mContext.getString(R.string.autofill_credit_card_editor_billing_address),
            billingAddresses, mContext.getString(R.string.select));

    // 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.
                        mProfilesForBillingAddress.add(billingAddress.getProfile());
                        billingAddresses.add(
                                0, 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);
}
 
Example #21
Source File: EditorFieldModel.java    From delion with Apache License 2.0 4 votes vote down vote up
/** @return The spinner key values. */
public List<DropdownKeyValue> getDropdownKeyValues() {
    assert mInputTypeHint == INPUT_TYPE_HINT_DROPDOWN;
    return mDropdownKeyValues;
}