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
3 // found in the LICENSE file.
5 package org.chromium.ui.autofill;
7 import android.content.Context;
8 import android.graphics.Color;
9 import android.text.TextUtils;
10 import android.view.LayoutInflater;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.widget.AbsListView.LayoutParams;
14 import android.widget.ArrayAdapter;
15 import android.widget.TextView;
17 import org.chromium.base.ApiCompatibilityUtils;
18 import org.chromium.ui.R;
20 import java.util.ArrayList;
24 * Autofill suggestion adapter for AutofillWindow.
26 public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> {
27 private Context mContext;
28 private Set<Integer> mSeparators;
30 AutofillListAdapter(Context context,
31 ArrayList<AutofillSuggestion> objects,
32 Set<Integer> separators) {
33 super(context, R.layout.autofill_text, objects);
34 mSeparators = separators;
39 public View getView(int position, View convertView, ViewGroup parent) {
40 View layout = convertView;
41 if (convertView == null) {
42 LayoutInflater inflater =
43 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
44 layout = inflater.inflate(R.layout.autofill_text, null);
45 ApiCompatibilityUtils.setBackgroundForView(layout, new AutofillDividerDrawable());
47 TextView labelView = (TextView) layout.findViewById(R.id.autofill_label);
48 labelView.setText(getItem(position).mLabel);
50 AutofillDividerDrawable divider = (AutofillDividerDrawable) layout.getBackground();
51 int height = mContext.getResources().getDimensionPixelSize(R.dimen.autofill_text_height);
53 divider.setColor(Color.TRANSPARENT);
55 int dividerHeight = mContext.getResources().getDimensionPixelSize(
56 R.dimen.autofill_text_divider_height);
57 height += dividerHeight;
58 divider.setHeight(dividerHeight);
59 if (mSeparators.contains(position)) {
60 divider.setColor(mContext.getResources().getColor(
61 R.color.autofill_dark_divider_color));
63 divider.setColor(mContext.getResources().getColor(
64 R.color.autofill_divider_color));
67 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height));
69 TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sublabel);
70 CharSequence sublabel = getItem(position).mSublabel;
71 if (TextUtils.isEmpty(sublabel)) {
72 sublabelView.setVisibility(View.GONE);
74 sublabelView.setText(sublabel);
75 sublabelView.setVisibility(View.VISIBLE);