From 1306455ce5eb75c74790526ec3687293221a42ba Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 28 Nov 2017 15:27:11 -0800 Subject: Format number for SIM selection Bug: 69812286 Test: PhoneNumberHelperTest PiperOrigin-RevId: 177227451 Change-Id: I6cf53e50d17860f4374cbd9a94451bc0731905a4 --- .../widget/SelectPhoneAccountDialogFragment.java | 22 +++++++++++++++++++--- .../dialer/phonenumberutil/PhoneNumberHelper.java | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java index e41a75b22..07891a069 100644 --- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java +++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java @@ -25,11 +25,13 @@ import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.os.ResultReceiver; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; +import android.telephony.SubscriptionInfo; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -43,7 +45,10 @@ import android.widget.ListAdapter; import android.widget.TextView; import com.android.contacts.common.R; import com.android.contacts.common.compat.PhoneAccountCompat; -import com.android.contacts.common.compat.PhoneNumberUtilsCompat; +import com.android.dialer.location.GeoUtil; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; +import com.android.dialer.telecom.TelecomUtil; +import com.google.common.base.Optional; import java.util.ArrayList; import java.util.List; @@ -319,8 +324,9 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { } else { holder.numberTextView.setVisibility(View.VISIBLE); holder.numberTextView.setText( - PhoneNumberUtilsCompat.createTtsSpannable( - account.getAddress().getSchemeSpecificPart())); + PhoneNumberHelper.formatNumberForDisplay( + account.getAddress().getSchemeSpecificPart(), + getCountryIso(getContext(), accountHandle))); } holder.imageView.setImageDrawable( PhoneAccountCompat.createIconDrawable(account, getContext())); @@ -339,6 +345,16 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment { return rowView; } + private static String getCountryIso( + Context context, @NonNull PhoneAccountHandle phoneAccountHandle) { + Optional info = + TelecomUtil.getSubscriptionInfo(context, phoneAccountHandle); + if (!info.isPresent()) { + return GeoUtil.getCurrentCountryIso(context); + } + return info.get().getCountryIso().toUpperCase(); + } + private static final class ViewHolder { TextView labelTextView; diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java index 40a338588..cdc06dead 100644 --- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java +++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java @@ -26,6 +26,8 @@ import android.support.annotation.Nullable; import android.telecom.PhoneAccountHandle; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; import android.text.TextUtils; import android.util.SparseIntArray; import com.android.dialer.common.Assert; @@ -337,6 +339,18 @@ public class PhoneNumberHelper { return formattedNumber != null ? formattedNumber : number; } + @Nullable + public static CharSequence formatNumberForDisplay( + @Nullable String number, @NonNull String countryIso) { + if (number == null) { + return null; + } + + return PhoneNumberUtils.createTtsSpannable( + BidiFormatter.getInstance() + .unicodeWrap(formatNumber(number, countryIso), TextDirectionHeuristics.LTR)); + } + /** * Determines if the specified number is actually a URI (i.e. a SIP address) rather than a regular * PSTN phone number, based on whether or not the number contains an "@" character. -- cgit v1.2.3