| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillLocalCardEditor.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillLocalCardEditor.java
|
| similarity index 77%
|
| copy from chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java
|
| copy to chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillLocalCardEditor.java
|
| index ae2e59d3554dfca85117df4952e881a964d4c361..0015ea799651cdb39b21aeab6701d5334b3adda8 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillLocalCardEditor.java
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -25,24 +25,21 @@ import org.chromium.chrome.browser.widget.FloatLabelLayout;
|
|
|
| import java.text.SimpleDateFormat;
|
| import java.util.Calendar;
|
| -import java.util.List;
|
| import java.util.Locale;
|
|
|
| /**
|
| - * Provides the Java-ui for editing a Credit Card autofill entry.
|
| + * Local credit card settings.
|
| */
|
| -public class AutofillCreditCardEditor extends AutofillEditorBase {
|
| +public class AutofillLocalCardEditor extends AutofillCreditCardEditor {
|
| private FloatLabelLayout mNameLabel;
|
| private EditText mNameText;
|
| private FloatLabelLayout mNumberLabel;
|
| private EditText mNumberText;
|
| private Spinner mExpirationMonth;
|
| private Spinner mExpirationYear;
|
| - private Spinner mBillingAddress;
|
|
|
| private int mInitialExpirationMonthPos;
|
| private int mInitialExpirationYearPos;
|
| - private int mInitialBillingAddressPos;
|
|
|
| @Override
|
| public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
| @@ -59,8 +56,6 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
|
|
| mExpirationMonth = (Spinner) v.findViewById(R.id.autofill_credit_card_editor_month_spinner);
|
| mExpirationYear = (Spinner) v.findViewById(R.id.autofill_credit_card_editor_year_spinner);
|
| - mBillingAddress =
|
| - (Spinner) v.findViewById(R.id.autofill_credit_card_editor_billing_address_spinner);
|
|
|
| addSpinnerAdapters();
|
| addCardDataToEditFields();
|
| @@ -70,7 +65,7 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
|
|
| @Override
|
| protected int getLayoutId() {
|
| - return R.layout.autofill_credit_card_editor;
|
| + return R.layout.autofill_local_card_editor;
|
| }
|
|
|
| @Override
|
| @@ -118,59 +113,35 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
| }
|
| adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
| mExpirationYear.setAdapter(adapter);
|
| -
|
| - // Populate the billing address dropdown.
|
| - ArrayAdapter<AutofillProfile> profilesAdapter = new ArrayAdapter<AutofillProfile>(
|
| - getActivity(), android.R.layout.simple_spinner_item);
|
| - profilesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
| -
|
| - AutofillProfile noSelection = new AutofillProfile();
|
| - noSelection.setLabel(
|
| - getActivity().getString(R.string.autofill_billing_address_select_prompt));
|
| - profilesAdapter.add(noSelection);
|
| -
|
| - List<AutofillProfile> profiles = PersonalDataManager.getInstance().getProfilesForSettings();
|
| - for (int i = 0; i < profiles.size(); i++) {
|
| - AutofillProfile profile = profiles.get(i);
|
| - if (profile.getIsLocal()) profilesAdapter.add(profile);
|
| - }
|
| -
|
| - mBillingAddress.setAdapter(profilesAdapter);
|
| - mInitialBillingAddressPos = 0;
|
| - mBillingAddress.setSelection(0);
|
| -
|
| - // TODO(rouslan): Use an [+ ADD ADDRESS] button instead of disabling the dropdown.
|
| - // http://crbug.com/623629
|
| - if (profilesAdapter.getCount() == 1) mBillingAddress.setEnabled(false);
|
| }
|
|
|
| private void addCardDataToEditFields() {
|
| - CreditCard card = PersonalDataManager.getInstance().getCreditCard(mGUID);
|
| - if (card == null) {
|
| + if (mCard == null) {
|
| mNameLabel.focusWithoutAnimation();
|
| return;
|
| }
|
|
|
| - if (!TextUtils.isEmpty(card.getName())) {
|
| - mNameLabel.setText(card.getName());
|
| + if (!TextUtils.isEmpty(mCard.getName())) {
|
| + mNameLabel.setText(mCard.getName());
|
| }
|
| - if (!TextUtils.isEmpty(card.getNumber())) {
|
| - mNumberLabel.setText(card.getNumber());
|
| + if (!TextUtils.isEmpty(mCard.getNumber())) {
|
| + mNumberLabel.setText(mCard.getNumber());
|
| }
|
|
|
| // Make the name label focusable in touch mode so that mNameText doesn't get focused.
|
| mNameLabel.getLabel().setFocusableInTouchMode(true);
|
|
|
| int monthAsInt = 1;
|
| - if (!card.getMonth().isEmpty()) {
|
| - monthAsInt = Integer.parseInt(card.getMonth());
|
| + if (!mCard.getMonth().isEmpty()) {
|
| + monthAsInt = Integer.parseInt(mCard.getMonth());
|
| }
|
| - mExpirationMonth.setSelection(monthAsInt - 1);
|
| + mInitialExpirationMonthPos = monthAsInt - 1;
|
| + mExpirationMonth.setSelection(mInitialExpirationMonthPos);
|
|
|
| mInitialExpirationYearPos = 0;
|
| boolean foundYear = false;
|
| for (int i = 0; i < mExpirationYear.getAdapter().getCount(); i++) {
|
| - if (card.getYear().equals(mExpirationYear.getAdapter().getItem(i))) {
|
| + if (mCard.getYear().equals(mExpirationYear.getAdapter().getItem(i))) {
|
| mInitialExpirationYearPos = i;
|
| foundYear = true;
|
| break;
|
| @@ -178,29 +149,16 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
| }
|
| // Maybe your card expired years ago? Add the card's year
|
| // to the spinner adapter if not found.
|
| - if (!foundYear && !card.getYear().isEmpty()) {
|
| + if (!foundYear && !mCard.getYear().isEmpty()) {
|
| @SuppressWarnings("unchecked")
|
| ArrayAdapter<CharSequence> adapter =
|
| (ArrayAdapter<CharSequence>) mExpirationYear.getAdapter();
|
| - adapter.insert(card.getYear(), 0);
|
| + adapter.insert(mCard.getYear(), 0);
|
| mInitialExpirationYearPos = 0;
|
| }
|
| mExpirationYear.setSelection(mInitialExpirationYearPos);
|
| -
|
| - if (!TextUtils.isEmpty(card.getBillingAddressId())) {
|
| - for (int i = 0; i < mBillingAddress.getAdapter().getCount(); i++) {
|
| - AutofillProfile profile = (AutofillProfile) mBillingAddress.getAdapter().getItem(i);
|
| - if (TextUtils.equals(profile.getGUID(), card.getBillingAddressId())) {
|
| - mInitialBillingAddressPos = i;
|
| - mBillingAddress.setSelection(i);
|
| - break;
|
| - }
|
| - }
|
| - }
|
| }
|
|
|
| - // Read edited data; save in the associated Chrome profile.
|
| - // Ignore empty fields.
|
| @Override
|
| protected void saveEntry() {
|
| // Remove all spaces in editText.
|
| @@ -212,7 +170,6 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
| (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
|
| 0 /* issuerIconDrawableId */,
|
| ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */);
|
| -
|
| PersonalDataManager.getInstance().setCreditCard(card);
|
| }
|
|
|
| @@ -238,8 +195,7 @@ public class AutofillCreditCardEditor extends AutofillEditorBase {
|
| private void updateSaveButtonEnabled() {
|
| boolean enabled = !TextUtils.isEmpty(mNameText.getText())
|
| || !TextUtils.isEmpty(mNumberText.getText());
|
| - Button button = (Button) getView().findViewById(R.id.button_primary);
|
| - button.setEnabled(enabled);
|
| + ((Button) getView().findViewById(R.id.button_primary)).setEnabled(enabled);
|
| }
|
|
|
| /**
|
|
|