summaryrefslogtreecommitdiffstats
path: root/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
diff options
context:
space:
mode:
authorTodor Kalaydjiev <todor@google.com>2012-03-05 12:10:43 -0800
committerTodor Kalaydjiev <todor@google.com>2012-03-08 10:22:42 -0800
commit26a92257b43e8941e1505a5f9df42b00f23a87ee (patch)
treef7619986ac1a6cd9981d41794f8f7d93ae427e39 /telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
parent0de2ed3bf355fd92bcb3c169895a29c9c3db745a (diff)
downloadframeworks_base-26a92257b43e8941e1505a5f9df42b00f23a87ee.zip
frameworks_base-26a92257b43e8941e1505a5f9df42b00f23a87ee.tar.gz
frameworks_base-26a92257b43e8941e1505a5f9df42b00f23a87ee.tar.bz2
Support auto-complete in PhoneNumberFormattingTextWatcher. Also, simplify logic.
Previously, the assumption was that only a deletion or an insertion can happen at a time; but with auto-complete, a deletion and insertion happen at the same time. Needed for bug 5992672 in the Messaging app and is nice to have in the platform. Change-Id: I2d80cecc486e7a1ceeaeb34866bcd834074f5ead
Diffstat (limited to 'telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java')
-rw-r--r--telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java56
1 files changed, 8 insertions, 48 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
index 6f85c7d..983c349 100644
--- a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
+++ b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
@@ -39,30 +39,6 @@ import java.util.Locale;
* The formatting will be restarted once the text is cleared.
*/
public class PhoneNumberFormattingTextWatcher implements TextWatcher {
- /**
- * One or more characters were removed from the end.
- */
- private final static int STATE_REMOVE_LAST = 0;
-
- /**
- * One or more characters were appended.
- */
- private final static int STATE_APPEND = 1;
-
- /**
- * One or more digits were changed in the beginning or the middle of text.
- */
- private final static int STATE_MODIFY_DIGITS = 2;
-
- /**
- * The changes other than the above.
- */
- private final static int STATE_OTHER = 3;
-
- /**
- * The state of this change could be one value of the above
- */
- private int mState;
/**
* Indicates the change was caused by ourselves.
@@ -97,46 +73,30 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
mFormatter = PhoneNumberUtil.getInstance().getAsYouTypeFormatter(countryCode);
}
+ @Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
if (mSelfChange || mStopFormatting) {
return;
}
- if (count == 0 && s.length() == start) {
- // Append one or more new chars
- mState = STATE_APPEND;
- } else if (after == 0 && start + count == s.length() && count > 0) {
- // Remove one or more chars from the end of string.
- mState = STATE_REMOVE_LAST;
- } else if (count > 0 && !hasSeparator(s, start, count)) {
- // Remove the dialable chars in the begin or middle of text.
- mState = STATE_MODIFY_DIGITS;
- } else {
- mState = STATE_OTHER;
+ // If the user manually deleted any non-dialable characters, stop formatting
+ if (count > 0 && hasSeparator(s, start, count)) {
+ stopFormatting();
}
}
+ @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mSelfChange || mStopFormatting) {
return;
}
- if (mState == STATE_OTHER) {
- if (count > 0 && !hasSeparator(s, start, count)) {
- // User inserted the dialable characters in the middle of text.
- mState = STATE_MODIFY_DIGITS;
- }
- }
- // Check whether we should stop formatting.
- if (mState == STATE_APPEND && count > 0 && hasSeparator(s, start, count)) {
- // User appended the non-dialable character, stop formatting.
- stopFormatting();
- } else if (mState == STATE_OTHER) {
- // User must insert or remove the non-dialable characters in the begin or middle of
- // number, stop formatting.
+ // If the user inserted any non-dialable characters, stop formatting
+ if (count > 0 && hasSeparator(s, start, count)) {
stopFormatting();
}
}
+ @Override
public synchronized void afterTextChanged(Editable s) {
if (mStopFormatting) {
// Restart the formatting when all texts were clear.