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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryBridge.java

Issue 1082183002: Android - Introduce "keyboard accessory" for Autofill suggestions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more dtrainor review 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: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..452feed3f0fda6eb7df1f5a61182e8ac54cd3701
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillKeyboardAccessoryBridge.java
@@ -0,0 +1,116 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.autofill;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.chrome.browser.ResourceId;
+import org.chromium.ui.DropdownItem;
+import org.chromium.ui.autofill.AutofillKeyboardAccessory;
+import org.chromium.ui.autofill.AutofillKeyboardAccessory.AutofillKeyboardAccessoryDelegate;
+import org.chromium.ui.autofill.AutofillSuggestion;
+import org.chromium.ui.base.WindowAndroid;
+
+/**
+* JNI call glue for AutofillExternalDelagate C++ and Java objects.
+* This provides an alternative UI for Autofill suggestions, and replaces AutofillPopupBridge when
+* --enable-autofill-keyboard-accessory-view is passed on the command line.
+*/
+@JNINamespace("autofill")
+public class AutofillKeyboardAccessoryBridge implements AutofillKeyboardAccessoryDelegate {
+ private long mNativeAutofillKeyboardAccessory;
+ private AutofillKeyboardAccessory mAccessoryView;
+
+ public AutofillKeyboardAccessoryBridge() {
newt (away) 2015/04/24 17:45:11 It appears this should be private.
Evan Stade 2015/04/24 21:19:18 Done.
+ }
+
+ @CalledByNative
+ private static AutofillKeyboardAccessoryBridge create() {
+ return new AutofillKeyboardAccessoryBridge();
+ }
+
+ @Override
+ public void dismissed() {
+ if (mNativeAutofillKeyboardAccessory == 0) return;
+ nativeViewDismissed(mNativeAutofillKeyboardAccessory);
+ }
+
+ @Override
+ public void suggestionSelected(int listIndex) {
+ if (mNativeAutofillKeyboardAccessory == 0) return;
+ nativeSuggestionSelected(mNativeAutofillKeyboardAccessory, listIndex);
+ }
+
+ /**
+ * Initializes this object.
+ * This function should be called at most one time.
+ * @param nativeAutofillKeyboardAccessory Handle to the native counterpart.
+ * @param windowAndroid The window on which to show the suggestions.
+ */
+ @CalledByNative
+ public void init(long nativeAutofillKeyboardAccessory, WindowAndroid windowAndroid) {
newt (away) 2015/04/24 17:45:12 can this be private?
Evan Stade 2015/04/24 21:19:18 Done.
+ if (windowAndroid == null || windowAndroid.getActivity().get() == null) {
+ nativeViewDismissed(nativeAutofillKeyboardAccessory);
+ dismissed();
+ return;
+ }
+
+ mNativeAutofillKeyboardAccessory = nativeAutofillKeyboardAccessory;
+ mAccessoryView = new AutofillKeyboardAccessory(windowAndroid, this);
+ }
+
+ /**
+ * Clears the reference to the native view.
+ */
+ @CalledByNative
+ private void nativeViewDestroyed() {
Evan Stade 2015/04/24 21:19:18 also changed the name of this because native* is u
+ mNativeAutofillKeyboardAccessory = 0;
+ }
+
+ /**
+ * Hides the Autofill view.
+ */
+ @CalledByNative
+ private void dismiss() {
+ if (mAccessoryView != null) mAccessoryView.dismiss();
+ }
+
+ /**
+ * Shows an Autofill view with specified suggestions.
+ * @param suggestions Autofill suggestions to be displayed.
+ */
+ @CalledByNative
+ private void show(AutofillSuggestion[] suggestions, boolean isRtl) {
+ if (mAccessoryView != null) mAccessoryView.filterAndShow(suggestions, isRtl);
+ }
+
+ // Helper methods for AutofillSuggestion. These are copied from AutofillPopupBridge (which
+ // should
+ // eventually disappear).
+
+ @CalledByNative
+ private static AutofillSuggestion[] createAutofillSuggestionArray(int size) {
+ return new AutofillSuggestion[size];
+ }
+
+ /**
+ * @param array AutofillSuggestion array that should get a new suggestion added.
+ * @param index Index in the array where to place a new suggestion.
+ * @param label First line of the suggestion.
+ * @param sublabel Second line of the suggestion.
+ * @param iconId The resource ID for the icon associated with the suggestion, or 0 for no icon.
+ * @param suggestionId Identifier for the suggestion type.
+ */
+ @CalledByNative
+ private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
+ String label, String sublabel, int iconId, int suggestionId) {
+ int drawableId = iconId == 0 ? DropdownItem.NO_ICON : ResourceId.mapToDrawableId(iconId);
+ array[index] = new AutofillSuggestion(label, sublabel, drawableId, suggestionId);
+ }
+
+ private native void nativeViewDismissed(long nativeAutofillKeyboardAccessoryView);
+ private native void nativeSuggestionSelected(
+ long nativeAutofillKeyboardAccessoryView, int listIndex);
+}

Powered by Google App Engine
This is Rietveld 408576698