Commit 05265d26 authored by gogerald's avatar gogerald Committed by Commit bot

Update billing address dropdown style to match the design

BUG=661357

Review-Url: https://codereview.chromium.org/2592733002
Cr-Commit-Position: refs/heads/master@{#441480}
parent 73929a70
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
--> -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_item"
style="?android:attr/spinnerItemStyle" style="?android:attr/spinnerItemStyle"
android:singleLine="false" android:singleLine="false"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingEnd="24dp"
android:textAlignment="inherit" /> android:textAlignment="inherit" />
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/spinner_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:minHeight="48dp"
style="?android:attr/spinnerDropDownItemStyle" />
</FrameLayout>
\ No newline at end of file
...@@ -21,9 +21,11 @@ ...@@ -21,9 +21,11 @@
<android.support.v7.widget.AppCompatSpinner <android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner" android:id="@+id/spinner"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/pref_autofill_field_top_margin" /> android:layout_marginTop="@dimen/pref_autofill_field_top_margin"
android:padding="0dp"
android:dropDownWidth="match_parent" />
<View style="@style/PreferenceSpinnerUnderlineView" /> <View style="@style/PreferenceSpinnerUnderlineView" />
......
...@@ -38,6 +38,7 @@ import java.util.List; ...@@ -38,6 +38,7 @@ import java.util.List;
* .............. * ..............
*/ */
public class BillingAddressAdapter<T> extends ArrayAdapter<T> { 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 * Creates an array adapter for which the last element is a hint that is not shown in the
...@@ -47,18 +48,22 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> { ...@@ -47,18 +48,22 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
* @param context The current context. * @param context The current context.
* @param resource The resource ID for a layout file containing a layout to use when * @param resource The resource ID for a layout file containing a layout to use when
* instantiating views. * instantiating views.
* @param objects The objects to represent in the ListView, the last of which will have a "+" * @param textViewResourceId The id of the TextView within the layout resource to be populated.
* icon on its left and will have a blue tint. * @param objects The objects to represent in the ListView, the last of which will
* @param hint The element to be used as a hint when no element is selected. It is not taken * have a "+" icon on its left and will have a blue tint.
* into account in the count function and thus will not be displayed when in the * @param hint The element to be used as a hint when no element is selected. It is
* expanded dropdown view. * 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. // 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 // 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. // expanded and not be taken into account in the getCount function.
add(hint); add(hint);
mTextViewResourceId = textViewResourceId;
} }
@Override @Override
...@@ -70,32 +75,58 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> { ...@@ -70,32 +75,58 @@ public class BillingAddressAdapter<T> extends ArrayAdapter<T> {
@Override @Override
public View getDropDownView(int position, View convertView, ViewGroup parent) { 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);
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. // 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(); 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. // Create the "+" icon, put it left of the text and add appropriate padding.
tv.setCompoundDrawablesWithIntrinsicBounds( textView.setCompoundDrawablesWithIntrinsicBounds(
TintedDrawable.constructTintedDrawable( TintedDrawable.constructTintedDrawable(
resources, R.drawable.plus, R.color.light_active_color), resources, R.drawable.plus, R.color.light_active_color),
null, null, null); null, null, null);
tv.setCompoundDrawablePadding( textView.setCompoundDrawablePadding(
resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing)); resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));
// Set the correct appearance, face and style for the text. // Set the correct appearance, face and style for the text.
ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel); ApiCompatibilityUtils.setTextAppearance(
tv.setTypeface(Typeface.create( textView, R.style.PaymentsUiSectionAddButtonLabel);
resources.getString(R.string.roboto_medium_typeface), textView.setTypeface(
Typeface.create(resources.getString(R.string.roboto_medium_typeface),
R.integer.roboto_medium_textstyle)); R.integer.roboto_medium_textstyle));
} else {
// Don't use the recycled convertView, as it may have the style of the last element. // Padding at the bottom of the dropdown.
view = super.getDropDownView(position, null, parent); ApiCompatibilityUtils.setPaddingRelative(convertView,
ApiCompatibilityUtils.getPaddingStart(convertView), convertView.getPaddingTop(),
ApiCompatibilityUtils.getPaddingEnd(convertView),
getContext().getResources().getDimensionPixelSize(
R.dimen.payments_section_small_spacing));
} }
return view; return convertView;
} }
} }
\ No newline at end of file
...@@ -59,9 +59,15 @@ class EditorDropdownField implements EditorFieldView { ...@@ -59,9 +59,15 @@ class EditorDropdownField implements EditorFieldView {
ArrayAdapter<DropdownKeyValue> adapter; ArrayAdapter<DropdownKeyValue> adapter;
if (mFieldModel.getHint() != null) { if (mFieldModel.getHint() != null) {
// Use the BillingAddressAdapter and pass it a hint to be displayed as default. // Use the BillingAddressAdapter and pass it a hint to be displayed as default.
adapter = new BillingAddressAdapter<DropdownKeyValue>( adapter = new BillingAddressAdapter<DropdownKeyValue>(context,
context, R.layout.multiline_spinner_item, dropdownKeyValues, R.layout.multiline_spinner_item, R.id.spinner_item, dropdownKeyValues,
new DropdownKeyValue("", mFieldModel.getHint().toString())); new DropdownKeyValue("", mFieldModel.getHint().toString()));
// Wrap the TextView in the dropdown popup around with a FrameLayout to display the text
// in multiple lines.
// Note that the TextView in the dropdown popup is displayed in a DropDownListView for
// the dropdown style Spinner and the DropDownListView sets to display TextView instance
// in a single line.
adapter.setDropDownViewResource(R.layout.payment_request_dropdown_item);
// If no value is selected, select the hint entry which is the last item in the adapter. // If no value is selected, select the hint entry which is the last item in the adapter.
// Using getCount will not result in an out of bounds index because the hint value is // Using getCount will not result in an out of bounds index because the hint value is
...@@ -70,8 +76,8 @@ class EditorDropdownField implements EditorFieldView { ...@@ -70,8 +76,8 @@ class EditorDropdownField implements EditorFieldView {
} else { } else {
adapter = new ArrayAdapter<DropdownKeyValue>( adapter = new ArrayAdapter<DropdownKeyValue>(
context, R.layout.multiline_spinner_item, dropdownKeyValues); context, R.layout.multiline_spinner_item, dropdownKeyValues);
}
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
mDropdown = (Spinner) mLayout.findViewById(R.id.spinner); mDropdown = (Spinner) mLayout.findViewById(R.id.spinner);
mDropdown.setTag(this); mDropdown.setTag(this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment