Search in sources :

Example 6 with ParagraphStyle

use of android.text.style.ParagraphStyle in project XobotOS by xamarin.

the class TextView method spanChange.

/**
     * Not private so it can be called from an inner class without going
     * through a thunk.
     */
void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd, int newEnd) {
    // XXX Make the start and end move together if this ends up
    // spending too much time invalidating.
    boolean selChanged = false;
    int newSelStart = -1, newSelEnd = -1;
    final InputMethodState ims = mInputMethodState;
    if (what == Selection.SELECTION_END) {
        mHighlightPathBogus = true;
        selChanged = true;
        newSelEnd = newStart;
        if (!isFocused()) {
            mSelectionMoved = true;
        }
        if (oldStart >= 0 || newStart >= 0) {
            invalidateCursor(Selection.getSelectionStart(buf), oldStart, newStart);
            registerForPreDraw();
            makeBlink();
        }
    }
    if (what == Selection.SELECTION_START) {
        mHighlightPathBogus = true;
        selChanged = true;
        newSelStart = newStart;
        if (!isFocused()) {
            mSelectionMoved = true;
        }
        if (oldStart >= 0 || newStart >= 0) {
            int end = Selection.getSelectionEnd(buf);
            invalidateCursor(end, oldStart, newStart);
        }
    }
    if (selChanged) {
        if ((buf.getSpanFlags(what) & Spanned.SPAN_INTERMEDIATE) == 0) {
            if (newSelStart < 0) {
                newSelStart = Selection.getSelectionStart(buf);
            }
            if (newSelEnd < 0) {
                newSelEnd = Selection.getSelectionEnd(buf);
            }
            onSelectionChanged(newSelStart, newSelEnd);
        }
    }
    if (what instanceof UpdateAppearance || what instanceof ParagraphStyle || (what instanceof SuggestionSpan && (((SuggestionSpan) what).getFlags() & SuggestionSpan.FLAG_AUTO_CORRECTION) != 0)) {
        if (ims == null || ims.mBatchEditNesting == 0) {
            invalidate();
            mHighlightPathBogus = true;
            checkForResize();
        } else {
            ims.mContentChanged = true;
        }
    }
    if (MetaKeyKeyListener.isMetaTracker(buf, what)) {
        mHighlightPathBogus = true;
        if (ims != null && MetaKeyKeyListener.isSelectingMetaTracker(buf, what)) {
            ims.mSelectionModeChanged = true;
        }
        if (Selection.getSelectionStart(buf) >= 0) {
            if (ims == null || ims.mBatchEditNesting == 0) {
                invalidateCursor();
            } else {
                ims.mCursorChanged = true;
            }
        }
    }
    if (what instanceof ParcelableSpan) {
        // the current extract editor would be interested in it.
        if (ims != null && ims.mExtracting != null) {
            if (ims.mBatchEditNesting != 0) {
                if (oldStart >= 0) {
                    if (ims.mChangedStart > oldStart) {
                        ims.mChangedStart = oldStart;
                    }
                    if (ims.mChangedStart > oldEnd) {
                        ims.mChangedStart = oldEnd;
                    }
                }
                if (newStart >= 0) {
                    if (ims.mChangedStart > newStart) {
                        ims.mChangedStart = newStart;
                    }
                    if (ims.mChangedStart > newEnd) {
                        ims.mChangedStart = newEnd;
                    }
                }
            } else {
                if (DEBUG_EXTRACT)
                    Log.v(LOG_TAG, "Span change outside of batch: " + oldStart + "-" + oldEnd + "," + newStart + "-" + newEnd + what);
                ims.mContentChanged = true;
            }
        }
    }
    if (newStart < 0 && what instanceof SpellCheckSpan) {
        getSpellChecker().removeSpellCheckSpan((SpellCheckSpan) what);
    }
}
Also used : UpdateAppearance(android.text.style.UpdateAppearance) SpellCheckSpan(android.text.style.SpellCheckSpan) ParagraphStyle(android.text.style.ParagraphStyle) SuggestionSpan(android.text.style.SuggestionSpan) ParcelableSpan(android.text.ParcelableSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 7 with ParagraphStyle

use of android.text.style.ParagraphStyle in project android_frameworks_base by ResurrectionRemix.

the class Layout method drawText.

/**
     * @hide
     */
public void drawText(Canvas canvas, int firstLine, int lastLine) {
    int previousLineBottom = getLineTop(firstLine);
    int previousLineEnd = getLineStart(firstLine);
    ParagraphStyle[] spans = NO_PARA_SPANS;
    int spanEnd = 0;
    TextPaint paint = mPaint;
    CharSequence buf = mText;
    Alignment paraAlign = mAlignment;
    TabStops tabStops = null;
    boolean tabStopsIsInitialized = false;
    TextLine tl = TextLine.obtain();
    // The baseline is the top of the following line minus the current line's descent.
    for (int lineNum = firstLine; lineNum <= lastLine; lineNum++) {
        int start = previousLineEnd;
        previousLineEnd = getLineStart(lineNum + 1);
        int end = getLineVisibleEnd(lineNum, start, previousLineEnd);
        int ltop = previousLineBottom;
        int lbottom = getLineTop(lineNum + 1);
        previousLineBottom = lbottom;
        int lbaseline = lbottom - getLineDescent(lineNum);
        int dir = getParagraphDirection(lineNum);
        int left = 0;
        int right = mWidth;
        if (mSpannedText) {
            Spanned sp = (Spanned) buf;
            int textLength = buf.length();
            boolean isFirstParaLine = (start == 0 || buf.charAt(start - 1) == '\n');
            // our problem.
            if (start >= spanEnd && (lineNum == firstLine || isFirstParaLine)) {
                spanEnd = sp.nextSpanTransition(start, textLength, ParagraphStyle.class);
                spans = getParagraphSpans(sp, start, spanEnd, ParagraphStyle.class);
                paraAlign = mAlignment;
                for (int n = spans.length - 1; n >= 0; n--) {
                    if (spans[n] instanceof AlignmentSpan) {
                        paraAlign = ((AlignmentSpan) spans[n]).getAlignment();
                        break;
                    }
                }
                tabStopsIsInitialized = false;
            }
            // Draw all leading margin spans.  Adjust left or right according
            // to the paragraph direction of the line.
            final int length = spans.length;
            boolean useFirstLineMargin = isFirstParaLine;
            for (int n = 0; n < length; n++) {
                if (spans[n] instanceof LeadingMarginSpan2) {
                    int count = ((LeadingMarginSpan2) spans[n]).getLeadingMarginLineCount();
                    int startLine = getLineForOffset(sp.getSpanStart(spans[n]));
                    // the count that is greatest
                    if (lineNum < startLine + count) {
                        useFirstLineMargin = true;
                        break;
                    }
                }
            }
            for (int n = 0; n < length; n++) {
                if (spans[n] instanceof LeadingMarginSpan) {
                    LeadingMarginSpan margin = (LeadingMarginSpan) spans[n];
                    if (dir == DIR_RIGHT_TO_LEFT) {
                        margin.drawLeadingMargin(canvas, paint, right, dir, ltop, lbaseline, lbottom, buf, start, end, isFirstParaLine, this);
                        right -= margin.getLeadingMargin(useFirstLineMargin);
                    } else {
                        margin.drawLeadingMargin(canvas, paint, left, dir, ltop, lbaseline, lbottom, buf, start, end, isFirstParaLine, this);
                        left += margin.getLeadingMargin(useFirstLineMargin);
                    }
                }
            }
        }
        boolean hasTab = getLineContainsTab(lineNum);
        // Can't tell if we have tabs for sure, currently
        if (hasTab && !tabStopsIsInitialized) {
            if (tabStops == null) {
                tabStops = new TabStops(TAB_INCREMENT, spans);
            } else {
                tabStops.reset(TAB_INCREMENT, spans);
            }
            tabStopsIsInitialized = true;
        }
        // Determine whether the line aligns to normal, opposite, or center.
        Alignment align = paraAlign;
        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(lineNum, Alignment.ALIGN_LEFT);
            } else {
                x = right + getIndentAdjust(lineNum, Alignment.ALIGN_RIGHT);
            }
        } else {
            int max = (int) getLineExtent(lineNum, tabStops, false);
            if (align == Alignment.ALIGN_OPPOSITE) {
                if (dir == DIR_LEFT_TO_RIGHT) {
                    x = right - max + getIndentAdjust(lineNum, Alignment.ALIGN_RIGHT);
                } else {
                    x = left - max + getIndentAdjust(lineNum, Alignment.ALIGN_LEFT);
                }
            } else {
                // Alignment.ALIGN_CENTER
                max = max & ~1;
                x = ((right + left - max) >> 1) + getIndentAdjust(lineNum, Alignment.ALIGN_CENTER);
            }
        }
        paint.setHyphenEdit(getHyphen(lineNum));
        Directions directions = getLineDirections(lineNum);
        if (directions == DIRS_ALL_LEFT_TO_RIGHT && !mSpannedText && !hasTab) {
            // XXX: assumes there's nothing additional to be done
            canvas.drawText(buf, start, end, x, lbaseline, paint);
        } else {
            tl.set(paint, buf, start, end, dir, directions, hasTab, tabStops);
            tl.draw(canvas, x, ltop, lbaseline, lbottom);
        }
        paint.setHyphenEdit(0);
    }
    TextLine.recycle(tl);
}
Also used : AlignmentSpan(android.text.style.AlignmentSpan) ParagraphStyle(android.text.style.ParagraphStyle) Paint(android.graphics.Paint) LeadingMarginSpan2(android.text.style.LeadingMarginSpan.LeadingMarginSpan2) LeadingMarginSpan(android.text.style.LeadingMarginSpan)

