Java 类android.text.style.LineHeightSpan 实例源码

项目:markor    文件:Highlighter.java   
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);
}
项目:IntentsLab    文件:FormattedTextBuilder.java   
@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;
    }
}