Java Code Examples for org.chromium.chrome.browser.payments.ui.SectionInformation#NO_SELECTION

The following examples show how to use org.chromium.chrome.browser.payments.ui.SectionInformation#NO_SELECTION . 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: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a list of shipping options and returns their parsed representation.
 *
 * @param options The raw shipping options to parse and validate.
 * @param totalCurrency The currency code for the total amount of payment.
 * @param formatter A formatter and validator for the currency amount value.
 * @return The UI representation of the shipping options.
 */
private static SectionInformation getShippingOptions(PaymentShippingOption[] options,
        String totalCurrency, CurrencyStringFormatter formatter) {
    // Shipping options are optional.
    if (options == null || options.length == 0) {
        return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
    }

    List<PaymentOption> result = new ArrayList<>();
    int selectedItemIndex = SectionInformation.NO_SELECTION;
    for (int i = 0; i < options.length; i++) {
        PaymentShippingOption option = options[i];
        result.add(new PaymentOption(option.id, option.label,
                formatter.format(option.amount.value), null));
        if (option.selected) selectedItemIndex = i;
    }

    return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, selectedItemIndex,
            result);
}
 
Example 2
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a list of shipping options and returns their parsed representation.
 *
 * @param options   The raw shipping options to parse. Can be null.
 * @return The UI representation of the shipping options.
 */
private SectionInformation getShippingOptions(@Nullable PaymentShippingOption[] options) {
    // Shipping options are optional.
    if (options == null || options.length == 0) {
        return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
    }

    List<PaymentOption> result = new ArrayList<>();
    int selectedItemIndex = SectionInformation.NO_SELECTION;
    for (int i = 0; i < options.length; i++) {
        PaymentShippingOption option = options[i];
        CurrencyFormatter formatter = getOrCreateCurrencyFormatter(option.amount);
        String currencyPrefix = isMixedOrChangedCurrency()
                ? formatter.getFormattedCurrencyCode() + "\u0020"
                : "";
        result.add(new PaymentOption(option.id, option.label,
                currencyPrefix + formatter.format(option.amount.value), null));
        if (option.selected) selectedItemIndex = i;
    }

    return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, selectedItemIndex,
            Collections.unmodifiableList(result));
}
 
Example 3
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void createShippingSection(
        Context context, List<AutofillProfile> unmodifiableProfiles) {
    List<AutofillAddress> addresses = new ArrayList<>();

    for (int i = 0; i < unmodifiableProfiles.size(); i++) {
        AutofillProfile profile = unmodifiableProfiles.get(i);
        mAddressEditor.addPhoneNumberIfValid(profile.getPhoneNumber());

        // Only suggest addresses that have a street address.
        if (!TextUtils.isEmpty(profile.getStreetAddress())) {
            addresses.add(new AutofillAddress(context, profile));
        }
    }

    // Suggest complete addresses first.
    Collections.sort(addresses, COMPLETENESS_COMPARATOR);

    // Limit the number of suggestions.
    addresses = addresses.subList(0, Math.min(addresses.size(), SUGGESTIONS_LIMIT));

    // Load the validation rules for each unique region code.
    Set<String> uniqueCountryCodes = new HashSet<>();
    for (int i = 0; i < addresses.size(); ++i) {
        String countryCode = AutofillAddress.getCountryCode(addresses.get(i).getProfile());
        if (!uniqueCountryCodes.contains(countryCode)) {
            uniqueCountryCodes.add(countryCode);
            PersonalDataManager.getInstance().loadRulesForAddressNormalization(countryCode);
        }
    }

    // Log the number of suggested shipping addresses.
    mJourneyLogger.setNumberOfSuggestionsShown(Section.SHIPPING_ADDRESS, addresses.size());

    // Automatically select the first address if one is complete and if the merchant does
    // not require a shipping address to calculate shipping costs.
    int firstCompleteAddressIndex = SectionInformation.NO_SELECTION;
    if (mUiShippingOptions.getSelectedItem() != null && !addresses.isEmpty()
            && addresses.get(0).isComplete()) {
        firstCompleteAddressIndex = 0;

        // The initial label for the selected shipping address should not include the
        // country.
        addresses.get(firstCompleteAddressIndex).setShippingAddressLabelWithoutCountry();
    }

    mShippingAddressesSection = new SectionInformation(
            PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, firstCompleteAddressIndex, addresses);
}