Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 19 import java.util.ArrayList; | 22 import java.util.ArrayList; |
| 23 import java.util.Set; | |
| 20 | 24 |
| 21 /** | 25 /** |
| 22 * Autofill suggestion adapter for AutofillWindow. | 26 * Autofill suggestion adapter for AutofillWindow. |
| 23 */ | 27 */ |
| 24 public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { | 28 public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { |
| 25 private Context mContext; | 29 private Context mContext; |
| 30 private Set<Integer> mSeparators; | |
| 26 | 31 |
| 27 AutofillListAdapter(Context context, ArrayList<AutofillSuggestion> objects) { | 32 AutofillListAdapter(Context context, |
| 33 ArrayList<AutofillSuggestion> objects, | |
| 34 Set<Integer> separators) { | |
| 28 super(context, R.layout.autofill_text, objects); | 35 super(context, R.layout.autofill_text, objects); |
| 36 mSeparators = separators; | |
| 29 mContext = context; | 37 mContext = context; |
| 30 } | 38 } |
| 31 | 39 |
| 32 @Override | 40 @Override |
| 33 public View getView(int position, View convertView, ViewGroup parent) { | 41 public View getView(int position, View convertView, ViewGroup parent) { |
| 34 View layout = convertView; | 42 View layout = convertView; |
| 35 if (convertView == null) { | 43 if (convertView == null) { |
| 36 LayoutInflater inflater = | 44 LayoutInflater inflater = |
| 37 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); | 45 (LayoutInflater) mContext.getSystemService(Context.LAYOUT_IN FLATER_SERVICE); |
| 38 layout = inflater.inflate(R.layout.autofill_text, null); | 46 layout = inflater.inflate(R.layout.autofill_text, null); |
| 47 layout.setBackground(new AutofillDividerDrawable()); | |
| 39 } | 48 } |
| 40 TextView labelView = (TextView) layout.findViewById(R.id.autofill_label) ; | 49 TextView labelView = (TextView) layout.findViewById(R.id.autofill_label) ; |
| 41 labelView.setText(getItem(position).mLabel); | 50 labelView.setText(getItem(position).mLabel); |
| 42 | 51 |
| 52 AutofillDividerDrawable divider = (AutofillDividerDrawable) layout.getBa ckground(); | |
| 53 int height = mContext.getResources().getDimensionPixelSize(R.dimen.autof ill_text_height); | |
| 54 if (position == 0) { | |
| 55 divider.setColor(Color.TRANSPARENT); | |
| 56 } else { | |
| 57 int dividerHeight = mContext.getResources().getDimensionPixelSize( | |
| 58 R.dimen.autofill_text_divider_height); | |
| 59 height += dividerHeight; | |
| 60 divider.setHeight(dividerHeight); | |
| 61 if (mSeparators.contains(position)) { | |
|
newt (away)
2013/10/03 16:34:51
do you want the same divider height for dark divid
keishi
2013/10/04 05:52:28
Yes. Same height just darker color.
| |
| 62 divider.setColor(mContext.getResources().getColor( | |
| 63 R.color.autofill_dark_divider_color)); | |
| 64 } else { | |
| 65 divider.setColor(mContext.getResources().getColor( | |
| 66 R.color.autofill_divider_color)); | |
| 67 } | |
| 68 } | |
| 69 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, heigh t)); | |
| 70 | |
| 43 TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sub label); | 71 TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sub label); |
| 44 CharSequence sublabel = getItem(position).mSublabel; | 72 CharSequence sublabel = getItem(position).mSublabel; |
| 45 if (TextUtils.isEmpty(sublabel)) { | 73 if (TextUtils.isEmpty(sublabel)) { |
| 46 sublabelView.setVisibility(View.GONE); | 74 sublabelView.setVisibility(View.GONE); |
| 47 } else { | 75 } else { |
| 48 sublabelView.setText(sublabel); | 76 sublabelView.setText(sublabel); |
| 49 sublabelView.setVisibility(View.VISIBLE); | 77 sublabelView.setVisibility(View.VISIBLE); |
| 50 } | 78 } |
| 51 | 79 |
| 52 return layout; | 80 return layout; |
| 53 } | 81 } |
| 54 } | 82 } |
| OLD | NEW |