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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationAdapter.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/PasswordGenerationAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..2d9f9c181786e1e83ab9eab122365deda25b5e9f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationAdapter.java
@@ -0,0 +1,136 @@
+// 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.text.SpannableString;
+import android.text.Spanned;
+import android.text.TextPaint;
+import android.text.method.LinkMovementMethod;
+import android.text.style.ClickableSpan;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.RelativeLayout.LayoutParams;
+import android.widget.TextView;
+
+import org.chromium.chrome.R;
+
+import java.util.List;
+
+/**
+ * The adapter that populates the list popup for password generation with data.
+ */
+public class PasswordGenerationAdapter extends ArrayAdapter<Integer> {
+ private Context mContext;
+ private PasswordGeneration mPasswordGeneration;
+ private SpannableString mExplanationSpan;
+
+ /**
+ * Builds the adapter to display views using data from delegate.
+ * @param context Android context.
+ * @param views The types of views to display in the list popup.
+ * @param delegate The data to be populated in the list popup.
+ */
+ public PasswordGenerationAdapter(Context context, List<Integer> views,
+ PasswordGeneration passwordGeneration,
+ final PasswordGenerationPopup.Delegate delegate) {
+ super(context, R.layout.password_generation_popup, views);
+ mContext = context;
+ mPasswordGeneration = passwordGeneration;
+
+ mExplanationSpan = new SpannableString(mPasswordGeneration.getExplanationText());
+ mExplanationSpan.setSpan(
+ new ClickableSpan() {
+ @Override
+ public void onClick(View view) {
+ delegate.onSavedPasswordsLinkClicked();
+ }
+ @Override
+ public void updateDrawState(TextPaint textPaint) {
+ textPaint.setUnderlineText(false);
+ textPaint.setColor(mContext.getResources().getColor(
+ R.color.password_generation_link_text_color));
+ }
+ },
+ mPasswordGeneration.getExplanationTextLinkRangeStart(),
+ mPasswordGeneration.getExplanationTextLinkRangeEnd(),
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ /**
+ * Used by list popup window to draw an element.
+ * @param position The position of the element in the popup list.
+ * @param convertView If not null, the element view where the data goes.
+ * @param parent The list popup.
+ * @return The view of the popup list element at the given position.
+ */
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View layout = convertView;
+ if (convertView == null) {
+ LayoutInflater inflater =
+ (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ layout = inflater.inflate(R.layout.password_generation_popup, null);
+ }
+
+ View suggestion = layout.findViewById(R.id.password_generation_suggestion);
+ TextView title = (TextView) layout.findViewById(R.id.password_generation_title);
+ TextView password = (TextView) layout.findViewById(R.id.password_generation_password);
+ View divider = layout.findViewById(R.id.password_generation_divider);
+ TextView explanation = (TextView) layout.findViewById(R.id.password_generation_explanation);
+
+ title.setText(mPasswordGeneration.getSuggestionTitle());
+ password.setText(mPasswordGeneration.getPassword());
+ explanation.setText(mExplanationSpan);
+ explanation.setMovementMethod(LinkMovementMethod.getInstance());
+
+ suggestion.setMinimumWidth(mPasswordGeneration.getMinimumWidth());
+ suggestion.setVisibility(View.VISIBLE);
+ divider.setVisibility(View.VISIBLE);
+ explanation.setVisibility(View.VISIBLE);
+ suggestion.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ explanation.setLayoutParams(
+ new LayoutParams(suggestion.getMeasuredWidth(), LayoutParams.WRAP_CONTENT));
+
+ switch (getItem(position)) {
+ case PasswordGenerationPopup.SUGGESTION:
+ suggestion.setVisibility(View.VISIBLE);
+ divider.setVisibility(View.VISIBLE);
+ explanation.setVisibility(View.GONE);
+ break;
+
+ case PasswordGenerationPopup.EXPLANATION:
+ suggestion.setVisibility(View.GONE);
+ divider.setVisibility(View.GONE);
+ explanation.setVisibility(View.VISIBLE);
+ break;
+ }
+
+ return layout;
+ }
+
+ /**
+ * Used by list popup window to check if all of the elements are enabled. All password
+ * generation popups have an explanation element, which is not selectable. Therefore, this
+ * method always returns false: some of the items are disabled.
+ * @return boolean Always false.
+ */
+ @Override
+ public boolean areAllItemsEnabled() {
+ return false;
+ }
+
+ /**
+ * Used by list popup window to check if the element at this position is enabled. Only the
+ * suggestion element is enabled.
+ * @return boolean True if the view at position is a suggestion.
+ */
+ @Override
+ public boolean isEnabled(int position) {
+ return getItem(position) == PasswordGenerationPopup.SUGGESTION;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698