OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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.autofill; | |
6 | |
7 import android.widget.EditText; | |
8 import android.widget.Spinner; | |
9 | |
10 import org.chromium.chrome.browser.autofill.AutofillDialogConstants; | |
11 | |
12 import org.chromium.chrome.R; | |
13 | |
14 /** | |
15 * Utility class for converting section/field IDs to Android IDs for the Autofil
lDialog. | |
16 */ | |
17 public class AutofillDialogUtils { | |
18 | |
19 // The default invalid ID to return when no such field/section is present. | |
20 public static final int INVALID_ID = -1; | |
21 public static final int INVALID_SECTION = -1; | |
22 | |
23 private AutofillDialogUtils() { | |
24 } | |
25 | |
26 /** | |
27 * Returns the {@link Spinner} ID for the given section in the AutofillDialo
g layout. | |
28 * @param section The section to return the spinner ID for. | |
29 * @return The Android ID for the spinner dropdown for the given section. | |
30 */ | |
31 public static int getSpinnerIDForSection(int section) { | |
32 switch (section) { | |
33 case AutofillDialogConstants.SECTION_CC : | |
34 return R.id.cc_spinner; | |
35 case AutofillDialogConstants.SECTION_CC_BILLING : | |
36 return R.id.cc_billing_spinner; | |
37 case AutofillDialogConstants.SECTION_SHIPPING : | |
38 return R.id.address_spinner; | |
39 case AutofillDialogConstants.SECTION_BILLING : | |
40 return R.id.billing_spinner; | |
41 case AutofillDialogConstants.SECTION_EMAIL : | |
42 return R.id.email_spinner; | |
43 default: | |
44 assert(false); | |
45 return INVALID_ID; | |
46 } | |
47 } | |
48 | |
49 /** | |
50 * Returns the autofill menu item layout ID for the given section in the Aut
ofillDialog layout. | |
51 * @param section The section to return the item layout ID for. | |
52 * @return The Android ID for the autofill menu item layout for the given se
ction. | |
53 */ | |
54 public static int getItemLayoutIDForSection(int section) { | |
55 switch (section) { | |
56 case AutofillDialogConstants.SECTION_CC : | |
57 return R.layout.autofill_menu_item; | |
58 case AutofillDialogConstants.SECTION_CC_BILLING : | |
59 return R.layout.autofill_menu_item; | |
60 case AutofillDialogConstants.SECTION_SHIPPING : | |
61 return R.layout.autofill_simple_menu_item; | |
62 case AutofillDialogConstants.SECTION_BILLING : | |
63 return R.layout.autofill_simple_menu_item; | |
64 case AutofillDialogConstants.SECTION_EMAIL : | |
65 return R.layout.autofill_simple_menu_item; | |
66 default: | |
67 assert(false); | |
68 return INVALID_ID; | |
69 } | |
70 } | |
71 | |
72 /** | |
73 * Returns the section that has a spinner with the given id. | |
74 * @param id The Android ID to look up. | |
75 * @return The section with a spinner with the given ID. | |
76 */ | |
77 public static int getSectionForSpinnerID(int id) { | |
78 for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { | |
79 if (getSpinnerIDForSection(i) == id) return i; | |
80 } | |
81 return INVALID_SECTION; | |
82 } | |
83 | |
84 /** | |
85 * Returns whether the given section contains any credit card related | |
86 * information. | |
87 * @param section The section to check. | |
88 * @return Whether the given section is related with credit card information
. | |
89 */ | |
90 public static boolean containsCreditCardInfo(int section) { | |
91 return section == AutofillDialogConstants.SECTION_CC | |
92 || section == AutofillDialogConstants.SECTION_CC_BILLING; | |
93 } | |
94 | |
95 /** | |
96 * Returns the {@link ViewGroup} ID for the given section in the AutofillDia
log layout. | |
97 * @param section The section to return the layout ID for. | |
98 * @return The Android ID for the edit layout for the given section. | |
99 */ | |
100 public static int getLayoutIDForSection(int section) { | |
101 switch (section) { | |
102 case AutofillDialogConstants.SECTION_CC : | |
103 return R.id.editing_layout_credit_card; | |
104 case AutofillDialogConstants.SECTION_CC_BILLING : | |
105 return R.id.editing_layout_cc_billing; | |
106 case AutofillDialogConstants.SECTION_SHIPPING : | |
107 return R.id.editing_layout_shipping; | |
108 case AutofillDialogConstants.SECTION_BILLING : | |
109 return R.id.editing_layout_billing; | |
110 case AutofillDialogConstants.SECTION_EMAIL : | |
111 return R.id.editing_layout_email; | |
112 default: | |
113 assert(false); | |
114 return INVALID_ID; | |
115 } | |
116 } | |
117 | |
118 /** | |
119 * Returns the label ID for the given section in the AutofillDialog | |
120 * layout | |
121 * @param section The section to return the label ID for. | |
122 * @return The Android ID for the label text for the given section. | |
123 */ | |
124 public static int getLabelIDForSection(int section) { | |
125 switch (section) { | |
126 case AutofillDialogConstants.SECTION_CC : | |
127 return R.id.cc_label; | |
128 case AutofillDialogConstants.SECTION_CC_BILLING : | |
129 return R.id.cc_billing_label; | |
130 case AutofillDialogConstants.SECTION_SHIPPING : | |
131 return R.id.shipping_label; | |
132 case AutofillDialogConstants.SECTION_BILLING : | |
133 return R.id.billing_label; | |
134 case AutofillDialogConstants.SECTION_EMAIL : | |
135 return R.id.email_label; | |
136 default: | |
137 assert(false); | |
138 return INVALID_ID; | |
139 } | |
140 } | |
141 | |
142 /** | |
143 * Returns the {@link EditText} ID for the given field in the given section
in the | |
144 * AutofillDialog layout. | |
145 * @param section The section that the field belongs to. | |
146 * @param field The field to return the Android ID for. | |
147 * @return The Android ID corresponding to the field. | |
148 */ | |
149 public static int getViewIDForField(int section, int field) { | |
150 switch (section) { | |
151 case AutofillDialogConstants.SECTION_EMAIL : | |
152 assert(field == AutofillDialogConstants.EMAIL_ADDRESS); | |
153 return R.id.email_address; | |
154 case AutofillDialogConstants.SECTION_CC : | |
155 switch (field) { | |
156 case AutofillDialogConstants.CREDIT_CARD_NUMBER : | |
157 return R.id.card_number; | |
158 case AutofillDialogConstants.CREDIT_CARD_EXP_MONTH : | |
159 return R.id.expiration_month_spinner; | |
160 case AutofillDialogConstants.CREDIT_CARD_EXP_4_DIGIT_YEAR : | |
161 return R.id.expiration_year_spinner; | |
162 case AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE : | |
163 return R.id.cvc_code; | |
164 case AutofillDialogConstants.CREDIT_CARD_NAME : | |
165 return R.id.cardholder_name; | |
166 default: | |
167 assert(false); | |
168 return INVALID_ID; | |
169 } | |
170 case AutofillDialogConstants.SECTION_BILLING : | |
171 switch (field) { | |
172 case AutofillDialogConstants.ADDRESS_BILLING_LINE1 : | |
173 return R.id.billing_street_address_1; | |
174 case AutofillDialogConstants.ADDRESS_BILLING_LINE2 : | |
175 return R.id.billing_street_address_2; | |
176 case AutofillDialogConstants.ADDRESS_BILLING_CITY : | |
177 return R.id.billing_city; | |
178 case AutofillDialogConstants.ADDRESS_BILLING_STATE : | |
179 return R.id.billing_state; | |
180 case AutofillDialogConstants.ADDRESS_BILLING_ZIP : | |
181 return R.id.billing_zip_code; | |
182 case AutofillDialogConstants.ADDRESS_BILLING_COUNTRY : | |
183 return R.id.billing_country_spinner; | |
184 case AutofillDialogConstants.PHONE_BILLING_WHOLE_NUMBER: | |
185 return R.id.billing_phone_number; | |
186 default: | |
187 assert(false); | |
188 return INVALID_ID; | |
189 } | |
190 case AutofillDialogConstants.SECTION_CC_BILLING : | |
191 switch (field) { | |
192 case AutofillDialogConstants.CREDIT_CARD_NUMBER : | |
193 return R.id.card_number; | |
194 case AutofillDialogConstants.CREDIT_CARD_EXP_MONTH : | |
195 return R.id.expiration_month_spinner; | |
196 case AutofillDialogConstants.CREDIT_CARD_EXP_4_DIGIT_YEAR : | |
197 return R.id.expiration_year_spinner; | |
198 case AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE : | |
199 return R.id.cvc_code; | |
200 case AutofillDialogConstants.CREDIT_CARD_NAME : | |
201 return R.id.cardholder_name; | |
202 case AutofillDialogConstants.ADDRESS_BILLING_LINE1 : | |
203 return R.id.billing_street_address_1; | |
204 case AutofillDialogConstants.ADDRESS_BILLING_LINE2 : | |
205 return R.id.billing_street_address_2; | |
206 case AutofillDialogConstants.ADDRESS_BILLING_CITY : | |
207 return R.id.billing_city; | |
208 case AutofillDialogConstants.ADDRESS_BILLING_STATE : | |
209 return R.id.billing_state; | |
210 case AutofillDialogConstants.ADDRESS_BILLING_ZIP : | |
211 return R.id.billing_zip_code; | |
212 case AutofillDialogConstants.ADDRESS_BILLING_COUNTRY : | |
213 return R.id.billing_country_spinner; | |
214 case AutofillDialogConstants.PHONE_BILLING_WHOLE_NUMBER : | |
215 return R.id.billing_phone_number; | |
216 default: | |
217 assert(false); | |
218 return INVALID_ID; | |
219 } | |
220 case AutofillDialogConstants.SECTION_SHIPPING : | |
221 switch (field) { | |
222 case AutofillDialogConstants.NAME_FULL : | |
223 return R.id.recipient_name; | |
224 case AutofillDialogConstants.ADDRESS_HOME_LINE1 : | |
225 return R.id.shipping_street_address_1; | |
226 case AutofillDialogConstants.ADDRESS_HOME_LINE2 : | |
227 return R.id.shipping_street_address_2; | |
228 case AutofillDialogConstants.ADDRESS_HOME_CITY : | |
229 return R.id.shipping_city; | |
230 case AutofillDialogConstants.ADDRESS_HOME_STATE : | |
231 return R.id.shipping_state; | |
232 case AutofillDialogConstants.ADDRESS_HOME_ZIP : | |
233 return R.id.shipping_zip_code; | |
234 case AutofillDialogConstants.ADDRESS_HOME_COUNTRY : | |
235 return R.id.shipping_country_spinner; | |
236 case AutofillDialogConstants.PHONE_HOME_WHOLE_NUMBER : | |
237 return R.id.shipping_phone_number; | |
238 default: | |
239 assert(false); | |
240 return INVALID_ID; | |
241 } | |
242 default: | |
243 assert(false); | |
244 return INVALID_ID; | |
245 } | |
246 | |
247 } | |
248 } | |
OLD | NEW |