Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java

Issue 23314003: Add support for datalist to text input element on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1612f0b15bb5902172d90553450e1d2191749d3b 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);
}
/**
@@ -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,10 @@ 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();
+ int listIndex = mSuggestions.indexOf(adapter.getItem(position));
+ assert listIndex > -1;
+ mAutofillCallback.suggestionSelected(listIndex);
}
}
« no previous file with comments | « ui/android/java/src/org/chromium/ui/autofill/AutofillListAdapter.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698