Example 8 with ParagraphStyle

use of android.text.style.ParagraphStyle in project android_frameworks_base by ResurrectionRemix.

the class Layout method drawBackground.

/**
     * @hide
     */
public void drawBackground(Canvas canvas, Path highlight, Paint highlightPaint, int cursorOffsetVertical, int firstLine, int lastLine) {
    // They are evaluated at each line.
    if (mSpannedText) {
        if (mLineBackgroundSpans == null) {
            mLineBackgroundSpans = new SpanSet<LineBackgroundSpan>(LineBackgroundSpan.class);
        }
        Spanned buffer = (Spanned) mText;
        int textLength = buffer.length();
        mLineBackgroundSpans.init(buffer, 0, textLength);
        if (mLineBackgroundSpans.numberOfSpans > 0) {
            int previousLineBottom = getLineTop(firstLine);
            int previousLineEnd = getLineStart(firstLine);
            ParagraphStyle[] spans = NO_PARA_SPANS;
            int spansLength = 0;
            TextPaint paint = mPaint;
            int spanEnd = 0;
            final int width = mWidth;
            for (int i = firstLine; i <= lastLine; i++) {
                int start = previousLineEnd;
                int end = getLineStart(i + 1);
                previousLineEnd = end;
                int ltop = previousLineBottom;
                int lbottom = getLineTop(i + 1);
                previousLineBottom = lbottom;
                int lbaseline = lbottom - getLineDescent(i);
                if (start >= spanEnd) {
                    // These should be infrequent, so we'll use this so that
                    // we don't have to check as often.
                    spanEnd = mLineBackgroundSpans.getNextTransition(start, textLength);
                    // All LineBackgroundSpans on a line contribute to its background.
                    spansLength = 0;
                    // Duplication of the logic of getParagraphSpans
                    if (start != end || start == 0) {
                        // array instead to reduce memory allocation
                        for (int j = 0; j < mLineBackgroundSpans.numberOfSpans; j++) {
                            // construction
                            if (mLineBackgroundSpans.spanStarts[j] >= end || mLineBackgroundSpans.spanEnds[j] <= start)
                                continue;
                            spans = GrowingArrayUtils.append(spans, spansLength, mLineBackgroundSpans.spans[j]);
                            spansLength++;
                        }
                    }
                }
                for (int n = 0; n < spansLength; n++) {
                    LineBackgroundSpan lineBackgroundSpan = (LineBackgroundSpan) spans[n];
                    lineBackgroundSpan.drawBackground(canvas, paint, 0, width, ltop, lbaseline, lbottom, buffer, start, end, i);
                }
            }
        }
        mLineBackgroundSpans.recycle();
    }
    // a non-spanned transformation of a spanned editing buffer.
    if (highlight != null) {
        if (cursorOffsetVertical != 0)
            canvas.translate(0, cursorOffsetVertical);
        canvas.drawPath(highlight, highlightPaint);
        if (cursorOffsetVertical != 0)
            canvas.translate(0, -cursorOffsetVertical);
    }
}
Also used : LineBackgroundSpan(android.text.style.LineBackgroundSpan) ParagraphStyle(android.text.style.ParagraphStyle) Paint(android.graphics.Paint)

