| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java
|
| index d7651749dc40752b32c56f982170029c087b53d5..084e197d7de8590d85aefa3e71b919b32f920707 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java
|
| @@ -38,27 +38,32 @@ import java.util.List;
|
| * ..............
|
| */
|
| public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
|
| + private final int mTextViewResourceId;
|
|
|
| /**
|
| * Creates an array adapter for which the last element is a hint that is not shown in the
|
| * expanded view and where the last shown element has a "+" icon on its left and has a blue
|
| * tint.
|
| *
|
| - * @param context The current context.
|
| - * @param resource The resource ID for a layout file containing a layout to use when
|
| - * instantiating views.
|
| - * @param objects The objects to represent in the ListView, the last of which will have a "+"
|
| - * icon on its left and will have a blue tint.
|
| - * @param hint The element to be used as a hint when no element is selected. It is not taken
|
| - * into account in the count function and thus will not be displayed when in the
|
| - * expanded dropdown view.
|
| + * @param context The current context.
|
| + * @param resource The resource ID for a layout file containing a layout to use when
|
| + * instantiating views.
|
| + * @param textViewResourceId The id of the TextView within the layout resource to be populated.
|
| + * @param objects The objects to represent in the ListView, the last of which will
|
| + * have a "+" icon on its left and will have a blue tint.
|
| + * @param hint The element to be used as a hint when no element is selected. It is
|
| + * not taken into account in the count function and thus will not be
|
| + * displayed when in the expanded dropdown view.
|
| */
|
| - public BillingAddressAdapter(Context context, int resource, List<T> objects, T hint) {
|
| + public BillingAddressAdapter(
|
| + Context context, int resource, int textViewResourceId, List<T> objects, T hint) {
|
| // Make a copy of objects so the hint is not added to the original list.
|
| - super(context, resource, new ArrayList<T>(objects));
|
| + super(context, resource, textViewResourceId, new ArrayList<T>(objects));
|
| // The hint is added as the last element. It will not be shown when the dropdown is
|
| // expanded and not be taken into account in the getCount function.
|
| add(hint);
|
| +
|
| + mTextViewResourceId = textViewResourceId;
|
| }
|
|
|
| @Override
|
| @@ -70,32 +75,58 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
|
|
|
| @Override
|
| public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
| - View view;
|
| + TextView textView = convertView == null
|
| + ? null
|
| + : (TextView) convertView.findViewById(mTextViewResourceId);
|
| + if (textView != null) {
|
| + // Clear the possible changes for the first and last view.
|
| + ApiCompatibilityUtils.setPaddingRelative(convertView,
|
| + ApiCompatibilityUtils.getPaddingStart(convertView), 0,
|
| + ApiCompatibilityUtils.getPaddingEnd(convertView), 0);
|
| + textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
| + ApiCompatibilityUtils.setTextAppearance(
|
| + textView, android.R.style.TextAppearance_Widget_DropDownItem);
|
| + }
|
| + convertView = super.getDropDownView(position, convertView, parent);
|
|
|
| - // Add a "+" icon and a blue tint to the last element.
|
| - if (position == getCount() - 1) {
|
| - view = super.getDropDownView(position, convertView, parent);
|
| - TextView tv = (TextView) view;
|
| + if (position == 0) {
|
| + // Padding at the top of the dropdown.
|
| + ApiCompatibilityUtils.setPaddingRelative(convertView,
|
| + ApiCompatibilityUtils.getPaddingStart(convertView),
|
| + getContext().getResources().getDimensionPixelSize(
|
| + R.dimen.payments_section_small_spacing),
|
| + ApiCompatibilityUtils.getPaddingEnd(convertView),
|
| + convertView.getPaddingBottom());
|
| + } else if (position == getCount() - 1) {
|
| + // Add a "+" icon and a blue tint to the last element.
|
| Resources resources = getContext().getResources();
|
| + if (textView == null) {
|
| + textView = (TextView) convertView.findViewById(mTextViewResourceId);
|
| + }
|
|
|
| // Create the "+" icon, put it left of the text and add appropriate padding.
|
| - tv.setCompoundDrawablesWithIntrinsicBounds(
|
| + textView.setCompoundDrawablesWithIntrinsicBounds(
|
| TintedDrawable.constructTintedDrawable(
|
| - resources, R.drawable.plus, R.color.light_active_color),
|
| + resources, R.drawable.plus, R.color.light_active_color),
|
| null, null, null);
|
| - tv.setCompoundDrawablePadding(
|
| + textView.setCompoundDrawablePadding(
|
| resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));
|
|
|
| // Set the correct appearance, face and style for the text.
|
| - ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel);
|
| - tv.setTypeface(Typeface.create(
|
| - resources.getString(R.string.roboto_medium_typeface),
|
| - R.integer.roboto_medium_textstyle));
|
| - } else {
|
| - // Don't use the recycled convertView, as it may have the style of the last element.
|
| - view = super.getDropDownView(position, null, parent);
|
| + ApiCompatibilityUtils.setTextAppearance(
|
| + textView, R.style.PaymentsUiSectionAddButtonLabel);
|
| + textView.setTypeface(
|
| + Typeface.create(resources.getString(R.string.roboto_medium_typeface),
|
| + R.integer.roboto_medium_textstyle));
|
| +
|
| + // Padding at the bottom of the dropdown.
|
| + ApiCompatibilityUtils.setPaddingRelative(convertView,
|
| + ApiCompatibilityUtils.getPaddingStart(convertView), convertView.getPaddingTop(),
|
| + ApiCompatibilityUtils.getPaddingEnd(convertView),
|
| + getContext().getResources().getDimensionPixelSize(
|
| + R.dimen.payments_section_small_spacing));
|
| }
|
|
|
| - return view;
|
| + return convertView;
|
| }
|
| }
|
|
|