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

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

Issue 2479613002: [Payments] Style the add address option in billing address selection. (Closed)
Patch Set: Addressed Dan's comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorDropdownField.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..f14b2b967dd19d3f9bdb02b10d2b8d57625b25af
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/BillingAddressAdapter.java
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.payments.ui;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Typeface;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.widget.TintedDrawable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Subclass of ArrayAdapter used to display a dropdown hint that won't appear in the expanded
+ * dropdown options but will be used when no element is selected. The last shown element will have a
+ * "+" icon on its left and a blue tint to indicate the option to add an element.
+ *
+ * @param <T> The type of element to be inserted into the adapter.
+ *
+ *
+ * collapsed view: -------- Expanded view: ------------
+ * (no item selected) | hint | | option 1 |
+ * -------- |------------|
+ * | option 2 |
+ * collapsed view: ---------- |------------|
+ * (with selected item) | option X | | + option N | -> stylized and "+" icon
+ * ---------- .------------.
+ * . hint . -> hidden
+ * ..............
+ */
+public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
+
+ /**
+ * 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.
+ */
+ public BillingAddressAdapter(Context context, int resource, 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));
+ // 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);
+ }
+
+ @Override
+ public int getCount() {
+ // Don't display last item, it is used as hint.
+ int count = super.getCount();
+ return count > 0 ? count - 1 : count;
+ }
+
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ View view = super.getDropDownView(position, convertView, parent);
+
+ // Add a "+" icon and a blue tint to the last element.
+ if (position == getCount() - 1) {
+ TextView tv = (TextView) view;
+ Resources resources = getContext().getResources();
+
+ // Create the "+" icon, put it left of the text and add appropriate padding.
+ tv.setCompoundDrawablesWithIntrinsicBounds(
+ TintedDrawable.constructTintedDrawable(
+ resources, R.drawable.plus, R.color.light_active_color),
+ null, null, null);
+ tv.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));
+ }
+
+ return view;
+ }
+}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorDropdownField.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698