Search in sources :

Example 41 with TabStopSpan

use of android.text.style.TabStopSpan in project android_frameworks_base by crdroidandroid.

the class Layout method getLineStartPos.

/**
     * Return the start position of the line, given the left and right bounds
     * of the margins.
     *
     * @param line the line index
     * @param left the left bounds (0, or leading margin if ltr para)
     * @param right the right bounds (width, minus leading margin if rtl para)
     * @return the start position of the line (to right of line if rtl para)
     */
private int getLineStartPos(int line, int left, int right) {
    // Adjust the point at which to start rendering depending on the
    // alignment of the paragraph.
    Alignment align = getParagraphAlignment(line);
    int dir = getParagraphDirection(line);
    if (align == Alignment.ALIGN_LEFT) {
        align = (dir == DIR_LEFT_TO_RIGHT) ? Alignment.ALIGN_NORMAL : Alignment.ALIGN_OPPOSITE;
    } else if (align == Alignment.ALIGN_RIGHT) {
        align = (dir == DIR_LEFT_TO_RIGHT) ? Alignment.ALIGN_OPPOSITE : Alignment.ALIGN_NORMAL;
    }
    int x;
    if (align == Alignment.ALIGN_NORMAL) {
        if (dir == DIR_LEFT_TO_RIGHT) {
            x = left + getIndentAdjust(line, Alignment.ALIGN_LEFT);
        } else {
            x = right + getIndentAdjust(line, Alignment.ALIGN_RIGHT);
        }
    } else {
        TabStops tabStops = null;
        if (mSpannedText && getLineContainsTab(line)) {
            Spanned spanned = (Spanned) mText;
            int start = getLineStart(line);
            int spanEnd = spanned.nextSpanTransition(start, spanned.length(), TabStopSpan.class);
            TabStopSpan[] tabSpans = getParagraphSpans(spanned, start, spanEnd, TabStopSpan.class);
            if (tabSpans.length > 0) {
                tabStops = new TabStops(TAB_INCREMENT, tabSpans);
            }
        }
        int max = (int) getLineExtent(line, tabStops, false);
        if (align == Alignment.ALIGN_OPPOSITE) {
            if (dir == DIR_LEFT_TO_RIGHT) {
                x = right - max + getIndentAdjust(line, Alignment.ALIGN_RIGHT);
            } else {
                // max is negative here
                x = left - max + getIndentAdjust(line, Alignment.ALIGN_LEFT);
            }
        } else {
            // Alignment.ALIGN_CENTER
            max = max & ~1;
            x = (left + right - max) >> 1 + getIndentAdjust(line, Alignment.ALIGN_CENTER);
        }
    }
    return x;
}
Also used : TabStopSpan(android.text.style.TabStopSpan) Paint(android.graphics.Paint)

Example 42 with TabStopSpan

use of android.text.style.TabStopSpan in project android_frameworks_base by crdroidandroid.

the class Layout method getLineExtent.

/**
     * Like {@link #getLineExtent(int,TabStops,boolean)} but determines the
     * tab stops instead of using the ones passed in.
     * @param line the index of the line
     * @param full whether to include trailing whitespace
     * @return the extent of the line
     */
private float getLineExtent(int line, boolean full) {
    int start = getLineStart(line);
    int end = full ? getLineEnd(line) : getLineVisibleEnd(line);
    boolean hasTabs = getLineContainsTab(line);
    TabStops tabStops = null;
    if (hasTabs && mText instanceof Spanned) {
        // Just checking this line should be good enough, tabs should be
        // consistent across all lines in a paragraph.
        TabStopSpan[] tabs = getParagraphSpans((Spanned) mText, start, end, TabStopSpan.class);
        if (tabs.length > 0) {
            // XXX should reuse
            tabStops = new TabStops(TAB_INCREMENT, tabs);
        }
    }
    Directions directions = getLineDirections(line);
    // Returned directions can actually be null
    if (directions == null) {
        return 0f;
    }
    int dir = getParagraphDirection(line);
    TextLine tl = TextLine.obtain();
    tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops);
    float width = tl.metrics(null);
    TextLine.recycle(tl);
    return width;
}
Also used : TabStopSpan(android.text.style.TabStopSpan) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)42 TabStopSpan (android.text.style.TabStopSpan)42 LeadingMarginSpan (android.text.style.LeadingMarginSpan)12 LeadingMarginSpan2 (android.text.style.LeadingMarginSpan.LeadingMarginSpan2)7 LineHeightSpan (android.text.style.LineHeightSpan)7 MetricAffectingSpan (android.text.style.MetricAffectingSpan)7 Bitmap (android.graphics.Bitmap)2