From 1632cfe1e3f3f94295289a62c69ec5a0489d8f13 Mon Sep 17 00:00:00 2001 From: roldenburg Date: Thu, 30 Nov 2017 11:16:31 -0800 Subject: *** Reason for rollback *** Copybara is fixed for AOSP export Bug: 68665330 Test: rollback PiperOrigin-RevId: 177480870 Change-Id: I0ba38e213bb840436fa6dafc4af0a79019ee93f4 --- .../dialer/dialpadview/DialpadFragment.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'java/com/android/dialer/dialpadview') diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java index 69186d87c..4673d9eca 100644 --- a/java/com/android/dialer/dialpadview/DialpadFragment.java +++ b/java/com/android/dialer/dialpadview/DialpadFragment.java @@ -49,6 +49,7 @@ import android.telephony.PhoneNumberFormattingTextWatcher; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.text.Editable; +import android.text.Selection; import android.text.TextUtils; import android.text.TextWatcher; import android.util.AttributeSet; @@ -89,6 +90,7 @@ import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.CallUtil; import com.android.dialer.util.PermissionsUtil; import com.android.dialer.widget.FloatingActionButtonController; +import com.google.common.base.Ascii; import com.google.common.base.Optional; import java.util.HashSet; import java.util.List; @@ -1882,13 +1884,21 @@ public class DialpadFragment extends Fragment @Override public synchronized void afterTextChanged(Editable s) { - super.afterTextChanged(s); - - if (!"AR".equals(countryCode)) { + // When the country code is NOT "AR", Android telephony's PhoneNumberFormattingTextWatcher can + // correctly handle the input so we will let it do its job. + if (!Ascii.toUpperCase(countryCode).equals("AR")) { + super.afterTextChanged(s); return; } + // When the country code is "AR", PhoneNumberFormattingTextWatcher can also format the input + // correctly if the number is NOT for a domestic call to a mobile phone. String rawNumber = getRawNumber(s); + Matcher matcher = AR_DOMESTIC_CALL_MOBILE_NUMBER_PATTERN.matcher(rawNumber); + if (!matcher.matches()) { + super.afterTextChanged(s); + return; + } // As modifying the input will trigger another call to afterTextChanged(Editable), we must // check whether the input's format has already been removed and return if it has @@ -1897,11 +1907,16 @@ public class DialpadFragment extends Fragment return; } - Matcher matcher = AR_DOMESTIC_CALL_MOBILE_NUMBER_PATTERN.matcher(rawNumber); - if (matcher.matches()) { - s.replace(0, s.length(), rawNumber); - PhoneNumberUtils.addTtsSpan(s, 0 /* start */, s.length() /* endExclusive */); - } + // If we reach this point, the country code must be "AR" and variable "s" represents a number + // for a domestic call to a mobile phone. "s" is incorrectly formatted by Android telephony's + // PhoneNumberFormattingTextWatcher so we remove its format by replacing it with the raw + // number. + s.replace(0, s.length(), rawNumber); + + // Make sure the cursor is at the end of the text. + Selection.setSelection(s, s.length()); + + PhoneNumberUtils.addTtsSpan(s, 0 /* start */, s.length() /* endExclusive */); } private static String getRawNumber(Editable s) { -- cgit v1.2.3