Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopup.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopup.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopup.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dd5018689daec3f468c106045fa1b8562321d911 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopup.java |
@@ -0,0 +1,107 @@ |
+// 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 android.content.Context; |
+import android.view.View; |
+import android.widget.AdapterView; |
+import android.widget.PopupWindow; |
+ |
+import org.chromium.ui.DropdownPopupWindow; |
+import org.chromium.ui.base.ViewAndroidDelegate; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+/** |
+ * The password generation popup that suggests an auto-generated password. |
+ */ |
+public class PasswordGenerationPopup extends DropdownPopupWindow |
+ implements AdapterView.OnItemClickListener, PopupWindow.OnDismissListener { |
+ private final Context mContext; |
+ private final Delegate mDelegate; |
+ |
+ /** |
+ * Handles touch interaction with the password generation popup. |
+ */ |
+ public interface Delegate { |
+ /** |
+ * Opens the "saved passwords" link. |
+ */ |
+ public void onSavedPasswordsLinkClicked(); |
+ |
+ /** |
+ * Informs the controller that the popup was hidden. |
+ */ |
+ public void onDismissed(); |
+ |
+ /** |
+ * Handles the selection of the suggested password in the popup. |
+ */ |
+ public void onPasswordSelected(); |
+ } |
+ |
+ /** |
+ * UI shows a generated password suggestion. |
+ */ |
+ public static final int SUGGESTION = 0; |
+ |
+ /** |
+ * UI shows an explanation about storing passwords in Chrome. |
+ */ |
+ public static final int EXPLANATION = 1; |
+ |
+ /** |
+ * Builds the password generation popup with data and behavior determined by the delegate. |
+ * @param context Android context. |
+ * @param viewAndroidDelegate View delegate used to add and remove views. |
+ * @param delegate Describes data in the popup and handles touch interactions. |
+ */ |
+ public PasswordGenerationPopup(Context context, ViewAndroidDelegate viewAndroidDelegate, |
+ Delegate delegate) { |
+ super(context, viewAndroidDelegate); |
+ mContext = context; |
+ mDelegate = delegate; |
+ |
+ setOnItemClickListener(this); |
+ setOnDismissListener(this); |
+ } |
+ |
+ /** |
+ * Shows the password generation popup. The popup will be in either suggestion or editing mode. |
+ * @param passwordGeneration Describes the state of the popup to show. |
+ */ |
+ public void show(PasswordGeneration passwordGeneration) { |
+ List<Integer> views = new ArrayList<Integer>(); |
+ if (passwordGeneration.isPasswordDisplayed()) { |
+ views.add(SUGGESTION); |
+ } |
+ views.add(EXPLANATION); |
+ setAdapter(new PasswordGenerationAdapter(mContext, views, passwordGeneration, mDelegate)); |
+ setRtl(passwordGeneration.isRtl()); |
+ show(); |
+ } |
+ |
+ /** |
+ * Handles clicks on popup list elements. Only suggestion element is enabled. Clicking on the |
+ * suggestion element notifies the delegate that the suggested password was selected. |
+ * @param parent The parent view where the click happened. |
+ * @param view The view that was provided by the adapter that was clicked. |
+ * @param position The position of the view in the adapter. |
+ * @param id The row id of the clicked element. |
+ */ |
+ @Override |
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
+ mDelegate.onPasswordSelected(); |
+ } |
+ |
+ /** |
+ * Handles dismissing the popup window. The delegate is notified to destroy the controller. |
+ */ |
+ @Override |
+ public void onDismiss() { |
+ mDelegate.onDismissed(); |
+ } |
+} |