Java Code Examples for android.text.style.LineHeightSpan

The following are top voted examples for showing how to use android.text.style.LineHeightSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: markor   File: Highlighter.java   View source code 5 votes vote down vote up
protected void clearSpans(Editable editable) {
    clearCharacterSpanType(editable, TextAppearanceSpan.class);
    clearCharacterSpanType(editable, ForegroundColorSpan.class);
    clearCharacterSpanType(editable, BackgroundColorSpan.class);
    clearCharacterSpanType(editable, StrikethroughSpan.class);
    clearCharacterSpanType(editable, RelativeSizeSpan.class);
    clearCharacterSpanType(editable, StyleSpan.class);
    clearCharacterSpanType(editable, ColorUnderlineSpan.class);
    clearParagraphSpanType(editable, LineBackgroundSpan.class);
    clearParagraphSpanType(editable, LineHeightSpan.class);
}
 
Example 2
Project: IntentsLab   File: FormattedTextBuilder.java   View source code 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T[] getSpans(int start, int end, Class<T> type) {
    // Fast path for common time-critical spans that aren't there
    if (type == MetricAffectingSpan.class && !mHasMetricAffectingSpan) {
        return (T[]) EMPTY_METRIC_AFFECTING_SPAN_ARRAY;
    }
    if (type == ReplacementSpan.class && !mHasReplacementSpan) {
        return (T[]) EMPTY_REPLACEMENT_SPAN_ARRAY;
    }
    if (!mHasParagraphStyle) {
        if (type == LeadingMarginSpan.class) {
            return (T[]) EMPTY_LEADING_MARGIN_SPAN_ARRAY;
        }
        if (type == LineHeightSpan.class) {
            return (T[]) EMPTY_LINE_HEIGHT_SPAN_ARRAY;
        }
        if (type == TabStopSpan.class) {
            return (T[]) EMPTY_TAB_STOP_SPAN_ARRAY;
        }
    }

    T[] spansFromSuperclass = mSpannableString.getSpans(start, end, type);

    if (
            mSpansArr.length == 0 || // We have no optimized spans
            isExcludedSpanType(type)) { // Query is about unoptimized span
        return spansFromSuperclass;
    }

    // Based on Arrays.binarySearch()
    int lo = 0;
    int hi = mSpansArr.length - 1;
    int mid = -2;

    while (lo <= hi) {
        mid = (lo + hi) >>> 1;
        int midVal = mSpansArr[mid].end;

        if (midVal < start) {
            lo = mid + 1;
        } else if (midVal > start) {
            hi = mid - 1;
        } else {
            break;
        }
    }

    // Iterate over spans in range
    List<T> result = null;
    for (; mid < mSpansArr.length && mSpansArr[mid].start < end; mid++) {
        if (mSpansArr[mid].end > start && type.isInstance(mSpansArr[mid].span)) {
            if (result == null) {
                result = LIST_POOL.acquire();
                if (spansFromSuperclass.length != 0) {
                    result.addAll(Arrays.asList(spansFromSuperclass));
                }
            }
            result.add((T) mSpansArr[mid].span);
        }
    }

    // If we have list then make array and pass to superclass
    if (result == null) {
        return spansFromSuperclass;
    } else {
        T[] resultArray = result.toArray((T[]) Array.newInstance(type, result.size()));
        LIST_POOL.release(result);
        return resultArray;
    }
}