Example 9 with ParagraphStyle

use of android.text.style.ParagraphStyle in project android_frameworks_base by ResurrectionRemix.

the class TextView method spanChange.

/**
     * Not private so it can be called from an inner class without going
     * through a thunk.
     */
void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd, int newEnd) {
    // XXX Make the start and end move together if this ends up
    // spending too much time invalidating.
    boolean selChanged = false;
    int newSelStart = -1, newSelEnd = -1;
    final Editor.InputMethodState ims = mEditor == null ? null : mEditor.mInputMethodState;
    if (what == Selection.SELECTION_END) {
        selChanged = true;
        newSelEnd = newStart;
        if (oldStart >= 0 || newStart >= 0) {
            invalidateCursor(Selection.getSelectionStart(buf), oldStart, newStart);
            checkForResize();
            registerForPreDraw();
            if (mEditor != null)
                mEditor.makeBlink();
        }
    }
    if (what == Selection.SELECTION_START) {
        selChanged = true;
        newSelStart = newStart;
        if (oldStart >= 0 || newStart >= 0) {
            int end = Selection.getSelectionEnd(buf);
            invalidateCursor(end, oldStart, newStart);
        }
    }
    if (selChanged) {
        mHighlightPathBogus = true;
        if (mEditor != null && !isFocused())
            mEditor.mSelectionMoved = true;
        if ((buf.getSpanFlags(what) & Spanned.SPAN_INTERMEDIATE) == 0) {
            if (newSelStart < 0) {
                newSelStart = Selection.getSelectionStart(buf);
            }
            if (newSelEnd < 0) {
                newSelEnd = Selection.getSelectionEnd(buf);
            }
            if (mEditor != null) {
                mEditor.refreshTextActionMode();
                if (!hasSelection() && mEditor.mTextActionMode == null && hasTransientState()) {
                    // User generated selection has been removed.
                    setHasTransientState(false);
                }
            }
            onSelectionChanged(newSelStart, newSelEnd);
        }
    }
    if (what instanceof UpdateAppearance || what instanceof ParagraphStyle || what instanceof CharacterStyle) {
        if (ims == null || ims.mBatchEditNesting == 0) {
            invalidate();
            mHighlightPathBogus = true;
            checkForResize();
        } else {
            ims.mContentChanged = true;
        }
        if (mEditor != null) {
            if (oldStart >= 0)
                mEditor.invalidateTextDisplayList(mLayout, oldStart, oldEnd);
            if (newStart >= 0)
                mEditor.invalidateTextDisplayList(mLayout, newStart, newEnd);
            mEditor.invalidateHandlesAndActionMode();
        }
    }
    if (MetaKeyKeyListener.isMetaTracker(buf, what)) {
        mHighlightPathBogus = true;
        if (ims != null && MetaKeyKeyListener.isSelectingMetaTracker(buf, what)) {
            ims.mSelectionModeChanged = true;
        }
        if (Selection.getSelectionStart(buf) >= 0) {
            if (ims == null || ims.mBatchEditNesting == 0) {
                invalidateCursor();
            } else {
                ims.mCursorChanged = true;
            }
        }
    }
    if (what instanceof ParcelableSpan) {
        // the current extract editor would be interested in it.
        if (ims != null && ims.mExtractedTextRequest != null) {
            if (ims.mBatchEditNesting != 0) {
                if (oldStart >= 0) {
                    if (ims.mChangedStart > oldStart) {
                        ims.mChangedStart = oldStart;
                    }
                    if (ims.mChangedStart > oldEnd) {
                        ims.mChangedStart = oldEnd;
                    }
                }
                if (newStart >= 0) {
                    if (ims.mChangedStart > newStart) {
                        ims.mChangedStart = newStart;
                    }
                    if (ims.mChangedStart > newEnd) {
                        ims.mChangedStart = newEnd;
                    }
                }
            } else {
                if (DEBUG_EXTRACT)
                    Log.v(LOG_TAG, "Span change outside of batch: " + oldStart + "-" + oldEnd + "," + newStart + "-" + newEnd + " " + what);
                ims.mContentChanged = true;
            }
        }
    }
    if (mEditor != null && mEditor.mSpellChecker != null && newStart < 0 && what instanceof SpellCheckSpan) {
        mEditor.mSpellChecker.onSpellCheckSpanRemoved((SpellCheckSpan) what);
    }
}
Also used : UpdateAppearance(android.text.style.UpdateAppearance) SpellCheckSpan(android.text.style.SpellCheckSpan) ParagraphStyle(android.text.style.ParagraphStyle) ParcelableSpan(android.text.ParcelableSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) CharacterStyle(android.text.style.CharacterStyle)

