From b06d00924123aa13086be564fee6404215fcc0d5 Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 1 Mar 2018 15:05:36 -0800 Subject: Disable phone number formatting for devices with Argentinian SIMs. Bug: 73718977 Test: PhoneNumberHelperTest PiperOrigin-RevId: 187540382 Change-Id: I814ec62b2215c24b8cde3442c5dc83d98ad87164 --- .../common/compat/PhoneNumberUtilsCompat.java | 46 ---------------------- .../contacts/common/list/ContactListItemView.java | 7 ++-- .../contacts/common/model/ContactLoader.java | 2 +- .../common/model/dataitem/PhoneDataItem.java | 12 +++--- .../contacts/common/util/ContactDisplayUtils.java | 4 +- .../widget/SelectPhoneAccountDialogFragment.java | 1 + 6 files changed, 13 insertions(+), 59 deletions(-) delete mode 100644 java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java (limited to 'java/com/android/contacts/common') diff --git a/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java b/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java deleted file mode 100644 index a6cfe07cd..000000000 --- a/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.contacts.common.compat; - -import android.telephony.PhoneNumberUtils; -import android.text.style.TtsSpan; - -/** - * This class contains static utility methods extracted from PhoneNumberUtils, and the methods were - * added in API level 23. In this way, we could enable the corresponding functionality for pre-M - * devices. We need maintain this class and keep it synced with PhoneNumberUtils. Another thing to - * keep in mind is that we use com.google.i18n rather than com.android.i18n in here, so we need make - * sure the application behavior is preserved. - */ -public class PhoneNumberUtilsCompat { - - /** Not instantiable. */ - private PhoneNumberUtilsCompat() {} - - public static String formatNumber( - String phoneNumber, String phoneNumberE164, String defaultCountryIso) { - return PhoneNumberUtils.formatNumber(phoneNumber, phoneNumberE164, defaultCountryIso); - } - - public static CharSequence createTtsSpannable(CharSequence phoneNumber) { - return PhoneNumberUtils.createTtsSpannable(phoneNumber); - } - - public static TtsSpan createTtsSpan(String phoneNumber) { - return PhoneNumberUtils.createTtsSpan(phoneNumber); - } -} diff --git a/java/com/android/contacts/common/list/ContactListItemView.java b/java/com/android/contacts/common/list/ContactListItemView.java index 0a5bf094b..409aa1b9e 100644 --- a/java/com/android/contacts/common/list/ContactListItemView.java +++ b/java/com/android/contacts/common/list/ContactListItemView.java @@ -32,6 +32,7 @@ import android.provider.ContactsContract.SearchSnippets; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; +import android.telephony.PhoneNumberUtils; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; @@ -50,7 +51,6 @@ import android.widget.TextView; import com.android.contacts.common.ContactPresenceIconUtil; import com.android.contacts.common.ContactStatusUtil; import com.android.contacts.common.R; -import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.contacts.common.format.TextHighlighter; import com.android.contacts.common.list.PhoneNumberListAdapter.Listener; import com.android.contacts.common.util.ContactDisplayUtils; @@ -1111,7 +1111,7 @@ public class ContactListItemView extends ViewGroup implements SelectionBoundsAdj mSnippetView.setVisibility(VISIBLE); if (ContactDisplayUtils.isPossiblePhoneNumber(text)) { // Give the text-to-speech engine a hint that it's a phone number - mSnippetView.setContentDescription(PhoneNumberUtilsCompat.createTtsSpannable(text)); + mSnippetView.setContentDescription(PhoneNumberUtils.createTtsSpannable(text)); } else { mSnippetView.setContentDescription(null); } @@ -1232,8 +1232,7 @@ public class ContactListItemView extends ViewGroup implements SelectionBoundsAdj if (ContactDisplayUtils.isPossiblePhoneNumber(name)) { // Give the text-to-speech engine a hint that it's a phone number mNameTextView.setTextDirection(View.TEXT_DIRECTION_LTR); - mNameTextView.setContentDescription( - PhoneNumberUtilsCompat.createTtsSpannable(name.toString())); + mNameTextView.setContentDescription(PhoneNumberUtils.createTtsSpannable(name.toString())); } else { // Remove span tags of highlighting for talkback to avoid reading highlighting and rest // of the name into two separate parts. diff --git a/java/com/android/contacts/common/model/ContactLoader.java b/java/com/android/contacts/common/model/ContactLoader.java index 51b8e3efc..12cca4f13 100644 --- a/java/com/android/contacts/common/model/ContactLoader.java +++ b/java/com/android/contacts/common/model/ContactLoader.java @@ -669,7 +669,7 @@ public class ContactLoader extends AsyncTaskLoader { final DataItem dataItem = dataItems.get(dataIndex); if (dataItem instanceof PhoneDataItem) { final PhoneDataItem phoneDataItem = (PhoneDataItem) dataItem; - phoneDataItem.computeFormattedPhoneNumber(countryIso); + phoneDataItem.computeFormattedPhoneNumber(getContext(), countryIso); } } } diff --git a/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java b/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java index e1f56456a..ed3212490 100644 --- a/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java +++ b/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java @@ -19,15 +19,15 @@ package com.android.contacts.common.model.dataitem; import android.content.ContentValues; import android.content.Context; import android.provider.ContactsContract.CommonDataKinds.Phone; -import com.android.contacts.common.compat.PhoneNumberUtilsCompat; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; /** * Represents a phone data item, wrapping the columns in {@link - * ContactsContract.CommonDataKinds.Phone}. + * android.provider.ContactsContract.CommonDataKinds.Phone}. */ public class PhoneDataItem extends DataItem { - public static final String KEY_FORMATTED_PHONE_NUMBER = "formattedPhoneNumber"; + private static final String KEY_FORMATTED_PHONE_NUMBER = "formattedPhoneNumber"; /* package */ PhoneDataItem(ContentValues values) { super(values); @@ -50,12 +50,12 @@ public class PhoneDataItem extends DataItem { return getContentValues().getAsString(Phone.LABEL); } - public void computeFormattedPhoneNumber(String defaultCountryIso) { + public void computeFormattedPhoneNumber(Context context, String defaultCountryIso) { final String phoneNumber = getNumber(); if (phoneNumber != null) { final String formattedPhoneNumber = - PhoneNumberUtilsCompat.formatNumber( - phoneNumber, getNormalizedNumber(), defaultCountryIso); + PhoneNumberHelper.formatNumber( + context, phoneNumber, getNormalizedNumber(), defaultCountryIso); getContentValues().put(KEY_FORMATTED_PHONE_NUMBER, formattedPhoneNumber); } } diff --git a/java/com/android/contacts/common/util/ContactDisplayUtils.java b/java/com/android/contacts/common/util/ContactDisplayUtils.java index a45394f50..7d428e102 100644 --- a/java/com/android/contacts/common/util/ContactDisplayUtils.java +++ b/java/com/android/contacts/common/util/ContactDisplayUtils.java @@ -21,13 +21,13 @@ import android.content.res.Resources; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.telephony.PhoneNumberUtils; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.text.style.TtsSpan; import android.util.Patterns; import com.android.contacts.common.R; -import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.contacts.common.preference.ContactsPreferences; import com.android.dialer.common.LogUtil; import java.util.Objects; @@ -219,7 +219,7 @@ public class ContactDisplayUtils { int start = TextUtils.isEmpty(phoneNumber) ? -1 : message.indexOf(phoneNumber); while (start >= 0) { final int end = start + phoneNumber.length(); - final TtsSpan ttsSpan = PhoneNumberUtilsCompat.createTtsSpan(phoneNumber); + final TtsSpan ttsSpan = PhoneNumberUtils.createTtsSpan(phoneNumber); spannable.setSpan( ttsSpan, start, diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java index 07891a069..295aa963a 100644 --- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java +++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java @@ -325,6 +325,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { holder.numberTextView.setVisibility(View.VISIBLE); holder.numberTextView.setText( PhoneNumberHelper.formatNumberForDisplay( + getContext(), account.getAddress().getSchemeSpecificPart(), getCountryIso(getContext(), accountHandle))); } -- cgit v1.2.3