Created
September 17, 2016 13:00
-
-
Save suwhs/32a223b17a362f3162626af16c521c58 to your computer and use it in GitHub Desktop.
Split bidirectional text to avoid mixed ltr/rtl lines (workaround for wATL 1.2.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Spanned workaround(CharSequence string) { | |
SpannableStringBuilder ssb = new SpannableStringBuilder(string); | |
Bidi bidi = new Bidi(string.toString(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); | |
List<Integer> inserts = new ArrayList<Integer>(); | |
if (bidi.isMixed()) { | |
for (int run = 0; run < bidi.getRunCount(); run++) { | |
int end = bidi.getRunLimit(run); | |
inserts.add(end); | |
} | |
Collections.reverse(inserts); | |
for (int pos : inserts) ssb.insert(pos,"\n"); | |
} | |
return ssb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment