summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2017-11-28 15:27:11 -0800
committerCopybara-Service <copybara-piper@google.com>2017-11-29 11:49:11 -0800
commit1306455ce5eb75c74790526ec3687293221a42ba (patch)
treebbbb216c0e61454fab59c06ca5baf194d2ff63da /java
parent295d9ad53628eba12d635b35d6b51eb3cae8a4aa (diff)
Format number for SIM selection
Bug: 69812286 Test: PhoneNumberHelperTest PiperOrigin-RevId: 177227451 Change-Id: I6cf53e50d17860f4374cbd9a94451bc0731905a4
Diffstat (limited to 'java')
-rw-r--r--java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java22
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java14
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<SubscriptionInfo> 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.