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. |
4 | |
5 | |
6 | package org.chromium.ui.autofill; |
7 | |
8 | import android.content.Context; |
9 | import android.text.TextUtils; |
10 | |
11 | import android.view.LayoutInflater; |
12 | import android.view.View; |
13 | import android.view.ViewGroup; |
14 | import android.widget.ArrayAdapter; |
15 | import android.widget.TextView; |
16 | |
17 | import org.chromium.ui.R; |
18 | |
19 | import java.util.ArrayList; |
20 | |
21 | /** |
22 | * Autofill suggestion adapter for AutofillWindow. |
23 | */ |
24 | public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { |
25 | private Context mContext; |
26 | |
27 | AutofillListAdapter(Context context, ArrayList<AutofillSuggestion> objects) { |
28 | super(context, R.layout.autofill_text, objects); |
29 | mContext = context; |
30 | } |
31 | |
32 | @Override |
33 | public View getView(int position, View convertView, ViewGroup parent) { |
34 | View layout = convertView; |
35 | if (convertView == null) { |
36 | LayoutInflater inflater = |
37 | (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
38 | layout = inflater.inflate(R.layout.autofill_text, null); |
39 | } |
40 | TextView labelView = (TextView) layout.findViewById(R.id.autofill_label); |
41 | labelView.setText(getItem(position).mLabel); |
42 | |
43 | TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sublabel); |
44 | CharSequence sublabel = getItem(position).mSublabel; |
45 | if (TextUtils.isEmpty(sublabel)) { |
46 | sublabelView.setVisibility(View.GONE); |
47 | } else { |
48 | sublabelView.setText(sublabel); |
49 | sublabelView.setVisibility(View.VISIBLE); |
50 | } |
51 | |
52 | return layout; |
53 | } |
54 | } |