Force LTR for phone numbers in contact details and editor
Bug 8676101
Change-Id: Ia5117c2e7dbffb5ca17e4147a20bdade500a8c92
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 2647ad6..40a96ff 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -132,6 +132,8 @@
private static final String TAG = "ContactDetailFragment";
+ private static final int TEXT_DIRECTION_UNDEFINED = -1;
+
private interface ContextMenuIds {
static final int COPY_TEXT = 0;
static final int CLEAR_DEFAULT = 1;
@@ -616,6 +618,10 @@
// add to end of list
mPhoneEntries.add(entry);
}
+
+ // Configure the text direction. Phone numbers should be displayed LTR
+ // regardless of what locale the device is in.
+ entry.textDirection = View.TEXT_DIRECTION_LTR;
} else if (dataItem instanceof EmailDataItem && hasData) {
// Build email entries
entry.intent = new Intent(Intent.ACTION_SENDTO,
@@ -1217,6 +1223,7 @@
public String data;
public Uri uri;
public int maxLines = 1;
+ public int textDirection = TEXT_DIRECTION_UNDEFINED;
public String mimetype;
public Context context = null;
@@ -1766,6 +1773,11 @@
mViewEntryDimensions.getPaddingTop(),
secondaryActionViewContainer.getPaddingRight(),
mViewEntryDimensions.getPaddingBottom());
+
+ // Set the text direction
+ if (entry.textDirection != TEXT_DIRECTION_UNDEFINED) {
+ views.data.setTextDirection(entry.textDirection);
+ }
}
private void setMaxLines(TextView textView, int maxLines) {
diff --git a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
index edfd372..70a2b4e 100644
--- a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
+++ b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
@@ -212,8 +212,8 @@
} else {
phoneType = null;
}
- bindData(mContext.getText(R.string.phoneLabelsGroup),
- phoneNumber, phoneType, i == 0);
+ bindData(mContext.getText(R.string.phoneLabelsGroup), phoneNumber, phoneType,
+ i == 0, true);
}
}
@@ -243,8 +243,13 @@
}
}
- private void bindData(
- CharSequence titleText, CharSequence data, CharSequence type, boolean isFirstEntry) {
+ private void bindData(CharSequence titleText, CharSequence data, CharSequence type,
+ boolean isFirstEntry) {
+ bindData(titleText, data, type, isFirstEntry, false);
+ }
+
+ private void bindData(CharSequence titleText, CharSequence data, CharSequence type,
+ boolean isFirstEntry, boolean forceLTR) {
final View field = mInflater.inflate(R.layout.item_read_only_field, mGeneral, false);
final View divider = field.findViewById(R.id.divider);
if (isFirstEntry) {
@@ -258,6 +263,9 @@
}
final TextView dataView = (TextView) field.findViewById(R.id.data);
dataView.setText(data);
+ if (forceLTR) {
+ dataView.setTextDirection(View.TEXT_DIRECTION_LTR);
+ }
final TextView typeView = (TextView) field.findViewById(R.id.type);
if (!TextUtils.isEmpty(type)) {
typeView.setText(type);
diff --git a/src/com/android/contacts/editor/TextFieldsEditorView.java b/src/com/android/contacts/editor/TextFieldsEditorView.java
index 95eb0c1..a20ba77 100644
--- a/src/com/android/contacts/editor/TextFieldsEditorView.java
+++ b/src/com/android/contacts/editor/TextFieldsEditorView.java
@@ -215,6 +215,7 @@
fieldView.setInputType(inputType);
if (inputType == InputType.TYPE_CLASS_PHONE) {
PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(mContext, fieldView);
+ fieldView.setTextDirection(View.TEXT_DIRECTION_LTR);
}
// Show the "next" button in IME to navigate between text fields