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

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: pad at the end of the selected item view to avoid overlapping dropdown icon Created 3 years, 11 months 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..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;
}
}

Powered by Google App Engine
This is Rietveld 408576698