| 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..401b1d19d827c0a23ba7f0985760135e164270e0
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java
|
| @@ -0,0 +1,223 @@
|
| +// 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;
|
| +import java.util.List;
|
| +
|
| +/**
|
| + * An infobar for saving credit card information.
|
| + */
|
| +public class AutofillSaveCardInfoBar 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;
|
| +
|
| + /**
|
| + * 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;
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * 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 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 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 plain text legal message line.
|
| + */
|
| + public String text;
|
| +
|
| + /**
|
| + * A collection of links in the legal message line.
|
| + */
|
| + public final List<Link> links = new LinkedList<Link>();
|
| +
|
| + /**
|
| + * Creates a new instance of the legal message line.
|
| + *
|
| + * @param text The plain text legal message.
|
| + */
|
| + public LegalMessageLine(String text) {
|
| + this.text = text;
|
| + }
|
| + }
|
| +
|
| + private final long mNativeAutofillSaveCardInfoBar;
|
| + private final List<CardDetail> mCardDetails = new LinkedList<CardDetail>();
|
| + 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(long 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(long 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) {
|
| + 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);
|
| +}
|
|
|