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

Unified Diff: ui/android/java/src/org/chromium/ui/DropdownAdapter.java

Issue 2649623002: [Autofill] Uses uniform margin for icon, label and sublabel in popup (Closed)
Patch Set: Removes the 1px offset because the misalignment between card icon and 'C' in 'Chrom...' appears to … 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: ui/android/java/src/org/chromium/ui/DropdownAdapter.java
diff --git a/ui/android/java/src/org/chromium/ui/DropdownAdapter.java b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java
index d08a15935fff89636e09762c86751505c504e2a8..366c879e111f1e4d1a95312350f03e83865b6884 100644
--- a/ui/android/java/src/org/chromium/ui/DropdownAdapter.java
+++ b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java
@@ -34,6 +34,7 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
private final Integer mBackgroundColor;
private final Integer mDividerColor;
private final Integer mDropdownItemHeight;
+ private final Integer mMargin;
/**
* Creates an {@code ArrayAdapter} with specified parameters.
@@ -47,10 +48,13 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
* uses the values in colors.xml for the dark divider for the separators.
* @param dropdownItemHeight If {@code null}, uses the {@code dropdown_item_height} in
* dimens.xml. Otherwise, uses {@param dropdownItemHeight}.
+ * @param margin If {@code null}, uses the {@code dropdown_icon_margin} and
+ * {@code dropdown_item_label_margin} in dropdown_item.xml. Otherwise, uses {@param margin}
+ * for uniform margin for icon, label and between icon and label.
*/
public DropdownAdapter(Context context, List<? extends DropdownItem> items,
Set<Integer> separators, Integer backgroundColor, Integer dividerColor,
- Integer dropdownItemHeight) {
+ Integer dropdownItemHeight, Integer margin) {
Mathieu 2017/01/27 00:40:44 @Nullable?
csashi 2017/01/27 01:21:32 Done.
super(context, R.layout.dropdown_item);
mContext = context;
addAll(items);
@@ -59,6 +63,7 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
mBackgroundColor = backgroundColor;
mDividerColor = dividerColor;
mDropdownItemHeight = dropdownItemHeight;
+ mMargin = margin;
}
private boolean checkAreAllItemsEnabled() {
@@ -130,19 +135,31 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
labelView.setText(item.getLabel());
labelView.setSingleLine(!item.isMultilineLabel());
+ // If |margin| is not null, we use a uniform margin between start and the icon, between icon
+ // and the label and between the label and the end.
+ // <-- margin -->|icon|<-- margin -->|label|<-- margin -->
+ // <-- margin -->|label|<-- margin -->
+ int margin = mMargin == null ? 0 : (int) TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_DIP, mMargin, mContext.getResources().getDisplayMetrics());
+ LinearLayout.LayoutParams layoutParams;
if (item.isLabelAndSublabelOnSameLine()) {
- labelView.setLayoutParams(
- new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
+ layoutParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
} else {
- LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
+ LayoutParams.WRAP_CONTENT);
int labelMargin = mContext.getResources().getDimensionPixelSize(
R.dimen.dropdown_item_label_margin);
- ApiCompatibilityUtils.setMarginStart(layoutParams, labelMargin);
- ApiCompatibilityUtils.setMarginEnd(layoutParams, labelMargin);
- labelView.setLayoutParams(layoutParams);
+ if (margin == 0) {
Mathieu 2017/01/27 00:40:44 check for null?
csashi 2017/01/27 01:21:32 Done.
+ ApiCompatibilityUtils.setMarginStart(layoutParams, labelMargin);
+ ApiCompatibilityUtils.setMarginEnd(layoutParams, labelMargin);
+ } else {
+ if (item.getIconId() == DropdownItem.NO_ICON) {
+ ApiCompatibilityUtils.setMarginStart(layoutParams, margin);
+ }
+ ApiCompatibilityUtils.setMarginEnd(layoutParams, margin);
+ }
if (item.isMultilineLabel()) {
- // If there is a multiline label, we add extra padding top and bottom because
+ // If there is a multiline label, we add extra padding at the top and bottom because
// WRAP_CONTENT, defined above for multiline labels, leaves none.
int existingStart = ApiCompatibilityUtils.getPaddingStart(labelView);
int existingEnd = ApiCompatibilityUtils.getPaddingEnd(labelView);
@@ -151,6 +168,7 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
}
}
+ labelView.setLayoutParams(layoutParams);
labelView.setEnabled(item.isEnabled());
if (item.isGroupHeader() || item.isBoldLabel()) {
labelView.setTypeface(null, Typeface.BOLD);
@@ -168,6 +186,7 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
if (TextUtils.isEmpty(sublabel)) {
sublabelView.setVisibility(View.GONE);
} else {
+ sublabelView.setLayoutParams(layoutParams);
sublabelView.setText(sublabel);
sublabelView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
mContext.getResources().getDimension(item.getSublabelFontSizeResId()));
@@ -190,15 +209,16 @@ public class DropdownAdapter extends ArrayAdapter<DropdownItem> {
int iconSize = iconSizeResId == 0
? LayoutParams.WRAP_CONTENT
: mContext.getResources().getDimensionPixelSize(iconSizeResId);
- ViewGroup.MarginLayoutParams layoutParams =
+ ViewGroup.MarginLayoutParams iconLayoutParams =
(ViewGroup.MarginLayoutParams) iconView.getLayoutParams();
- layoutParams.width = iconSize;
- layoutParams.height = iconSize;
- int iconMargin =
- mContext.getResources().getDimensionPixelSize(item.getIconMarginResId());
- ApiCompatibilityUtils.setMarginStart(layoutParams, iconMargin);
- ApiCompatibilityUtils.setMarginEnd(layoutParams, iconMargin);
- iconView.setLayoutParams(layoutParams);
+ iconLayoutParams.width = iconSize;
+ iconLayoutParams.height = iconSize;
+ int iconMargin = margin == 0
Mathieu 2017/01/27 00:40:44 same?
csashi 2017/01/27 01:21:32 Done.
+ ? mContext.getResources().getDimensionPixelSize(item.getIconMarginResId())
+ : margin;
+ ApiCompatibilityUtils.setMarginStart(iconLayoutParams, iconMargin);
+ ApiCompatibilityUtils.setMarginEnd(iconLayoutParams, iconMargin);
+ iconView.setLayoutParams(iconLayoutParams);
iconView.setImageDrawable(AppCompatResources.getDrawable(mContext, item.getIconId()));
iconView.setVisibility(View.VISIBLE);
}

Powered by Google App Engine
This is Rietveld 408576698