| 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..636477b60a0c6cd0a43ac86a01cd8cc8b52f55bb
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationAdapter.java
|
| @@ -0,0 +1,140 @@
|
| +// 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<PasswordGenerationPopup.PasswordGenerationView> {
|
| + private Context mContext;
|
| + private PasswordGenerationPopup.Delegate mDelegate;
|
| + 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<PasswordGenerationPopup.PasswordGenerationView> views,
|
| + PasswordGenerationPopup.Delegate delegate) {
|
| + super(context, R.layout.password_generation_popup, views);
|
| +
|
| + mContext = context;
|
| + mDelegate = delegate;
|
| +
|
| + mExplanationSpan = new SpannableString(mDelegate.getExplanationText());
|
| + mExplanationSpan.setSpan(
|
| + new ClickableSpan() {
|
| + @Override
|
| + public void onClick(View view) {
|
| + mDelegate.onSavedPasswordsLinkClicked();
|
| + }
|
| + @Override
|
| + public void updateDrawState(TextPaint textPaint) {
|
| + textPaint.setUnderlineText(false);
|
| + textPaint.setColor(mContext.getResources().getColor(
|
| + R.color.password_generation_link_text_color));
|
| + }
|
| + },
|
| + mDelegate.getExplanationTextLinkRangeStart(),
|
| + mDelegate.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(mDelegate.getSuggestionTitle());
|
| + password.setText(mDelegate.getPassword());
|
| + explanation.setText(mExplanationSpan);
|
| + explanation.setMovementMethod(LinkMovementMethod.getInstance());
|
| +
|
| + suggestion.setMinimumWidth(mDelegate.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));
|
| +
|
| + PasswordGenerationPopup.PasswordGenerationView view = getItem(position);
|
| + switch (view) {
|
| + case SUGGESTION:
|
| + suggestion.setVisibility(View.VISIBLE);
|
| + divider.setVisibility(View.VISIBLE);
|
| + explanation.setVisibility(View.GONE);
|
| + break;
|
| +
|
| + case 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) {
|
| + PasswordGenerationPopup.PasswordGenerationView view = getItem(position);
|
| + return view == PasswordGenerationPopup.PasswordGenerationView.SUGGESTION;
|
| + }
|
| +}
|
|
|