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

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

Issue 23314003: Add support for datalist to text input element on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 5
6 package org.chromium.ui.autofill; 6 package org.chromium.ui.autofill;
7 7
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.res.Resources;
10 import android.graphics.Color;
11 import android.graphics.drawable.LayerDrawable;
9 import android.text.TextUtils; 12 import android.text.TextUtils;
10
11 import android.view.LayoutInflater; 13 import android.view.LayoutInflater;
12 import android.view.View; 14 import android.view.View;
13 import android.view.ViewGroup; 15 import android.view.ViewGroup;
16 import android.widget.AbsListView.LayoutParams;
14 import android.widget.ArrayAdapter; 17 import android.widget.ArrayAdapter;
15 import android.widget.TextView; 18 import android.widget.TextView;
16 19
17 import org.chromium.ui.R; 20 import org.chromium.ui.R;
18 21
22 import org.chromium.base.ApiCompatibilityUtils;
23
19 import java.util.ArrayList; 24 import java.util.ArrayList;
25 import java.util.Set;
20 26
21 /** 27 /**
22 * Autofill suggestion adapter for AutofillWindow. 28 * Autofill suggestion adapter for AutofillWindow.
23 */ 29 */
24 public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { 30 public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> {
25 private Context mContext; 31 private Context mContext;
32 private Set<Integer> mSeparators;
26 33
27 AutofillListAdapter(Context context, ArrayList<AutofillSuggestion> objects) { 34 AutofillListAdapter(Context context,
35 ArrayList<AutofillSuggestion> objects,
36 Set<Integer> separators) {
28 super(context, R.layout.autofill_text, objects); 37 super(context, R.layout.autofill_text, objects);
38 mSeparators = separators;
29 mContext = context; 39 mContext = context;
30 } 40 }
31 41
32 @Override 42 @Override
33 public View getView(int position, View convertView, ViewGroup parent) { 43 public View getView(int position, View convertView, ViewGroup parent) {
34 View layout = convertView; 44 View layout = convertView;
35 if (convertView == null) { 45 if (convertView == null) {
36 LayoutInflater inflater = 46 LayoutInflater inflater =
37 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); 47 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE);
38 layout = inflater.inflate(R.layout.autofill_text, null); 48 layout = inflater.inflate(R.layout.autofill_text, null);
49 ApiCompatibilityUtils.setBackgroundForView(layout, new AutofillDivid erDrawable());
39 } 50 }
40 TextView labelView = (TextView) layout.findViewById(R.id.autofill_label) ; 51 TextView labelView = (TextView) layout.findViewById(R.id.autofill_label) ;
41 labelView.setText(getItem(position).mLabel); 52 labelView.setText(getItem(position).mLabel);
42 53
54 AutofillDividerDrawable divider = (AutofillDividerDrawable) layout.getBa ckground();
55 int height = mContext.getResources().getDimensionPixelSize(R.dimen.autof ill_text_height);
56 if (position == 0) {
57 divider.setColor(Color.TRANSPARENT);
58 } else {
59 int dividerHeight = mContext.getResources().getDimensionPixelSize(
60 R.dimen.autofill_text_divider_height);
61 height += dividerHeight;
62 divider.setHeight(dividerHeight);
63 if (mSeparators.contains(position)) {
64 divider.setColor(mContext.getResources().getColor(
65 R.color.autofill_dark_divider_color));
66 } else {
67 divider.setColor(mContext.getResources().getColor(
68 R.color.autofill_divider_color));
69 }
70 }
71 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, heigh t));
72
43 TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sub label); 73 TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sub label);
44 CharSequence sublabel = getItem(position).mSublabel; 74 CharSequence sublabel = getItem(position).mSublabel;
45 if (TextUtils.isEmpty(sublabel)) { 75 if (TextUtils.isEmpty(sublabel)) {
46 sublabelView.setVisibility(View.GONE); 76 sublabelView.setVisibility(View.GONE);
47 } else { 77 } else {
48 sublabelView.setText(sublabel); 78 sublabelView.setText(sublabel);
49 sublabelView.setVisibility(View.VISIBLE); 79 sublabelView.setVisibility(View.VISIBLE);
50 } 80 }
51 81
52 return layout; 82 return layout;
53 } 83 }
54 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698