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

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

Issue 1082183002: Android - Introduce "keyboard accessory" for Autofill suggestions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 8 months 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
Index: ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java
diff --git a/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java b/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java
new file mode 100644
index 0000000000000000000000000000000000000000..90934af98d9087fde24c3c3e6aa00f8aea81bdbd
--- /dev/null
+++ b/ui/android/java/src/org/chromium/ui/autofill/AutofillKeyboardAccessory.java
@@ -0,0 +1,132 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
David Trainor- moved to gerrit 2015/04/20 23:29:43 2015
Evan Stade 2015/04/21 00:48:51 Done.
+// 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;
+
+import android.annotation.SuppressLint;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
+import android.widget.AdapterView;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.ui.DropdownAdapter;
+import org.chromium.ui.DropdownItem;
+import org.chromium.ui.R;
+import org.chromium.ui.base.WindowAndroid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+/**
+ * The Autofill suggestion view that lists relevant suggestions.
+ */
+public class AutofillKeyboardAccessory extends ListView implements AdapterView.OnItemClickListener {
+ /**
+ * The constant used to specify a separator in a list of Autofill suggestions.
+ * Has to be kept in sync with enum in WebAutofillClient.h
David Trainor- moved to gerrit 2015/04/20 23:29:43 Should we add a gyp target to build the Java enum
Evan Stade 2015/04/21 00:48:51 mehhh
David Trainor- moved to gerrit 2015/04/21 06:55:47 Haha I'm not sure your argument convinced me! I'l
Evan Stade 2015/04/21 18:10:30 OK, I looked at doing this. This file is in ui/ (b
David Trainor- moved to gerrit 2015/04/21 21:02:31 Okay in that case I'm fine with this for now. Tha
+ */
+ private static final int ITEM_ID_SEPARATOR_ENTRY = -3;
+
+ private final WindowAndroid mWindowAndroid;
+ private final AutofillKeyboardAccessoryDelegate mAutofillCallback;
+ private List<AutofillSuggestion> mSuggestions;
+
+ /**
+ * An interface to handle the touch interaction with an AutofillKeyboardAccessory object.
+ */
+ public interface AutofillKeyboardAccessoryDelegate {
+ /**
+ * Informs the controller the AutofillKeyboardAccessory was hidden.
+ */
+ public void dismissed();
+
+ /**
+ * Handles the selection of an Autofill suggestion from an AutofillKeyboardAccessory.
+ * @param listIndex The index of the selected Autofill suggestion.
+ */
+ public void suggestionSelected(int listIndex);
+ }
+
+ /**
+ * Creates an AutofillKeyboardAccessory with specified parameters.
+ * @param windowAndroid The owning WindowAndroid.
+ * @param autofillCallback A object that handles the calls to the native
+ * AutofillKeyboardAccessoryView.
+ */
+ public AutofillKeyboardAccessory(
+ WindowAndroid windowAndroid, AutofillKeyboardAccessoryDelegate autofillCallback) {
David Trainor- moved to gerrit 2015/04/20 23:29:43 assert autofillCallback != null?
Evan Stade 2015/04/21 00:48:51 Done.
+ super(windowAndroid.getActivity().get());
+ mWindowAndroid = windowAndroid;
+ mAutofillCallback = autofillCallback;
+
+ setBackgroundResource(R.drawable.autofill_accessory_view_border);
+ setOnItemClickListener(this);
+ setContentDescription(windowAndroid.getActivity().get().getString(
+ R.string.autofill_popup_content_description));
+ }
+
+ /**
+ * Filters the Autofill suggestions to the ones that we support and shows the popup.
+ * @param suggestions Autofill suggestion data.
+ * @param isRtl Gives the layout direction for the <input> field.
+ */
+ @SuppressLint("InlinedApi")
+ public void filterAndShow(AutofillSuggestion[] suggestions, boolean isRtl) {
+ mSuggestions = new ArrayList<AutofillSuggestion>(Arrays.asList(suggestions));
+ // Remove the AutofillSuggestions with IDs that are not supported by Android
+ ArrayList<DropdownItem> cleanedData = new ArrayList<DropdownItem>();
+ for (int i = 0; i < suggestions.length; i++) {
+ int itemId = suggestions[i].getSuggestionId();
+ if (itemId != ITEM_ID_SEPARATOR_ENTRY) {
+ cleanedData.add(suggestions[i]);
+ }
+ }
+
+ setAdapter(new DropdownAdapter(
+ mWindowAndroid.getActivity().get(), cleanedData, new HashSet<Integer>()));
+ ApiCompatibilityUtils.setLayoutDirection(
+ this, isRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
+
+ int height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ // Limit the visible number of suggestions (others are accessible via scrolling).
+ final int suggestionLimit = 2;
+ ListAdapter listAdapter = getAdapter();
+ if (listAdapter.getCount() > suggestionLimit) {
+ height = 0;
+ for (int i = 0; i < suggestionLimit; i++) {
+ View listItem = listAdapter.getView(i, null, this);
+ listItem.measure(0, 0);
David Trainor- moved to gerrit 2015/04/20 23:29:43 Should we make a proper widthMeasureSpec and heigh
Evan Stade 2015/04/21 00:48:51 I prefer to avoid adding complexity for the sake o
David Trainor- moved to gerrit 2015/04/21 06:55:47 I don't think changing it adds complexity. I thin
Evan Stade 2015/04/21 18:10:30 Done.
+ height += listItem.getMeasuredHeight();
+ }
+ }
+
+ setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
+
+ if (getParent() == null) {
+ ViewGroup container = mWindowAndroid.getKeyboardAccessoryView();
+ container.addView(this);
+ container.setVisibility(View.VISIBLE);
David Trainor- moved to gerrit 2015/04/20 23:29:43 Do we need to set visibility?
Evan Stade 2015/04/21 00:48:51 it's possible that we could just leave it visible
David Trainor- moved to gerrit 2015/04/21 06:55:47 Oh sorry I misread what you were setting visibilit
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+ }
+ }
+
+ public void dismiss() {
David Trainor- moved to gerrit 2015/04/20 23:29:43 Javadoc
Evan Stade 2015/04/21 18:10:30 Done.
+ ViewGroup container = mWindowAndroid.getKeyboardAccessoryView();
+ container.removeView(this);
+ container.setVisibility(View.GONE);
David Trainor- moved to gerrit 2015/04/20 23:29:43 Do we need to set visibility?
Evan Stade 2015/04/21 00:48:52 Done.
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ DropdownAdapter adapter = (DropdownAdapter) parent.getAdapter();
+ int listIndex = mSuggestions.indexOf(adapter.getItem(position));
+ assert listIndex > -1;
+ mAutofillCallback.suggestionSelected(listIndex);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698