Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBar.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..71a2ed3ed702523dd3819421134bb32ceed79f4c |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBar.java |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2016 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.infobar; |
| + |
| +import android.graphics.Bitmap; |
| +import android.text.SpannableString; |
| +import android.text.Spanned; |
| +import android.text.style.ClickableSpan; |
| +import android.view.View; |
| + |
| +import java.util.LinkedList; |
| +import java.util.List; |
| + |
| +/** |
| + * An infobar for saving credit card information. |
| + */ |
| +public class AutofillCCInfoBar extends ConfirmInfoBar { |
| + /** |
| + * Detailed card information to show in the infobar. |
| + */ |
| + public static class CardDetail { |
| + /** |
| + * The identifier of the drawable of the card issuer icon. |
| + */ |
| + public int issuerIconDrawableId; |
| + |
| + /** |
| + * The label for the card. |
| + */ |
| + public String label; |
| + |
| + /** |
| + * The sub-label for the card. |
| + */ |
| + public String subLabel; |
| + } |
| + |
| + /** |
| + * Legal message line with links to show in the infobar. |
| + */ |
| + public static class LegalMessageLine { |
| + /** |
| + * A link in the legal message line. |
| + */ |
| + public static class Link { |
| + /** |
| + * The starting inclusive index of the link position in the text. |
| + */ |
| + public int start; |
| + |
| + /** |
| + * The ending inclusive index of the link position in the text. |
| + */ |
| + public int end; |
| + |
| + /** |
| + * The URL of the link. |
| + */ |
| + public String url; |
| + } |
| + |
| + /** |
| + * The plain text legal message line. |
| + */ |
| + public String text; |
| + |
| + /** |
| + * A collection of links in the legal message line. |
| + */ |
| + public LinkedList<Link> links; |
| + } |
| + |
| + /** |
| + * An interface to be implemented by objects that wish to be notified of clicks on the links in |
| + * the legal message text. |
| + */ |
| + public interface LegalMessageLinkClickDelegate { |
| + /** |
| + * Called when a link in the legal message text was clicked. |
| + * @param url The URL of the clicked link. |
| + */ |
| + public void onLegalMessageLinkClicked(String url); |
| + } |
| + |
| + private final List<CardDetail> mCardDetails; |
| + private final List<LegalMessageLine> mLegalMessageLines; |
| + private final LegalMessageLinkClickDelegate mDelegate; |
| + |
| + /** |
| + * Creates an infobar for saving a credit card. |
| + * @param iconDrawableId Resource ID for the icon that will be shown for the InfoBar. |
| + * @param iconBitmap Bitmap to use if there is no equivalent Java resource for enumeratedIconId. |
| + * @param message Message to display to the user indicating what the InfoBar is for. |
| + * @param linkText Link text to display in addition to the message. |
| + * @param details Card details to show in the Infobar. |
| + * @param legalMessageLines Legal message lines to show in the InfoBar. |
| + * @param primaryButtonText String to display on the primary button. |
| + * @param secondaryButtonText String to display on the secondary button. |
| + * @param delegate The delegate to be notified of clicks on the links in the legal message text. |
| + */ |
| + public AutofillCCInfoBar(int iconDrawableId, Bitmap iconBitmap, String message, String linkText, |
| + List<CardDetail> details, List<LegalMessageLine> legalMessageLines, |
| + String primaryButtonText, String secondaryButtonText, |
| + LegalMessageLinkClickDelegate delegate) { |
| + super(null, iconDrawableId, iconBitmap, message, linkText, primaryButtonText, |
| + secondaryButtonText); |
| + mCardDetails = details; |
| + mLegalMessageLines = legalMessageLines; |
| + mDelegate = delegate; |
| + } |
| + |
| + /** |
| + * @see org.chromium.chrome.browser.infobar.InfoBarView#intteContent(InfoBarLayout layout) |
| + */ |
|
gone
2016/01/08 00:08:09
nit: Don't need a javadoc here.
please use gerrit instead
2016/01/12 00:47:25
Done.
|
| + @Override |
| + public void createContent(InfoBarLayout layout) { |
| + super.createContent(layout); |
| + InfoBarControlLayout control = layout.addControlLayout(); |
| + for (CardDetail detail : mCardDetails) { |
| + control.addIcon(detail.issuerIconDrawableId, detail.label, detail.subLabel); |
| + } |
| + |
| + for (LegalMessageLine line : mLegalMessageLines) { |
| + SpannableString text = new SpannableString(line.text); |
| + for (final LegalMessageLine.Link link : line.links) { |
|
gone
2016/01/08 00:08:09
nit: don't need a final here.
please use gerrit instead
2016/01/12 00:47:25
I need the final because "link" is accessed from w
|
| + text.setSpan(new ClickableSpan() { |
| + @Override |
| + public void onClick(View view) { |
| + mDelegate.onLegalMessageLinkClicked(link.url); |
| + } |
| + }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); |
| + } |
| + control.addDescription(text); |
| + } |
| + } |
| +} |