Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java |
| diff --git a/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java b/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java |
| index 0483b0272154afacca5c57178f3403e240c8b2bb..4c5a5abd34ae413d9b9d461a46987cb482e27323 100644 |
| --- a/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java |
| +++ b/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java |
| @@ -16,6 +16,9 @@ import android.widget.ListPopupWindow; |
| import android.widget.TextView; |
| import java.util.ArrayList; |
| +import java.util.Arrays; |
| +import java.util.HashSet; |
| +import java.util.List; |
| import org.chromium.ui.R; |
| import org.chromium.ui.ViewAndroidDelegate; |
| @@ -29,11 +32,12 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem |
| * Constants defining types of Autofill suggestion entries. |
| * Has to be kept in sync with enum in WebAutofillClient.h |
| * |
| - * Not supported: MenuItemIDWarningMessage, MenuItemIDSeparator, MenuItemIDClearForm, and |
| + * Not supported: MenuItemIDWarningMessage, MenuItemIDClearForm, and |
| * MenuItemIDAutofillOptions. |
| */ |
| private static final int ITEM_ID_AUTOCOMPLETE_ENTRY = 0; |
| private static final int ITEM_ID_PASSWORD_ENTRY = -2; |
| + private static final int ITEM_ID_SEPARATOR_ENTRY = -3; |
| private static final int ITEM_ID_DATA_LIST_ENTRY = -6; |
| private static final int TEXT_PADDING_DP = 30; |
| @@ -49,6 +53,7 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem |
| private Paint mLabelViewPaint; |
| private Paint mSublabelViewPaint; |
| private OnLayoutChangeListener mLayoutChangeListener; |
| + private List<AutofillSuggestion> mSuggestions; |
| /** |
| * An interface to handle the touch interaction with an AutofillPopup object. |
| @@ -105,6 +110,7 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem |
| // An ugly hack to keep the popup from expanding on top of the keyboard. |
| setInputMethodMode(INPUT_METHOD_NEEDED); |
| super.show(); |
| + getListView().setDividerHeight(0); |
|
newt (away)
2013/09/09 20:20:42
should this live in the constructor instead?
keishi
2013/09/10 09:19:56
I've tried and getListView() returns null in the c
newt (away)
2013/09/10 17:45:10
ah, the ListView probably isn't constructed until
|
| } |
| /** |
| @@ -131,16 +137,20 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem |
| * @param suggestions Autofill suggestion data. |
| */ |
| public void show(AutofillSuggestion[] suggestions) { |
| + mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestions)); |
| // Remove the AutofillSuggestions with IDs that are not supported by Android |
| ArrayList<AutofillSuggestion> cleanedData = new ArrayList<AutofillSuggestion>(); |
| + HashSet<Integer> separators = new HashSet<Integer>(); |
| for (int i = 0; i < suggestions.length; i++) { |
| int itemId = suggestions[i].mUniqueId; |
| if (itemId > 0 || itemId == ITEM_ID_AUTOCOMPLETE_ENTRY || |
| itemId == ITEM_ID_PASSWORD_ENTRY || itemId == ITEM_ID_DATA_LIST_ENTRY) { |
| cleanedData.add(suggestions[i]); |
| + } else if (itemId == ITEM_ID_SEPARATOR_ENTRY) { |
| + separators.add(cleanedData.size()); |
| } |
| } |
| - setAdapter(new AutofillListAdapter(mContext, cleanedData)); |
| + setAdapter(new AutofillListAdapter(mContext, cleanedData, separators)); |
| // Once the mAnchorRect is resized and placed correctly, it will show the Autofill popup. |
| mAnchorWidth = Math.max(getDesiredWidth(cleanedData), mAnchorWidth); |
| mViewAndroidDelegate.setAnchorViewPosition(mAnchorView, mAnchorX, mAnchorY, mAnchorWidth, |
| @@ -208,7 +218,9 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem |
| @Override |
| public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| - mAutofillCallback.suggestionSelected(position); |
| + AutofillListAdapter adapter = (AutofillListAdapter)parent.getAdapter(); |
|
newt (away)
2013/09/09 20:20:42
space after cast
keishi
2013/09/19 11:53:05
Done.
|
| + int listIndex = mSuggestions.indexOf(adapter.getItem(position)); |
|
newt (away)
2013/09/09 20:20:42
could this ever return -1? I'd handle that case, i
keishi
2013/09/19 11:53:05
It shouldn't return -1. Added an assertion.
|
| + mAutofillCallback.suggestionSelected(listIndex); |
| } |
| } |