diff options
author | Andrew Lee <anwlee@google.com> | 2015-06-04 13:53:45 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-06-04 14:21:41 -0700 |
commit | f4cb047c49e061cd0590a53d0a176233019eb906 (patch) | |
tree | 75fc7fb8d4ef5cc35b789651c6a993cca9516cf7 /src | |
parent | 11412dc1a83fdc4133385c173e44175dc15e5b86 (diff) |
Bidi-format joined strings.
When joining strings, we want to respect RTL formatting for the
individual elements being joined, and joined string as a whole.
For example...
In LTR: "<LTR-formatted string>, <RTL-formatted string>"
In RTL: "<RTL-formatted string>, <LTR-formatted string>"
Bug: 20988802
Change-Id: I984ff364cbd0b0378bc467213274080e9524b18b
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/util/DialerUtils.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java index a04719a41..a44c2eec6 100644 --- a/src/com/android/dialer/util/DialerUtils.java +++ b/src/com/android/dialer/util/DialerUtils.java @@ -28,6 +28,8 @@ import android.net.Uri; import android.os.Bundle; import android.provider.Telephony; import android.telecom.TelecomManager; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; import android.text.TextUtils; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -41,6 +43,8 @@ import com.android.dialer.R; import com.android.incallui.CallCardFragment; import com.android.incallui.Log; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -158,8 +162,25 @@ public class DialerUtils { * @return Joined char sequences. */ public static CharSequence join(Resources resources, Iterable<CharSequence> list) { + StringBuilder sb = new StringBuilder(); + final BidiFormatter formatter = BidiFormatter.getInstance(); final CharSequence separator = resources.getString(R.string.list_delimeter); - return TextUtils.join(separator, list); + + Iterator<CharSequence> itr = list.iterator(); + boolean firstTime = true; + while (itr.hasNext()) { + if (firstTime) { + firstTime = false; + } else { + sb.append(separator); + } + // Unicode wrap the elements of the list to respect RTL for individual strings. + sb.append(formatter.unicodeWrap( + itr.next().toString(), TextDirectionHeuristics.FIRSTSTRONG_LTR)); + } + + // Unicode wrap the joined value, to respect locale's RTL ordering for the whole list. + return formatter.unicodeWrap(sb.toString()); } /** |