From 77893a4c4b8d8ccbd98bb77ef70410f6cb954928 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Jun 2016 14:37:30 -0700 Subject: [PATCH] BidiFormat adapter name for bluetooth_is_visible_message Previously, adapter names which tend to be LTR and may appear at the beginning of the string could cause the detected bidi direction of the whole string (which would be RTL in RTL locales) to get miscalculated as LTR. With this fix, not only the detected bidi direction would be correct, but also odd adapter names would not impact the bidi layout of the whole string. Bug: 28816891 Change-Id: I1d25edbeeff7e9c013bb6c741e7f706431e721dc --- .../settings/bluetooth/BluetoothSettings.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index cc46fba351a..ba3336e6b80 100644 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -31,6 +31,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceScreen; +import android.text.BidiFormatter; import android.text.Spannable; import android.text.style.TextAppearanceSpan; import android.util.Log; @@ -57,6 +58,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Set; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; @@ -115,8 +117,12 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem private void updateDeviceName(Context context) { if (mLocalAdapter.isEnabled() && mMyDevicePreference != null) { - mMyDevicePreference.setSummary(context.getResources().getString( - R.string.bluetooth_is_visible_message, mLocalAdapter.getName())); + final Resources res = context.getResources(); + final Locale locale = res.getConfiguration().getLocales().get(0); + final BidiFormatter bidiFormatter = BidiFormatter.getInstance(locale); + mMyDevicePreference.setSummary(res.getString( + R.string.bluetooth_is_visible_message, + bidiFormatter.unicodeWrap(mLocalAdapter.getName()))); } } }; @@ -345,8 +351,12 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem startScanning(); } - mMyDevicePreference.setSummary(getResources().getString( - R.string.bluetooth_is_visible_message, mLocalAdapter.getName())); + final Resources res = getResources(); + final Locale locale = res.getConfiguration().getLocales().get(0); + final BidiFormatter bidiFormatter = BidiFormatter.getInstance(locale); + mMyDevicePreference.setSummary(res.getString( + R.string.bluetooth_is_visible_message, + bidiFormatter.unicodeWrap(mLocalAdapter.getName()))); getActivity().invalidateOptionsMenu();