OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
8 import android.text.SpannableString; | 8 import android.text.SpannableString; |
9 import android.text.Spanned; | 9 import android.text.Spanned; |
10 import android.text.style.ClickableSpan; | 10 import android.text.style.ClickableSpan; |
11 import android.view.View; | 11 import android.view.View; |
12 | 12 |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.chrome.browser.ResourceId; | 14 import org.chromium.chrome.browser.ResourceId; |
15 | 15 |
| 16 import java.util.ArrayList; |
16 import java.util.LinkedList; | 17 import java.util.LinkedList; |
17 import java.util.List; | 18 import java.util.List; |
18 | 19 |
19 /** | 20 /** |
20 * An infobar for saving credit card information. | 21 * An infobar for saving credit card information. |
21 */ | 22 */ |
22 public class AutofillSaveCardInfoBar extends ConfirmInfoBar { | 23 public class AutofillSaveCardInfoBar extends ConfirmInfoBar { |
23 /** | 24 /** |
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. | 25 * Legal message line with links to show in the infobar. |
60 */ | 26 */ |
61 public static class LegalMessageLine { | 27 public static class LegalMessageLine { |
62 /** | 28 /** |
63 * A link in the legal message line. | 29 * A link in the legal message line. |
64 */ | 30 */ |
65 public static class Link { | 31 public static class Link { |
66 /** | 32 /** |
67 * The starting inclusive index of the link position in the text. | 33 * The starting inclusive index of the link position in the text. |
68 */ | 34 */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 * Creates a new instance of the legal message line. | 72 * Creates a new instance of the legal message line. |
107 * | 73 * |
108 * @param text The plain text legal message. | 74 * @param text The plain text legal message. |
109 */ | 75 */ |
110 public LegalMessageLine(String text) { | 76 public LegalMessageLine(String text) { |
111 this.text = text; | 77 this.text = text; |
112 } | 78 } |
113 } | 79 } |
114 | 80 |
115 private final long mNativeAutofillSaveCardInfoBar; | 81 private final long mNativeAutofillSaveCardInfoBar; |
116 private final List<CardDetail> mCardDetails = new LinkedList<CardDetail>(); | 82 private final List<CardDetail> mCardDetails = new ArrayList<>(); |
117 private final LinkedList<LegalMessageLine> mLegalMessageLines = | 83 private final LinkedList<LegalMessageLine> mLegalMessageLines = |
118 new LinkedList<LegalMessageLine>(); | 84 new LinkedList<LegalMessageLine>(); |
119 | 85 |
120 /** | 86 /** |
121 * Creates a new instance of the infobar. | 87 * Creates a new instance of the infobar. |
122 * | 88 * |
123 * @param nativeAutofillSaveCardInfoBar The pointer to the native object for
callbacks. | 89 * @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. | 90 * @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 | 91 * The ID must have been mapped using the ResourceMa
pper class before |
126 * passing it to this function. | 92 * passing it to this function. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 */ | 159 */ |
194 @CalledByNative | 160 @CalledByNative |
195 private void addLinkToLastLegalMessageLine(int start, int end, String url) { | 161 private void addLinkToLastLegalMessageLine(int start, int end, String url) { |
196 mLegalMessageLines.getLast().links.add(new LegalMessageLine.Link(start,
end, url)); | 162 mLegalMessageLines.getLast().links.add(new LegalMessageLine.Link(start,
end, url)); |
197 } | 163 } |
198 | 164 |
199 @Override | 165 @Override |
200 public void createContent(InfoBarLayout layout) { | 166 public void createContent(InfoBarLayout layout) { |
201 super.createContent(layout); | 167 super.createContent(layout); |
202 InfoBarControlLayout control = layout.addControlLayout(); | 168 InfoBarControlLayout control = layout.addControlLayout(); |
203 for (CardDetail detail : mCardDetails) { | 169 for (int i = 0; i < mCardDetails.size(); i++) { |
| 170 CardDetail detail = mCardDetails.get(i); |
204 control.addIcon(detail.issuerIconDrawableId, 0, detail.label, detail
.subLabel); | 171 control.addIcon(detail.issuerIconDrawableId, 0, detail.label, detail
.subLabel); |
205 } | 172 } |
206 | 173 |
207 for (LegalMessageLine line : mLegalMessageLines) { | 174 for (LegalMessageLine line : mLegalMessageLines) { |
208 SpannableString text = new SpannableString(line.text); | 175 SpannableString text = new SpannableString(line.text); |
209 for (final LegalMessageLine.Link link : line.links) { | 176 for (final LegalMessageLine.Link link : line.links) { |
210 text.setSpan(new ClickableSpan() { | 177 text.setSpan(new ClickableSpan() { |
211 @Override | 178 @Override |
212 public void onClick(View view) { | 179 public void onClick(View view) { |
213 nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardI
nfoBar, link.url); | 180 nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardI
nfoBar, link.url); |
214 } | 181 } |
215 }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); | 182 }, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); |
216 } | 183 } |
217 control.addDescription(text); | 184 control.addDescription(text); |
218 } | 185 } |
219 } | 186 } |
220 | 187 |
221 private native void nativeOnLegalMessageLinkClicked( | 188 private native void nativeOnLegalMessageLinkClicked( |
222 long nativeAutofillSaveCardInfoBar, String url); | 189 long nativeAutofillSaveCardInfoBar, String url); |
223 } | 190 } |
OLD | NEW |