OLD | NEW |
---|---|
(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 | |
9 import org.chromium.base.annotations.CalledByNative; | |
10 import org.chromium.chrome.browser.ResourceId; | |
11 | |
12 import java.util.LinkedList; | |
13 import java.util.List; | |
14 | |
15 /** | |
16 * An infobar for saving credit card information. | |
please use gerrit instead
2016/07/27 17:02:25
This comment is not correct.
Mathieu
2016/07/27 21:35:52
Done. Sorry, so many files to keep track of :\
| |
17 */ | |
18 public class AutofillAssistInfoBar extends ConfirmInfoBar { | |
19 /** | |
20 * Detailed card information to show in the infobar. | |
21 */ | |
22 public static class CardDetail { | |
please use gerrit instead
2016/07/27 17:02:26
Let's extract this into a CardDetail.java that can
Mathieu
2016/07/27 21:35:52
Done.
| |
23 /** | |
24 * The identifier of the drawable of the card issuer icon. | |
25 */ | |
26 public int issuerIconDrawableId; | |
27 | |
28 /** | |
29 * The label for the card. | |
30 */ | |
31 public String label; | |
32 | |
33 /** | |
34 * The sub-label for the card. | |
35 */ | |
36 public String subLabel; | |
37 | |
38 /** | |
39 * Creates a new instance of the detailed card information. | |
40 * | |
41 * @param enumeratedIconId ID corresponding to the icon that will be sho wn for this credit | |
42 * card. The ID must have been mapped using the ResourceMapper class | |
43 * before passing it to this function. | |
44 * @param label The credit card label, for example "***1234". | |
45 * @param subLabel The credit card sub-label, for example "Exp: 06/17". | |
46 */ | |
47 public CardDetail(int enumeratedIconId, String label, String subLabel) { | |
48 this.issuerIconDrawableId = ResourceId.mapToDrawableId(enumeratedIco nId); | |
49 this.label = label; | |
50 this.subLabel = subLabel; | |
51 } | |
52 } | |
53 | |
54 private final long mNativeAutofillAssistInfoBar; | |
55 private final List<CardDetail> mCardDetails = new LinkedList<CardDetail>(); | |
please use gerrit instead
2016/07/27 17:02:26
new ArrayList<>();
Android's LinkedLists are inef
Mathieu
2016/07/27 21:35:52
Done.
| |
56 | |
57 /** | |
58 * Creates a new instance of the infobar. | |
59 * | |
60 * @param nativeAutofillAssistInfoBar The pointer to the native object for c allbacks. | |
61 * @param enumeratedIconId ID corresponding to the icon that will be shown f or the InfoBar. | |
62 * The ID must have been mapped using the ResourceMa pper class before | |
63 * passing it to this function. | |
64 * @param iconBitmap Bitmap to use if there is no equivalent Java resource f or enumeratedIconId. | |
65 * @param message Message to display to the user indicating what the InfoBar is for. | |
66 * @param buttonOk String to display on the OK button. | |
67 * @param buttonCancel String to display on the Cancel button. | |
68 */ | |
69 private AutofillAssistInfoBar(long nativeAutofillAssistInfoBar, int enumerat edIconId, | |
70 Bitmap iconBitmap, String message, String buttonOk, String buttonCan cel) { | |
71 super(ResourceId.mapToDrawableId(enumeratedIconId), iconBitmap, message, null, buttonOk, | |
72 buttonCancel); | |
73 mNativeAutofillAssistInfoBar = nativeAutofillAssistInfoBar; | |
74 } | |
75 | |
76 /** | |
77 * Creates an infobar for saving a credit card. | |
please use gerrit instead
2016/07/27 17:02:25
This comment is not correct.
Mathieu
2016/07/27 21:35:52
Done.
| |
78 * | |
79 * @param nativeAutofillAssistInfoBar The pointer to the native object for c allbacks. | |
80 * @param enumeratedIconId ID corresponding to the icon that will be shown f or the InfoBar. | |
81 * The ID must have been mapped using the ResourceMa pper class before | |
82 * passing it to this function. | |
83 * @param iconBitmap Bitmap to use if there is no equivalent Java resource f or enumeratedIconId. | |
84 * @param message Message to display to the user indicating what the InfoBar is for. | |
85 * @param buttonOk String to display on the OK button. | |
86 * @param buttonCancel String to display on the Cancel button. | |
87 * @return A new instance of the infobar. | |
88 */ | |
89 @CalledByNative | |
90 private static AutofillAssistInfoBar create(long nativeAutofillAssistInfoBar , | |
91 int enumeratedIconId, Bitmap iconBitmap, String message, String butt onOk, | |
92 String buttonCancel) { | |
93 return new AutofillAssistInfoBar(nativeAutofillAssistInfoBar, enumerated IconId, iconBitmap, | |
94 message, buttonOk, buttonCancel); | |
95 } | |
96 | |
97 /** | |
98 * Adds information to the infobar about the credit card that will be saved. | |
please use gerrit instead
2016/07/27 17:02:25
This comment is not correct.
Mathieu
2016/07/27 21:35:52
Done.
| |
99 * | |
100 * @param enumeratedIconId ID corresponding to the icon that will be shown f or this credit card. | |
101 * The ID must have been mapped using the ResourceMa pper class before | |
102 * passing it to this function. | |
103 * @param label The credit card label, for example "***1234". | |
104 * @param subLabel The credit card sub-label, for example "Exp: 06/17". | |
105 */ | |
106 @CalledByNative | |
107 private void addDetail(int enumeratedIconId, String label, String subLabel) { | |
108 mCardDetails.add(new CardDetail(enumeratedIconId, label, subLabel)); | |
109 } | |
110 | |
111 @Override | |
112 public void createContent(InfoBarLayout layout) { | |
113 super.createContent(layout); | |
114 InfoBarControlLayout control = layout.addControlLayout(); | |
115 for (CardDetail detail : mCardDetails) { | |
please use gerrit instead
2016/07/27 17:02:26
Use integer loops, because they are more efficient
Mathieu
2016/07/27 21:35:52
Done.
| |
116 control.addIcon(detail.issuerIconDrawableId, 0, detail.label, detail .subLabel); | |
117 } | |
118 } | |
119 } | |
OLD | NEW |