Example 10 with ParagraphStyle

use of android.text.style.ParagraphStyle in project android_frameworks_base by DirtyUnicorns.

the class Layout method drawBackground.

/**
     * @hide
     */
public void drawBackground(Canvas canvas, Path highlight, Paint highlightPaint, int cursorOffsetVertical, int firstLine, int lastLine) {
    // They are evaluated at each line.
    if (mSpannedText) {
        if (mLineBackgroundSpans == null) {
            mLineBackgroundSpans = new SpanSet<LineBackgroundSpan>(LineBackgroundSpan.class);
        }
        Spanned buffer = (Spanned) mText;
        int textLength = buffer.length();
        mLineBackgroundSpans.init(buffer, 0, textLength);
        if (mLineBackgroundSpans.numberOfSpans > 0) {
            int previousLineBottom = getLineTop(firstLine);
            int previousLineEnd = getLineStart(firstLine);
            ParagraphStyle[] spans = NO_PARA_SPANS;
            int spansLength = 0;
            TextPaint paint = mPaint;
            int spanEnd = 0;
            final int width = mWidth;
            for (int i = firstLine; i <= lastLine; i++) {
                int start = previousLineEnd;
                int end = getLineStart(i + 1);
                previousLineEnd = end;
                int ltop = previousLineBottom;
                int lbottom = getLineTop(i + 1);
                previousLineBottom = lbottom;
                int lbaseline = lbottom - getLineDescent(i);
                if (start >= spanEnd) {
                    // These should be infrequent, so we'll use this so that
                    // we don't have to check as often.
                    spanEnd = mLineBackgroundSpans.getNextTransition(start, textLength);
                    // All LineBackgroundSpans on a line contribute to its background.
                    spansLength = 0;
                    // Duplication of the logic of getParagraphSpans
                    if (start != end || start == 0) {
                        // array instead to reduce memory allocation
                        for (int j = 0; j < mLineBackgroundSpans.numberOfSpans; j++) {
                            // construction
                            if (mLineBackgroundSpans.spanStarts[j] >= end || mLineBackgroundSpans.spanEnds[j] <= start)
                                continue;
                            spans = GrowingArrayUtils.append(spans, spansLength, mLineBackgroundSpans.spans[j]);
                            spansLength++;
                        }
                    }
                }
                for (int n = 0; n < spansLength; n++) {
                    LineBackgroundSpan lineBackgroundSpan = (LineBackgroundSpan) spans[n];
                    lineBackgroundSpan.drawBackground(canvas, paint, 0, width, ltop, lbaseline, lbottom, buffer, start, end, i);
                }
            }
        }
        mLineBackgroundSpans.recycle();
    }
    // a non-spanned transformation of a spanned editing buffer.
    if (highlight != null) {
        if (cursorOffsetVertical != 0)
            canvas.translate(0, cursorOffsetVertical);
        canvas.drawPath(highlight, highlightPaint);
        if (cursorOffsetVertical != 0)
            canvas.translate(0, -cursorOffsetVertical);
    }
}
Also used : LineBackgroundSpan(android.text.style.LineBackgroundSpan) ParagraphStyle(android.text.style.ParagraphStyle) Paint(android.graphics.Paint)

Aggregations

ParagraphStyle (android.text.style.ParagraphStyle)25 Paint (android.graphics.Paint)20 ParcelableSpan (android.text.ParcelableSpan)7 TextPaint (android.text.TextPaint)7 AlignmentSpan (android.text.style.AlignmentSpan)7 LeadingMarginSpan (android.text.style.LeadingMarginSpan)7 LeadingMarginSpan2 (android.text.style.LeadingMarginSpan.LeadingMarginSpan2)7 LineBackgroundSpan (android.text.style.LineBackgroundSpan)7 SpellCheckSpan (android.text.style.SpellCheckSpan)7 UpdateAppearance (android.text.style.UpdateAppearance)7 CharacterStyle (android.text.style.CharacterStyle)6 BulletSpan (android.text.style.BulletSpan)5 SuggestionSpan (android.text.style.SuggestionSpan)1