/** * @see android.text.style.TabStopSpan */ public static Span tabStop(final int where) { return new Span(new SpanBuilder() { @Override public Object build() { return new TabStopSpan.Standard(where); } }); }
private void writeSingleParagraphStyle(ParagraphStyle style, DataOutputStream dos) throws IOException { Class clazz = style.getClass(); dos.writeInt(mString.getSpanStart(style)); dos.writeInt(mString.getSpanEnd(style)); dos.writeInt(mString.getSpanFlags(style)); if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) { int tag = mCharacterStylesTags.get(clazz.getSimpleName()); if (mCharacterStylesTags.containsKey(clazz.getSimpleName())) { dos.writeInt(tag); } switch (tag) { case 24: // AligmentSpan.Standard AlignmentSpan.Standard as2 = (AlignmentSpan.Standard)style; dos.writeInt(as2.getAlignment().ordinal()); break; case 25: // BulletSpan BulletSpan bs = (BulletSpan)style; dos.writeInt(bs.getLeadingMargin(true)); dos.writeInt(bs.getLeadingMargin(false)); break; case 30: // LeadingMarginSpan.Sandard LeadingMarginSpan.Standard lms = (LeadingMarginSpan.Standard)style; dos.writeInt(lms.getLeadingMargin(true)); dos.writeInt(lms.getLeadingMargin(false)); break; case 34: // QuoteSpan QuoteSpan qs = (QuoteSpan)style; dos.writeInt(qs.getColor()); break; case 36: // TabStopSpan.Standard TabStopSpan.Standard tss = (TabStopSpan.Standard)style; dos.writeInt(tss.getTabStop()); break; default: } } else { write(style,dos); } }
private SpanPlacementInfo readSingleParagraph(DataInputStream dis) throws IOException { SpanPlacementInfo spi = new SpanPlacementInfo(); spi.start = dis.readInt(); spi.end = dis.readInt(); spi.mode = dis.readInt(); int tag = dis.readInt(); // mCharacterStylesTags.get(clazz.getSimpleName()); switch (tag) { case 24: // AligmentSpan.Standard spi.span = new AlignmentSpan.Standard(Alignment.values()[dis.readInt()]); break; case 25: // BulletSpan spi.span = new BulletSpan(dis.readInt()); dis.readInt(); // skip gap width for other lines break; case 30: // LeadingMarginSpan.Sandard spi.span = new LeadingMarginSpan.Standard(dis.readInt(),dis.readInt()); break; case 34: // QuoteSpan spi.span = new QuoteSpan(dis.readInt()); break; case 36: // TabStopSpan.Standard spi.span = new TabStopSpan.Standard(dis.readInt()); break; case 80: // RemoteDrawableSpan break; default: spi.span = read(tag,dis); } return spi; }
@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; } }