Index: ui/android/java/src/org/chromium/ui/DropdownAdapter.java |
diff --git a/ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java |
similarity index 58% |
rename from ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java |
rename to ui/android/java/src/org/chromium/ui/DropdownAdapter.java |
index 94608af980270c8b4391044118bf88bb82b2c297..42fb11a76b4d785fb4176d29a667861294f5a48f 100644 |
--- a/ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java |
+++ b/ui/android/java/src/org/chromium/ui/DropdownAdapter.java |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-package org.chromium.ui.autofill; |
+package org.chromium.ui; |
import android.content.Context; |
import android.graphics.Color; |
@@ -15,24 +15,30 @@ import android.widget.ArrayAdapter; |
import android.widget.TextView; |
import org.chromium.base.ApiCompatibilityUtils; |
-import org.chromium.ui.R; |
-import java.util.ArrayList; |
+import java.util.List; |
import java.util.Set; |
/** |
- * Autofill suggestion adapter for AutofillWindow. |
+ * Dropdown item adapter for DropdownPopupWindow. |
*/ |
-public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { |
+public class DropdownAdapter extends ArrayAdapter<DropdownItem> { |
private Context mContext; |
private Set<Integer> mSeparators; |
+ private boolean mAreAllItemsEnabled; |
- AutofillListAdapter(Context context, |
- ArrayList<AutofillSuggestion> objects, |
- Set<Integer> separators) { |
- super(context, R.layout.autofill_text, objects); |
+ public DropdownAdapter(Context context, List<DropdownItem> items, Set<Integer> separators) { |
+ super(context, R.layout.dropdown_item, items); |
mSeparators = separators; |
mContext = context; |
+ |
+ mAreAllItemsEnabled = true; |
+ for (int i = 0; i < items.size(); i++) { |
+ if (items.get(i).isEnabled()) { |
+ mAreAllItemsEnabled = false; |
+ break; |
+ } |
+ } |
} |
@Override |
@@ -41,33 +47,36 @@ public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { |
if (convertView == null) { |
LayoutInflater inflater = |
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
- layout = inflater.inflate(R.layout.autofill_text, null); |
- ApiCompatibilityUtils.setBackgroundForView(layout, new AutofillDividerDrawable()); |
+ layout = inflater.inflate(R.layout.dropdown_item, null); |
+ ApiCompatibilityUtils.setBackgroundForView(layout, new DropdownDividerDrawable()); |
} |
- TextView labelView = (TextView) layout.findViewById(R.id.autofill_label); |
- labelView.setText(getItem(position).mLabel); |
- AutofillDividerDrawable divider = (AutofillDividerDrawable) layout.getBackground(); |
- int height = mContext.getResources().getDimensionPixelSize(R.dimen.autofill_text_height); |
+ DropdownItem item = getItem(position); |
+ |
+ TextView labelView = (TextView) layout.findViewById(R.id.dropdown_label); |
+ labelView.setText(item.getLabel()); |
+ |
+ DropdownDividerDrawable divider = (DropdownDividerDrawable) layout.getBackground(); |
+ int height = mContext.getResources().getDimensionPixelSize(R.dimen.dropdown_item_height); |
if (position == 0) { |
divider.setColor(Color.TRANSPARENT); |
} else { |
int dividerHeight = mContext.getResources().getDimensionPixelSize( |
- R.dimen.autofill_text_divider_height); |
+ R.dimen.dropdown_item_divider_height); |
height += dividerHeight; |
divider.setHeight(dividerHeight); |
- if (mSeparators.contains(position)) { |
+ if (mSeparators != null && mSeparators.contains(position)) { |
divider.setColor(mContext.getResources().getColor( |
- R.color.autofill_dark_divider_color)); |
+ R.color.dropdown_dark_divider_color)); |
} else { |
divider.setColor(mContext.getResources().getColor( |
- R.color.autofill_divider_color)); |
+ R.color.dropdown_divider_color)); |
} |
} |
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height)); |
- TextView sublabelView = (TextView) layout.findViewById(R.id.autofill_sublabel); |
- CharSequence sublabel = getItem(position).mSublabel; |
+ TextView sublabelView = (TextView) layout.findViewById(R.id.dropdown_sublabel); |
+ CharSequence sublabel = item.getSublabel(); |
if (TextUtils.isEmpty(sublabel)) { |
sublabelView.setVisibility(View.GONE); |
} else { |
@@ -77,4 +86,15 @@ public class AutofillListAdapter extends ArrayAdapter<AutofillSuggestion> { |
return layout; |
} |
+ |
+ @Override |
+ public boolean areAllItemsEnabled() { |
+ return mAreAllItemsEnabled; |
+ } |
+ |
+ @Override |
+ public boolean isEnabled(int position) { |
+ if (position < 0 || position >= getCount()) return false; |
+ return getItem(position).isEnabled(); |
+ } |
} |