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.payments; | 5 package org.chromium.chrome.browser.payments; |
6 | 6 |
7 import android.app.ProgressDialog; | 7 import android.app.ProgressDialog; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
10 import android.util.Pair; | 10 import android.util.Pair; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 /** | 65 /** |
66 * Adds the given phone number to the autocomplete set, if it's valid. | 66 * Adds the given phone number to the autocomplete set, if it's valid. |
67 * Note that here we consider all non-null and non-empty numbers as valid | 67 * Note that here we consider all non-null and non-empty numbers as valid |
68 * since we are doing strict validation of Autofill data. | 68 * since we are doing strict validation of Autofill data. |
69 * | 69 * |
70 * @param phoneNumber The phone number to possibly add. | 70 * @param phoneNumber The phone number to possibly add. |
71 */ | 71 */ |
72 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { | 72 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { |
73 if (TextUtils.isEmpty(phoneNumber)) mPhoneNumbers.add(phoneNumber.toStri
ng()); | 73 if (!TextUtils.isEmpty(phoneNumber)) mPhoneNumbers.add(phoneNumber.toStr
ing()); |
74 } | 74 } |
75 | 75 |
76 /** | 76 /** |
77 * Builds and shows an editor model with the following fields. | 77 * Builds and shows an editor model with the following fields. |
78 * | 78 * |
79 * [ country dropdown ] <----- country dropdown is always present. | 79 * [ country dropdown ] <----- country dropdown is always present. |
80 * [ an address field ] \ | 80 * [ an address field ] \ |
81 * [ an address field ] \ | 81 * [ an address field ] \ |
82 * ... <-- field order, presence, required, and labels
depend on country. | 82 * ... <-- field order, presence, required, and labels
depend on country. |
83 * [ an address field ] / | 83 * [ an address field ] / |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 mPhoneValidator.setCountryCode(mRecentlySelectedCountry); | 136 mPhoneValidator.setCountryCode(mRecentlySelectedCountry); |
137 mCountryChangeCallback = eventData.second; | 137 mCountryChangeCallback = eventData.second; |
138 loadAdminAreasForCountry(mRecentlySelectedCountry); | 138 loadAdminAreasForCountry(mRecentlySelectedCountry); |
139 } | 139 } |
140 }); | 140 }); |
141 | 141 |
142 // Country dropdown is cached, so the selected item needs to be updated
for the new profile | 142 // Country dropdown is cached, so the selected item needs to be updated
for the new profile |
143 // that's being edited. This will not fire the dropdown callback. | 143 // that's being edited. This will not fire the dropdown callback. |
144 mCountryField.setValue(AutofillAddress.getCountryCode(mProfile)); | 144 mCountryField.setValue(AutofillAddress.getCountryCode(mProfile)); |
145 | 145 |
| 146 // Phone number validator and formatter are cached, so their contry code
needs to be updated |
| 147 // for the new profile that's being edited. |
| 148 assert mCountryField.getValue() != null; |
| 149 mPhoneValidator.setCountryCode(mCountryField.getValue().toString()); |
| 150 mPhoneFormatter.setCountryCode(mCountryField.getValue().toString()); |
| 151 |
146 // There's a finite number of fields for address editing. Changing the c
ountry will re-order | 152 // There's a finite number of fields for address editing. Changing the c
ountry will re-order |
147 // and relabel the fields. The meaning of each field remains the same. | 153 // and relabel the fields. The meaning of each field remains the same. |
148 if (mAddressFields.isEmpty()) { | 154 if (mAddressFields.isEmpty()) { |
149 // City, dependent locality, and organization don't have any special
formatting hints. | 155 // City, dependent locality, and organization don't have any special
formatting hints. |
150 mAddressFields.put(AddressField.LOCALITY, EditorFieldModel.createTex
tInput()); | 156 mAddressFields.put(AddressField.LOCALITY, EditorFieldModel.createTex
tInput()); |
151 mAddressFields.put(AddressField.DEPENDENT_LOCALITY, EditorFieldModel
.createTextInput()); | 157 mAddressFields.put(AddressField.DEPENDENT_LOCALITY, EditorFieldModel
.createTextInput()); |
152 mAddressFields.put(AddressField.ORGANIZATION, EditorFieldModel.creat
eTextInput()); | 158 mAddressFields.put(AddressField.ORGANIZATION, EditorFieldModel.creat
eTextInput()); |
153 | 159 |
154 // Sorting code and postal code (a.k.a. ZIP code) should show both l
etters and digits on | 160 // Sorting code and postal code (a.k.a. ZIP code) should show both l
etters and digits on |
155 // the keyboard, if possible. | 161 // the keyboard, if possible. |
156 mAddressFields.put(AddressField.SORTING_CODE, EditorFieldModel.creat
eTextInput( | 162 mAddressFields.put(AddressField.SORTING_CODE, EditorFieldModel.creat
eTextInput( |
157 EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC)); | 163 EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC)); |
158 mAddressFields.put(AddressField.POSTAL_CODE, EditorFieldModel.create
TextInput( | 164 mAddressFields.put(AddressField.POSTAL_CODE, EditorFieldModel.create
TextInput( |
159 EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC)); | 165 EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC)); |
160 | 166 |
161 // Street line field can contain \n to indicate line breaks. | 167 // Street line field can contain \n to indicate line breaks. |
162 mAddressFields.put(AddressField.STREET_ADDRESS, EditorFieldModel.cre
ateTextInput( | 168 mAddressFields.put(AddressField.STREET_ADDRESS, EditorFieldModel.cre
ateTextInput( |
163 EditorFieldModel.INPUT_TYPE_HINT_STREET_LINES)); | 169 EditorFieldModel.INPUT_TYPE_HINT_STREET_LINES)); |
164 | 170 |
165 // Android has special formatting rules for names. | 171 // Android has special formatting rules for names. |
166 mAddressFields.put(AddressField.RECIPIENT, EditorFieldModel.createTe
xtInput( | 172 mAddressFields.put(AddressField.RECIPIENT, EditorFieldModel.createTe
xtInput( |
167 EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME)); | 173 EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME)); |
168 } | 174 } |
169 | 175 |
170 | 176 |
171 // Phone number is present and required for all countries. | 177 // Phone number is present and required for all countries. |
172 if (mPhoneField == null) { | 178 if (mPhoneField == null) { |
173 assert mCountryField.getValue() != null; | |
174 mPhoneValidator.setCountryCode(mCountryField.getValue().toString()); | |
175 mPhoneFormatter.setCountryCode(mCountryField.getValue().toString()); | |
176 mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPU
T_TYPE_HINT_PHONE, | 179 mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPU
T_TYPE_HINT_PHONE, |
177 mContext.getString(R.string.autofill_profile_editor_phone_nu
mber), | 180 mContext.getString(R.string.autofill_profile_editor_phone_nu
mber), |
178 mPhoneNumbers, mPhoneFormatter, mPhoneValidator, null, | 181 mPhoneNumbers, mPhoneFormatter, mPhoneValidator, null, |
179 mContext.getString(R.string.payments_field_required_validati
on_message), | 182 mContext.getString(R.string.payments_field_required_validati
on_message), |
180 mContext.getString(R.string.payments_phone_invalid_validatio
n_message), null); | 183 mContext.getString(R.string.payments_phone_invalid_validatio
n_message), null); |
181 } | 184 } |
182 | 185 |
183 // Phone number field is cached, so its value needs to be updated for ev
ery new profile | 186 // Phone number field is cached, so its value needs to be updated for ev
ery new profile |
184 // that's being edited. | 187 // that's being edited. |
185 mPhoneField.setValue(mProfile.getPhoneNumber()); | 188 mPhoneField.setValue(mProfile.getPhoneNumber()); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 public boolean isValid(@Nullable CharSequence value) { | 431 public boolean isValid(@Nullable CharSequence value) { |
429 return value != null && PhoneNumberUtil.isValidNumber(value.toString
(), mCountryCode); | 432 return value != null && PhoneNumberUtil.isValidNumber(value.toString
(), mCountryCode); |
430 } | 433 } |
431 | 434 |
432 @Override | 435 @Override |
433 public boolean isLengthMaximum(@Nullable CharSequence value) { | 436 public boolean isLengthMaximum(@Nullable CharSequence value) { |
434 return false; | 437 return false; |
435 } | 438 } |
436 } | 439 } |
437 } | 440 } |
OLD | NEW |