Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(950)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java

Issue 2592733002: [Payments] Update billing address dropdown style to match the design (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bfe68653dbd6208169c9c173f419d02144f2abb9 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
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.payments.ui;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@@ -38,6 +39,7 @@ import java.util.List;
* ..............
*/
public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
+ private final Context mContext;
/**
* Creates an array adapter for which the last element is a hint that is not shown in the
@@ -59,6 +61,7 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
// 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);
+ mContext = context;
}
@Override
@@ -70,30 +73,46 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
- View view;
+ // Don't use the recycled convertView, as it may have the style of the last element.
+ // Wrap the TextView around with a LinearLayout to display the text in multiple lines.
+ View view = LayoutInflater.from(mContext).inflate(
Ian Wen 2016/12/20 21:52:23 Oops. Always inflating sounds like a bad idea as i
gogerald1 2016/12/21 00:36:34 Yes, unfortunately getViewTypeCount must return 1
+ R.layout.payment_request_dropdown_item, parent, false);
+ if (position == 0) {
+ // Padding at the top of the dropdown.
+ ApiCompatibilityUtils.setPaddingRelative(view,
+ ApiCompatibilityUtils.getPaddingStart(view),
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.payments_section_small_spacing),
+ ApiCompatibilityUtils.getPaddingEnd(view), view.getPaddingBottom());
+ }
+ TextView textView = (TextView) view.findViewById(R.id.dropdown_item);
+ textView.setText(getItem(position).toString());
// 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;
Resources resources = getContext().getResources();
// 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(view,
+ ApiCompatibilityUtils.getPaddingStart(view), view.getPaddingTop(),
+ ApiCompatibilityUtils.getPaddingEnd(view),
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.payments_section_small_spacing));
}
return view;

Powered by Google App Engine
This is Rietveld 408576698