Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java

Issue 2101813002: Enable [Save] button after changing billing address. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.preferences.autofill; 5 package org.chromium.chrome.browser.preferences.autofill;
6 6
7 import android.os.Bundle; 7 import android.os.Bundle;
8 import android.text.Editable; 8 import android.text.Editable;
9 import android.text.TextUtils; 9 import android.text.TextUtils;
10 import android.text.TextWatcher; 10 import android.text.TextWatcher;
(...skipping 24 matching lines...) Expand all
35 private FloatLabelLayout mNameLabel; 35 private FloatLabelLayout mNameLabel;
36 private EditText mNameText; 36 private EditText mNameText;
37 private FloatLabelLayout mNumberLabel; 37 private FloatLabelLayout mNumberLabel;
38 private EditText mNumberText; 38 private EditText mNumberText;
39 private Spinner mExpirationMonth; 39 private Spinner mExpirationMonth;
40 private Spinner mExpirationYear; 40 private Spinner mExpirationYear;
41 private Spinner mBillingAddress; 41 private Spinner mBillingAddress;
42 42
43 private int mInitialExpirationMonthPos; 43 private int mInitialExpirationMonthPos;
44 private int mInitialExpirationYearPos; 44 private int mInitialExpirationYearPos;
45 private int mInitialBillingAddressPos;
45 46
46 @Override 47 @Override
47 public View onCreateView(LayoutInflater inflater, ViewGroup container, 48 public View onCreateView(LayoutInflater inflater, ViewGroup container,
48 Bundle savedInstanceState) { 49 Bundle savedInstanceState) {
49 View v = super.onCreateView(inflater, container, savedInstanceState); 50 View v = super.onCreateView(inflater, container, savedInstanceState);
50 51
51 mNameLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_name_lab el); 52 mNameLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_name_lab el);
52 mNameText = (EditText) v.findViewById(R.id.credit_card_name_edit); 53 mNameText = (EditText) v.findViewById(R.id.credit_card_name_edit);
53 mNumberLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_number _label); 54 mNumberLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_number _label);
54 mNumberText = (EditText) v.findViewById(R.id.credit_card_number_edit); 55 mNumberText = (EditText) v.findViewById(R.id.credit_card_number_edit);
(...skipping 19 matching lines...) Expand all
74 75
75 @Override 76 @Override
76 protected int getTitleResourceId(boolean isNewEntry) { 77 protected int getTitleResourceId(boolean isNewEntry) {
77 return isNewEntry 78 return isNewEntry
78 ? R.string.autofill_create_credit_card : R.string.autofill_edit_ credit_card; 79 ? R.string.autofill_create_credit_card : R.string.autofill_edit_ credit_card;
79 } 80 }
80 81
81 @Override 82 @Override
82 public void onItemSelected(AdapterView<?> parent, View view, int position, l ong id) { 83 public void onItemSelected(AdapterView<?> parent, View view, int position, l ong id) {
83 if ((parent == mExpirationYear && position != mInitialExpirationYearPos) 84 if ((parent == mExpirationYear && position != mInitialExpirationYearPos)
84 || (parent == mExpirationMonth && position != mInitialExpiration MonthPos)) { 85 || (parent == mExpirationMonth && position != mInitialExpiration MonthPos)
86 || (parent == mBillingAddress && position != mInitialBillingAddr essPos)) {
85 updateSaveButtonEnabled(); 87 updateSaveButtonEnabled();
86 } 88 }
87 } 89 }
88 90
89 @Override 91 @Override
90 public void onTextChanged(CharSequence s, int start, int before, int count) { 92 public void onTextChanged(CharSequence s, int start, int before, int count) {
91 updateSaveButtonEnabled(); 93 updateSaveButtonEnabled();
92 } 94 }
93 95
94 void addSpinnerAdapters() { 96 void addSpinnerAdapters() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 getActivity().getString(R.string.autofill_billing_address_select _prompt)); 129 getActivity().getString(R.string.autofill_billing_address_select _prompt));
128 profilesAdapter.add(noSelection); 130 profilesAdapter.add(noSelection);
129 131
130 List<AutofillProfile> profiles = PersonalDataManager.getInstance().getPr ofilesForSettings(); 132 List<AutofillProfile> profiles = PersonalDataManager.getInstance().getPr ofilesForSettings();
131 for (int i = 0; i < profiles.size(); i++) { 133 for (int i = 0; i < profiles.size(); i++) {
132 AutofillProfile profile = profiles.get(i); 134 AutofillProfile profile = profiles.get(i);
133 if (profile.getIsLocal()) profilesAdapter.add(profile); 135 if (profile.getIsLocal()) profilesAdapter.add(profile);
134 } 136 }
135 137
136 mBillingAddress.setAdapter(profilesAdapter); 138 mBillingAddress.setAdapter(profilesAdapter);
139 mInitialBillingAddressPos = 0;
137 mBillingAddress.setSelection(0); 140 mBillingAddress.setSelection(0);
138 141
139 // TODO(rouslan): Use an [+ ADD ADDRESS] button instead of disabling the dropdown. 142 // TODO(rouslan): Use an [+ ADD ADDRESS] button instead of disabling the dropdown.
140 // http://crbug.com/623629 143 // http://crbug.com/623629
141 if (profilesAdapter.getCount() == 1) mBillingAddress.setEnabled(false); 144 if (profilesAdapter.getCount() == 1) mBillingAddress.setEnabled(false);
142 } 145 }
143 146
144 private void addCardDataToEditFields() { 147 private void addCardDataToEditFields() {
145 CreditCard card = PersonalDataManager.getInstance().getCreditCard(mGUID) ; 148 CreditCard card = PersonalDataManager.getInstance().getCreditCard(mGUID) ;
146 if (card == null) { 149 if (card == null) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 (ArrayAdapter<CharSequence>) mExpirationYear.getAdapter(); 184 (ArrayAdapter<CharSequence>) mExpirationYear.getAdapter();
182 adapter.insert(card.getYear(), 0); 185 adapter.insert(card.getYear(), 0);
183 mInitialExpirationYearPos = 0; 186 mInitialExpirationYearPos = 0;
184 } 187 }
185 mExpirationYear.setSelection(mInitialExpirationYearPos); 188 mExpirationYear.setSelection(mInitialExpirationYearPos);
186 189
187 if (!TextUtils.isEmpty(card.getBillingAddressId())) { 190 if (!TextUtils.isEmpty(card.getBillingAddressId())) {
188 for (int i = 0; i < mBillingAddress.getAdapter().getCount(); i++) { 191 for (int i = 0; i < mBillingAddress.getAdapter().getCount(); i++) {
189 AutofillProfile profile = (AutofillProfile) mBillingAddress.getA dapter().getItem(i); 192 AutofillProfile profile = (AutofillProfile) mBillingAddress.getA dapter().getItem(i);
190 if (TextUtils.equals(profile.getGUID(), card.getBillingAddressId ())) { 193 if (TextUtils.equals(profile.getGUID(), card.getBillingAddressId ())) {
194 mInitialBillingAddressPos = i;
191 mBillingAddress.setSelection(i); 195 mBillingAddress.setSelection(i);
192 break; 196 break;
193 } 197 }
194 } 198 }
195 } 199 }
196 } 200 }
197 201
198 // Read edited data; save in the associated Chrome profile. 202 // Read edited data; save in the associated Chrome profile.
199 // Ignore empty fields. 203 // Ignore empty fields.
200 @Override 204 @Override
(...skipping 20 matching lines...) Expand all
221 225
222 @Override 226 @Override
223 protected void initializeButtons(View v) { 227 protected void initializeButtons(View v) {
224 super.initializeButtons(v); 228 super.initializeButtons(v);
225 229
226 // Listen for changes to inputs. Enable the save button after something has changed. 230 // Listen for changes to inputs. Enable the save button after something has changed.
227 mNameText.addTextChangedListener(this); 231 mNameText.addTextChangedListener(this);
228 mNumberText.addTextChangedListener(this); 232 mNumberText.addTextChangedListener(this);
229 mExpirationMonth.setOnItemSelectedListener(this); 233 mExpirationMonth.setOnItemSelectedListener(this);
230 mExpirationYear.setOnItemSelectedListener(this); 234 mExpirationYear.setOnItemSelectedListener(this);
235 mBillingAddress.setOnItemSelectedListener(this);
231 } 236 }
232 237
233 private void updateSaveButtonEnabled() { 238 private void updateSaveButtonEnabled() {
234 boolean enabled = !TextUtils.isEmpty(mNameText.getText()) 239 boolean enabled = !TextUtils.isEmpty(mNameText.getText())
235 || !TextUtils.isEmpty(mNumberText.getText()); 240 || !TextUtils.isEmpty(mNumberText.getText());
236 Button button = (Button) getView().findViewById(R.id.button_primary); 241 Button button = (Button) getView().findViewById(R.id.button_primary);
237 button.setEnabled(enabled); 242 button.setEnabled(enabled);
238 } 243 }
239 244
240 /** 245 /**
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 325 }
321 } 326 }
322 327
323 public static boolean hasDashOrSpace(final CharSequence s, final int sta rt, 328 public static boolean hasDashOrSpace(final CharSequence s, final int sta rt,
324 final int count) { 329 final int count) {
325 return TextUtils.indexOf(s, " ", start, start + count) != -1 330 return TextUtils.indexOf(s, " ", start, start + count) != -1
326 || TextUtils.indexOf(s, "-", start, start + count) != -1; 331 || TextUtils.indexOf(s, "-", start, start + count) != -1;
327 } 332 }
328 } 333 }
329 } 334 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698