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

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: Spellcheck comments. 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..c0f94a79e0d6fcd751906fc5f333c3a7d7688a7a
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopup.java
@@ -0,0 +1,156 @@
+// 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 shows the password suggestion.
+ */
+public class PasswordGenerationPopup extends DropdownPopupWindow
+ implements AdapterView.OnItemClickListener, PopupWindow.OnDismissListener {
+ private final Context mContext;
+ private final Delegate mDelegate;
+
+ /**
+ * An interface to describe the state of the popup and handle the touch interaction with a
+ * 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();
+
+ /**
+ * Returns true if the popup is RTL.
+ */
+ public boolean isRtl();
+
+ /**
+ * Returns the minimum width for the popup.
+ */
+ public int getMinimumWidth();
+
+ /**
+ * If true, then the generated password should be displayed.
+ */
+ public boolean isPasswordDisplayed();
+
+ /**
+ * Returns the suggested auto-generated password.
+ */
+ public String getPassword();
+
+ /**
+ * Returns the translated text for the title of the popup.
+ */
+ public String getSuggestionTitle();
+
+ /**
+ * Returns the translated text for the explanation of the popup.
+ */
+ public String getExplanationText();
+
+ /**
+ * Returns the start of the range in the explanation text that should be a link to the saved
+ * passwords.
+ */
+ public int getExplanationTextLinkRangeStart();
+
+ /**
+ * Returns the end of the range in the explanation text that should be a link to the saved
+ * passwords.
+ */
+ public int getExplanationTextLinkRangeEnd();
+ }
+
+ /**
+ * The types of UI that can be displayed.
+ */
+ public enum PasswordGenerationView {
aurimas (slooooooooow) 2014/10/16 01:40:18 Using enums in Java is expensive. Change to using
please use gerrit instead 2014/10/16 03:31:33 Done. I've made them public static final. I've see
+ /**
+ * UI shows a generated password suggestion.
+ */
+ SUGGESTION,
+
+ /**
+ * UI shows an explanation about storing passwords in Chrome.
+ */
+ EXPLANATION,
+ }
+
+ /**
+ * 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,
+ * depending on the data in the delegate.
+ */
+ @Override
+ public void show() {
+ List<PasswordGenerationView> views = new ArrayList<PasswordGenerationView>();
+ if (mDelegate.isPasswordDisplayed()) {
+ views.add(PasswordGenerationView.SUGGESTION);
+ }
+ views.add(PasswordGenerationView.EXPLANATION);
+ setAdapter(new PasswordGenerationAdapter(mContext, views, mDelegate));
+ super.setRtl(mDelegate.isRtl());
+ super.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