Correctly format numbers in RTL languages.
When phone numbers are formatted together with text in an RTL language,
the numbers will themselves formatted RTL by default: if they have any
formatting (e.g., +, -, (, ), or spaces), then these will not be
formatted correctly, as they should be shown LTR as a whole. This works
by itself if the number is the only thing shown in a text field (since
phone numbers are always made of characters that are entirely LTR), but
fails if the number is formatted within some translated text.
This commit forces the phone number to always be shown LTR.
Also, make it more explicit that the strict is meant to be used with a
number, since the description and xliff tag contradicted the name of the
string.
Bug: 5429886
Change-Id: Ifd1835ecfa89725ea596d02d9945712c4f351ddf
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index caa8bce..6224d19 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -22,6 +22,7 @@
import com.android.contacts.calllog.ContactInfo;
import com.android.contacts.calllog.ContactInfoHelper;
import com.android.contacts.calllog.PhoneNumberHelper;
+import com.android.contacts.format.FormatUtils;
import com.android.contacts.util.AsyncTaskExecutor;
import com.android.contacts.util.AsyncTaskExecutors;
import com.android.contacts.voicemail.VoicemailPlaybackFragment;
@@ -469,7 +470,8 @@
firstDetails.number, firstDetails.formattedNumber);
ViewEntry entry = new ViewEntry(
- getString(R.string.menu_callNumber, displayNumber),
+ getString(R.string.menu_callNumber,
+ FormatUtils.forceLeftToRight(displayNumber)),
new Intent(Intent.ACTION_CALL_PRIVILEGED, numberCallUri),
getString(R.string.description_call, nameOrNumber));
diff --git a/src/com/android/contacts/format/FormatUtils.java b/src/com/android/contacts/format/FormatUtils.java
index 4b076cf..82bf78d 100644
--- a/src/com/android/contacts/format/FormatUtils.java
+++ b/src/com/android/contacts/format/FormatUtils.java
@@ -28,6 +28,8 @@
* Assorted utility methods related to text formatting in Contacts.
*/
public class FormatUtils {
+ private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A';
+ private static final char POP_DIRECTIONAL_FORMATTING = '\u202C';
/**
* Finds the earliest point in buffer1 at which the first part of buffer2 matches. For example,
@@ -180,4 +182,13 @@
return -1;
}
+
+ /** Returns the given text, forced to be left-to-right. */
+ public static CharSequence forceLeftToRight(CharSequence text) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(LEFT_TO_RIGHT_EMBEDDING);
+ sb.append(text);
+ sb.append(POP_DIRECTIONAL_FORMATTING);
+ return sb.toString();
+ }
}