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

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

Issue 606153002: [android] Password generation UI for android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unify default text color. Use integers instead of enums. Simplify delegate. Created 6 years, 2 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/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();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698