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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java

Issue 2434603004: Resume formatting card number after user deletes extra chars. (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java
index 42b98e894b241603062d2edaf6ae216eb60a41ae..20a3077db6a2c8ee4771f751a524c2e4d3a91539 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/CreditCardNumberFormattingTextWatcher.java
@@ -21,6 +21,8 @@ public class CreditCardNumberFormattingTextWatcher implements TextWatcher {
/** Character for card number section separator. */
private static final String SEPARATOR = " ";
+ private static final int NUMBER_OF_DIGITS = 16;
+
/**
* Whether to format the credit card number. If true, spaces will be inserted
* automatically between each group of 4 digits in the credit card number as the user types.
@@ -33,7 +35,10 @@ public class CreditCardNumberFormattingTextWatcher implements TextWatcher {
* This is set true when we are manipulating the text of EditText,
* and all callback functions should check this boolean to avoid infinite recursion.
*/
- private boolean mSelfChange = false;
+ private boolean mSelfChange;
+
+ /** Whether the formatting is disabled because the number is too long. */
+ private boolean mNumberTooLong;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
@@ -62,11 +67,17 @@ public class CreditCardNumberFormattingTextWatcher implements TextWatcher {
removeSeparators(s);
// If number is too long, do not format it and remove all
// previous separators.
- if (s.length() > 16) {
+ if (s.length() > NUMBER_OF_DIGITS) {
+ mNumberTooLong = true;
mFormattingEnabled = false;
} else {
insertSeparators(s);
}
+ } else if (mNumberTooLong && s.length() <= NUMBER_OF_DIGITS) {
+ // If user deletes extra characters, re-enable formatting
+ mNumberTooLong = false;
+ mFormattingEnabled = true;
+ insertSeparators(s);
}
// If user clears the input, re-enable formatting
if (s.length() == 0) mFormattingEnabled = true;
« 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