Skip to content

Instantly share code, notes, and snippets.

@suwhs
Created September 17, 2016 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suwhs/32a223b17a362f3162626af16c521c58 to your computer and use it in GitHub Desktop.
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)
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