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

Side by Side Diff: ui/android/java/src/org/chromium/ui/DropdownAdapter.java

Issue 443193006: Show icons in Android web autofill dropdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.ui; 5 package org.chromium.ui;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Color; 8 import android.graphics.Color;
9 import android.graphics.Typeface; 9 import android.graphics.Typeface;
10 import android.text.TextUtils; 10 import android.text.TextUtils;
11 import android.view.LayoutInflater; 11 import android.view.LayoutInflater;
12 import android.view.View; 12 import android.view.View;
13 import android.view.ViewGroup; 13 import android.view.ViewGroup;
14 import android.widget.AbsListView.LayoutParams; 14 import android.widget.AbsListView.LayoutParams;
15 import android.widget.ArrayAdapter; 15 import android.widget.ArrayAdapter;
16 import android.widget.ImageView;
16 import android.widget.TextView; 17 import android.widget.TextView;
17 18
18 import org.chromium.base.ApiCompatibilityUtils; 19 import org.chromium.base.ApiCompatibilityUtils;
19 20
20 import java.util.List; 21 import java.util.List;
21 import java.util.Set; 22 import java.util.Set;
22 23
23 /** 24 /**
24 * Dropdown item adapter for DropdownPopupWindow. 25 * Dropdown item adapter for DropdownPopupWindow.
25 */ 26 */
(...skipping 29 matching lines...) Expand all
55 @Override 56 @Override
56 public View getView(int position, View convertView, ViewGroup parent) { 57 public View getView(int position, View convertView, ViewGroup parent) {
57 View layout = convertView; 58 View layout = convertView;
58 if (convertView == null) { 59 if (convertView == null) {
59 LayoutInflater inflater = 60 LayoutInflater inflater =
60 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); 61 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE);
61 layout = inflater.inflate(R.layout.dropdown_item, null); 62 layout = inflater.inflate(R.layout.dropdown_item, null);
62 ApiCompatibilityUtils.setBackgroundForView(layout, new DropdownDivid erDrawable()); 63 ApiCompatibilityUtils.setBackgroundForView(layout, new DropdownDivid erDrawable());
63 } 64 }
64 65
65 DropdownItem item = getItem(position);
66
67 TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label) ;
68 labelView.setText(item.getLabel());
69
70 labelView.setEnabled(item.isEnabled());
71 if (item.isGroupHeader()) {
72 labelView.setTypeface(null, Typeface.BOLD);
73 } else {
74 labelView.setTypeface(null, Typeface.NORMAL);
75 }
76
77 DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBa ckground(); 66 DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBa ckground();
78 int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropd own_item_height); 67 int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropd own_item_height);
79 if (position == 0) { 68 if (position == 0) {
80 divider.setColor(Color.TRANSPARENT); 69 divider.setColor(Color.TRANSPARENT);
81 } else { 70 } else {
82 int dividerHeight = mContext.getResources().getDimensionPixelSize( 71 int dividerHeight = mContext.getResources().getDimensionPixelSize(
83 R.dimen.dropdown_item_divider_height); 72 R.dimen.dropdown_item_divider_height);
84 height += dividerHeight; 73 height += dividerHeight;
85 divider.setHeight(dividerHeight); 74 divider.setHeight(dividerHeight);
86 if (mSeparators != null && mSeparators.contains(position)) { 75 if (mSeparators != null && mSeparators.contains(position)) {
87 divider.setColor(mContext.getResources().getColor( 76 divider.setColor(mContext.getResources().getColor(
88 R.color.dropdown_dark_divider_color)); 77 R.color.dropdown_dark_divider_color));
89 } else { 78 } else {
90 divider.setColor(mContext.getResources().getColor( 79 divider.setColor(mContext.getResources().getColor(
91 R.color.dropdown_divider_color)); 80 R.color.dropdown_divider_color));
92 } 81 }
93 } 82 }
94 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, heigh t)); 83 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, heigh t));
95 84
85 DropdownItem item = getItem(position);
86 TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label) ;
87 labelView.setText(item.getLabel());
88
89 labelView.setEnabled(item.isEnabled());
90 if (item.isGroupHeader()) {
91 labelView.setTypeface(null, Typeface.BOLD);
92 } else {
93 labelView.setTypeface(null, Typeface.NORMAL);
94 }
95
96 TextView sublabelView = (TextView) layout.findViewById(R.id.dropdown_sub label); 96 TextView sublabelView = (TextView) layout.findViewById(R.id.dropdown_sub label);
97 CharSequence sublabel = item.getSublabel(); 97 CharSequence sublabel = item.getSublabel();
98 if (TextUtils.isEmpty(sublabel)) { 98 if (TextUtils.isEmpty(sublabel)) {
99 sublabelView.setVisibility(View.GONE); 99 sublabelView.setVisibility(View.GONE);
100 } else { 100 } else {
101 sublabelView.setText(sublabel); 101 sublabelView.setText(sublabel);
102 sublabelView.setVisibility(View.VISIBLE); 102 sublabelView.setVisibility(View.VISIBLE);
103 } 103 }
104 104
105 ImageView iconView = (ImageView) layout.findViewById(R.id.dropdown_icon) ;
106 if (item.getIconId() == DropdownItem.NO_ICON) {
107 iconView.setVisibility(View.GONE);
108 } else {
109 iconView.setImageResource(item.getIconId());
110 iconView.setVisibility(View.VISIBLE);
111 }
112
105 return layout; 113 return layout;
106 } 114 }
107 115
108 @Override 116 @Override
109 public boolean areAllItemsEnabled() { 117 public boolean areAllItemsEnabled() {
110 return mAreAllItemsEnabled; 118 return mAreAllItemsEnabled;
111 } 119 }
112 120
113 @Override 121 @Override
114 public boolean isEnabled(int position) { 122 public boolean isEnabled(int position) {
115 if (position < 0 || position >= getCount()) return false; 123 if (position < 0 || position >= getCount()) return false;
116 DropdownItem item = getItem(position); 124 DropdownItem item = getItem(position);
117 return item.isEnabled() && !item.isGroupHeader(); 125 return item.isEnabled() && !item.isGroupHeader();
118 } 126 }
119 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698