@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        } catch (IndexOutOfBoundsException e) {
            fixOnMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
<p/>
A {@link TextView} that insert spaces around its text spans where needed to prevent
{@link IndexOutOfBoundsException} in {@link #onMeasure(int, int)} on Jelly Bean.
<p/>
When {@link #onMeasure(int, int)} throws an exception, we try to fix the text by adding spaces
around spans, until it works again. We then try removing some of the added spans, to minimize the
insertions.
<p/>
The fix is time consuming (a few ms, it depends on the size of your text), but it should only
happen once per text change.
<p/>
See http://code.google.com/p/android/issues/detail?id=35466
<p/>
From https://gist.github.com/pyricau/3424004 with fix from comments
android/modules/module_common/src/main/java/github/tornaco/android/thanos/widget/html/JellyBeanSpanFixTextView.java