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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillSaveCardInfoBar.java

Issue 1540423004: Add card details and legal message to Android save credit card infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: components/autofill review. Created 4 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.infobar;
6
7 import android.graphics.Bitmap;
8 import android.text.SpannableString;
9 import android.text.Spanned;
10 import android.text.style.ClickableSpan;
11 import android.view.View;
12
13 import org.chromium.base.annotations.CalledByNative;
14 import org.chromium.chrome.browser.ResourceId;
15
16 import java.util.LinkedList;
17 import java.util.List;
18
19 /**
20 * An infobar for saving credit card information.
21 */
22 public class AutofillSaveCardInfoBar extends ConfirmInfoBar {
23 /**
24 * Detailed card information to show in the infobar.
25 */
26 public static class CardDetail {
27 /**
28 * The identifier of the drawable of the card issuer icon.
29 */
30 public int issuerIconDrawableId;
31
32 /**
33 * The label for the card.
34 */
35 public String label;
36
37 /**
38 * The sub-label for the card.
39 */
40 public String subLabel;
41
42 /**
43 * Creates a new instance of the detailed card information.
44 *
45 * @param enumeratedIconId ID corresponding to the icon that will be sho wn for this credit
46 * card. The ID must have been mapped using the ResourceMapper class
47 * before passing it to this function.
48 * @param label The credit card label, for example "***1234".
49 * @param subLabel The credit card sub-label, for example "Exp: 06/17".
50 */
51 public CardDetail(int enumeratedIconId, String label, String subLabel) {
52 this.issuerIconDrawableId = ResourceId.mapToDrawableId(enumeratedIco nId);
53 this.label = label;
54 this.subLabel = subLabel;
55 }
56 }
57
58 /**
59 * Legal message line with links to show in the infobar.
60 */
61 public static class LegalMessageLine {
62 /**
63 * A link in the legal message line.
64 */
65 public static class Link {
66 /**
67 * The starting inclusive index of the link position in the text.
68 */
69 public int start;
70
71 /**
72 * The ending exclusive index of the link position in the text.
73 */
74 public int end;
75
76 /**
77 * The URL of the link.
78 */
79 public String url;
80
81 /**
82 * Creates a new instance of the link.
83 *
84 * @param start The starting inclusive index of the link position in the text.
85 * @param end The ending exclusive index of the link position in the text.
86 * @param url The URL of the link.
87 */
88 public Link(int start, int end, String url) {
89 this.start = start;
90 this.end = end;
91 this.url = url;
92 }
93 }
94
95 /**
96 * The plain text legal message line.
97 */
98 public String text;
99
100 /**
101 * A collection of links in the legal message line.
102 */
103 public final List<Link> links = new LinkedList<Link>();
104
105 /**
106 * Creates a new instance of the legal message line.
107 *
108 * @param text The plain text legal message.
109 */
110 public LegalMessageLine(String text) {
111 this.text = text;
112 }
113 }
114
115 private final long mNativeAutofillSaveCardInfoBar;
116 private final List<CardDetail> mCardDetails = new LinkedList<CardDetail>();
117 private final LinkedList<LegalMessageLine> mLegalMessageLines =
118 new LinkedList<LegalMessageLine>();
119
120 /**
121 * Creates a new instance of the infobar.
122 *
123 * @param nativeAutofillSaveCardInfoBar The pointer to the native object for callbacks.
124 * @param enumeratedIconId ID corresponding to the icon that will be shown f or the InfoBar.
125 * The ID must have been mapped using the ResourceMa pper class before
126 * passing it to this function.
127 * @param iconBitmap Bitmap to use if there is no equivalent Java resource f or enumeratedIconId.
128 * @param message Message to display to the user indicating what the InfoBar is for.
129 * @param linkText Link text to display in addition to the message.
130 * @param buttonOk String to display on the OK button.
131 * @param buttonCancel String to display on the Cancel button.
132 */
133 private AutofillSaveCardInfoBar(long nativeAutofillSaveCardInfoBar, int enum eratedIconId,
134 Bitmap iconBitmap, String message, String linkText, String buttonOk,
135 String buttonCancel) {
136 super(null, ResourceId.mapToDrawableId(enumeratedIconId), iconBitmap, me ssage, linkText,
137 buttonOk, buttonCancel);
138 mNativeAutofillSaveCardInfoBar = nativeAutofillSaveCardInfoBar;
139 }
140
141 /**
142 * Creates an infobar for saving a credit card.
143 *
144 * @param nativeAutofillSaveCardInfoBar The pointer to the native object for callbacks.
145 * @param enumeratedIconId ID corresponding to the icon that will be shown f or the InfoBar.
146 * The ID must have been mapped using the ResourceMa pper class before
147 * passing it to this function.
148 * @param iconBitmap Bitmap to use if there is no equivalent Java resource f or enumeratedIconId.
149 * @param message Message to display to the user indicating what the InfoBar is for.
150 * @param linkText Link text to display in addition to the message.
151 * @param buttonOk String to display on the OK button.
152 * @param buttonCancel String to display on the Cancel button.
153 * @return A new instance of the infobar.
154 */
155 @CalledByNative
156 private static AutofillSaveCardInfoBar create(long nativeAutofillSaveCardInf oBar,
157 int enumeratedIconId, Bitmap iconBitmap, String message, String link Text,
158 String buttonOk, String buttonCancel) {
159 return new AutofillSaveCardInfoBar(nativeAutofillSaveCardInfoBar, enumer atedIconId,
160 iconBitmap, message, linkText, buttonOk, buttonCancel);
161 }
162
163 /**
164 * Adds information to the infobar about the credit card that will be saved.
165 *
166 * @param enumeratedIconId ID corresponding to the icon that will be shown f or this credit card.
167 * The ID must have been mapped using the ResourceMa pper class before
168 * passing it to this function.
169 * @param label The credit card label, for example "***1234".
170 * @param subLabel The credit card sub-label, for example "Exp: 06/17".
171 */
172 @CalledByNative
173 private void addDetail(int enumeratedIconId, String label, String subLabel) {
174 mCardDetails.add(new CardDetail(enumeratedIconId, label, subLabel));
175 }
176
177 /**
178 * Adds a line of legal message plain text to the infobar.
179 *
180 * @param text The legal message plain text.
181 */
182 @CalledByNative
183 private void addLegalMessageLine(String text) {
184 mLegalMessageLines.add(new LegalMessageLine(text));
185 }
186
187 /**
188 * Marks up the last added line of legal message text with a link.
189 *
190 * @param start The inclusive offset of the start of the link in the text.
191 * @param end The exclusive offset of the end of the link in the text.
192 * @param url The URL to open when the link is clicked.
193 */
194 @CalledByNative
195 private void addLinkToLastLegalMessageLine(int start, int end, String url) {
196 mLegalMessageLines.getLast().links.add(new LegalMessageLine.Link(start, end, url));
197 }
198
199 @Override
200 public void createContent(InfoBarLayout layout) {
201 super.createContent(layout);
202 InfoBarControlLayout control = layout.addControlLayout();
203 for (CardDetail detail : mCardDetails) {
204 control.addIcon(detail.issuerIconDrawableId, detail.label, detail.su bLabel);
205 }
206
207 for (LegalMessageLine line : mLegalMessageLines) {
208 SpannableString text = new SpannableString(line.text);
209 for (final LegalMessageLine.Link link : line.links) {
210 text.setSpan(new ClickableSpan() {
211 @Override
212 public void onClick(View view) {
213 nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardI nfoBar, link.url);
214 }
215 }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
216 }
217 control.addDescription(text);
218 }
219 }
220
221 private native void nativeOnLegalMessageLinkClicked(
222 long nativeAutofillSaveCardInfoBar, String url);
223 }
OLDNEW
« no previous file with comments | « android_webview/native/aw_autofill_client.cc ('k') | chrome/browser/android/chrome_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698