Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4dd913fd34a7f4468ccbec9ebd789d03151666b5 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java |
@@ -0,0 +1,222 @@ |
+// 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 org.chromium.base.annotations.CalledByNative; |
+import org.chromium.chrome.browser.ResourceId; |
+ |
+import java.util.LinkedList; |
+ |
+/** |
+ * An infobar for saving credit card information. |
+ */ |
+public class AutofillSaveCardInfoBar extends ConfirmInfoBar { |
+ /** |
+ * Detailed card information to show in the infobar. |
+ */ |
+ public static class CardDetail { |
+ /** |
gone
2016/01/12 19:04:23
nit: member fields come before methods
please use gerrit instead
2016/01/12 22:58:56
Done.
|
+ * Creates a new instance of the detailed card information. |
+ * |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for this credit |
+ * card. The ID must have been mapped using the ResourceMapper class |
+ * before passing it to this function. |
+ * @param label The credit card label, for example "***1234". |
+ * @param subLabel The credit card sub-label, for example "Exp: 06/17". |
+ */ |
+ public CardDetail(int enumeratedIconId, String label, String subLabel) { |
+ this.issuerIconDrawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
+ this.label = label; |
+ this.subLabel = subLabel; |
+ } |
+ |
+ /** |
+ * 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 { |
+ /** |
gone
2016/01/12 19:04:23
nit: Ditto above.
please use gerrit instead
2016/01/12 22:58:55
Done.
|
+ * Creates a new instance of the link. |
+ * |
+ * @param start The starting inclusive index of the link position in the text. |
+ * @param end The ending exclusive index of the link position in the text. |
+ * @param url The URL of the link. |
+ */ |
+ public Link(int start, int end, String url) { |
+ this.start = start; |
+ this.end = end; |
+ this.url = url; |
+ } |
+ |
+ /** |
+ * The starting inclusive index of the link position in the text. |
+ */ |
+ public int start; |
+ |
+ /** |
+ * The ending exclusive index of the link position in the text. |
+ */ |
+ public int end; |
+ |
+ /** |
+ * The URL of the link. |
+ */ |
+ public String url; |
+ } |
+ |
+ /** |
+ * Creates a new instance of the legal message line. |
+ * |
+ * @param text The plain text legal message. |
+ */ |
+ public LegalMessageLine(String text) { |
+ this.text = text; |
+ } |
+ |
+ /** |
+ * The plain text legal message line. |
+ */ |
+ public String text; |
+ |
+ /** |
+ * A collection of links in the legal message line. |
+ */ |
+ public LinkedList<Link> links = new LinkedList<Link>(); |
gone
2016/01/12 19:04:23
nit: public final List<Link> links = new LinkedLis
please use gerrit instead
2016/01/12 22:58:55
Done.
|
+ } |
+ |
+ private final long mNativeAutofillSaveCardInfoBar; |
+ private final LinkedList<CardDetail> mCardDetails = new LinkedList<CardDetail>(); |
gone
2016/01/12 19:04:23
nit: List instead of LinkedList for the first one
please use gerrit instead
2016/01/12 22:58:55
Done.
|
+ private final LinkedList<LegalMessageLine> mLegalMessageLines = |
+ new LinkedList<LegalMessageLine>(); |
+ |
+ /** |
+ * Creates a new instance of the infobar. |
+ * |
+ * @param nativeAutofillSaveCardInfoBar The pointer to the native object for callbacks. |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for the InfoBar. |
+ * The ID must have been mapped using the ResourceMapper class before |
+ * passing it to this function. |
+ * @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 buttonOk String to display on the OK button. |
+ * @param buttonCancel String to display on the Cancel button. |
+ */ |
+ private AutofillSaveCardInfoBar(int nativeAutofillSaveCardInfoBar, int enumeratedIconId, |
+ Bitmap iconBitmap, String message, String linkText, String buttonOk, |
+ String buttonCancel) { |
+ super(null, ResourceId.mapToDrawableId(enumeratedIconId), iconBitmap, message, linkText, |
+ buttonOk, buttonCancel); |
+ mNativeAutofillSaveCardInfoBar = nativeAutofillSaveCardInfoBar; |
+ } |
+ |
+ /** |
+ * Creates an infobar for saving a credit card. |
+ * |
+ * @param nativeAutofillSaveCardInfoBar The pointer to the native object for callbacks. |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for the InfoBar. |
+ * The ID must have been mapped using the ResourceMapper class before |
+ * passing it to this function. |
+ * @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 buttonOk String to display on the OK button. |
+ * @param buttonCancel String to display on the Cancel button. |
+ * @return A new instance of the infobar. |
+ */ |
+ @CalledByNative |
+ private static AutofillSaveCardInfoBar create(int nativeAutofillSaveCardInfoBar, |
+ int enumeratedIconId, Bitmap iconBitmap, String message, String linkText, |
+ String buttonOk, String buttonCancel) { |
+ return new AutofillSaveCardInfoBar(nativeAutofillSaveCardInfoBar, enumeratedIconId, |
+ iconBitmap, message, linkText, buttonOk, buttonCancel); |
+ } |
+ |
+ /** |
+ * Adds information to the infobar about the credit card that will be saved. |
+ * |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for this credit card. |
+ * The ID must have been mapped using the ResourceMapper class before |
+ * passing it to this function. |
+ * @param label The credit card label, for example "***1234". |
+ * @param subLabel The credit card sub-label, for example "Exp: 06/17". |
+ */ |
+ @CalledByNative |
+ private void addDetail(int enumeratedIconId, String label, String subLabel) { |
+ mCardDetails.add(new CardDetail(enumeratedIconId, label, subLabel)); |
+ } |
+ |
+ /** |
+ * Adds a line of legal message plain text to the infobar. |
+ * |
+ * @param text The legal message plain text. |
+ */ |
+ @CalledByNative |
+ private void addLegalMessageLine(String text) { |
+ mLegalMessageLines.add(new LegalMessageLine(text)); |
+ } |
+ |
+ /** |
+ * Marks up the last added line of legal message text with a link. |
+ * |
+ * @param start The inclusive offset of the start of the link in the text. |
+ * @param end The exclusive offset of the end of the link in the text. |
+ * @param url The URL to open when the link is clicked. |
+ */ |
+ @CalledByNative |
+ private void addLinkToLastLegalMessageLine(int start, int end, String url) { |
+ mLegalMessageLines.getLast().links.add(new LegalMessageLine.Link(start, end, url)); |
+ } |
+ |
+ @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/12 19:04:23
don't need the final here, I think.
please use gerrit instead
2016/01/12 22:58:56
Need it to use link inside of the ClickableSpan be
|
+ text.setSpan(new ClickableSpan() { |
+ @Override |
+ public void onClick(View view) { |
+ nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardInfoBar, link.url); |
+ } |
+ }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); |
+ } |
+ control.addDescription(text); |
+ } |
+ } |
+ |
+ private native void nativeOnLegalMessageLinkClicked( |
+ long nativeAutofillSaveCardInfoBar, String url); |
+} |