Search in sources :

Example 11 with DynamicLayout

use of android.text.DynamicLayout in project android_frameworks_base by crdroidandroid.

the class TextView method makeSingleLayout.

/**
     * @hide
     */
protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth, Layout.Alignment alignment, boolean shouldEllipsize, TruncateAt effectiveEllipsize, boolean useSaved) {
    Layout result = null;
    if (mText instanceof Spannable) {
        result = new DynamicLayout(mText, mTransformed, mTextPaint, wantWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad, mBreakStrategy, mHyphenationFrequency, getKeyListener() == null ? effectiveEllipsize : null, ellipsisWidth);
    } else {
        if (boring == UNKNOWN_BORING) {
            boring = BoringLayout.isBoring(mTransformed, mTextPaint, mTextDir, mBoring);
            if (boring != null) {
                mBoring = boring;
            }
        }
        if (boring != null) {
            if (boring.width <= wantWidth && (effectiveEllipsize == null || boring.width <= ellipsisWidth)) {
                if (useSaved && mSavedLayout != null) {
                    result = mSavedLayout.replaceOrMake(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad);
                } else {
                    result = BoringLayout.make(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad);
                }
                if (useSaved) {
                    mSavedLayout = (BoringLayout) result;
                }
            } else if (shouldEllipsize && boring.width <= wantWidth) {
                if (useSaved && mSavedLayout != null) {
                    result = mSavedLayout.replaceOrMake(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad, effectiveEllipsize, ellipsisWidth);
                } else {
                    result = BoringLayout.make(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad, effectiveEllipsize, ellipsisWidth);
                }
            }
        }
    }
    if (result == null) {
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(mTransformed, 0, mTransformed.length(), mTextPaint, wantWidth).setAlignment(alignment).setTextDirection(mTextDir).setLineSpacing(mSpacingAdd, mSpacingMult).setIncludePad(mIncludePad).setBreakStrategy(mBreakStrategy).setHyphenationFrequency(mHyphenationFrequency);
        if (shouldEllipsize) {
            builder.setEllipsize(effectiveEllipsize).setEllipsizedWidth(ellipsisWidth).setMaxLines(mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
        }
        // TODO: explore always setting maxLines
        result = builder.build();
    }
    return result;
}
Also used : BoringLayout(android.text.BoringLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) Spannable(android.text.Spannable)

Example 12 with DynamicLayout

use of android.text.DynamicLayout in project weiciyuan by qii.

the class TextDrawerImpl method draw.

@Override
public void draw(Canvas canvas, boolean hasPositionChanged) {
    if (shouldDrawText()) {
        float[] textPosition = getBestTextPosition();
        if (!TextUtils.isEmpty(mTitle)) {
            canvas.save();
            if (hasPositionChanged) {
                mDynamicTitleLayout = new DynamicLayout(mTitle, mPaintTitle, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true);
            }
            canvas.translate(textPosition[0], textPosition[1]);
            mDynamicTitleLayout.draw(canvas);
            canvas.restore();
        }
        if (!TextUtils.isEmpty(mDetails)) {
            canvas.save();
            if (hasPositionChanged) {
                mDynamicDetailLayout = new DynamicLayout(mDetails, mPaintDetail, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true);
            }
            canvas.translate(textPosition[0], textPosition[1] + mDynamicTitleLayout.getHeight());
            mDynamicDetailLayout.draw(canvas);
            canvas.restore();
        }
    }
}
Also used : DynamicLayout(android.text.DynamicLayout)

Example 13 with DynamicLayout

use of android.text.DynamicLayout in project platform_frameworks_base by android.

the class Editor method invalidateTextDisplayList.

/**
     * Invalidates all the sub-display lists that overlap the specified character range
     */
void invalidateTextDisplayList(Layout layout, int start, int end) {
    if (mTextRenderNodes != null && layout instanceof DynamicLayout) {
        final int firstLine = layout.getLineForOffset(start);
        final int lastLine = layout.getLineForOffset(end);
        DynamicLayout dynamicLayout = (DynamicLayout) layout;
        int[] blockEndLines = dynamicLayout.getBlockEndLines();
        int[] blockIndices = dynamicLayout.getBlockIndices();
        final int numberOfBlocks = dynamicLayout.getNumberOfBlocks();
        int i = 0;
        // Skip the blocks before firstLine
        while (i < numberOfBlocks) {
            if (blockEndLines[i] >= firstLine)
                break;
            i++;
        }
        // Invalidate all subsequent blocks until lastLine is passed
        while (i < numberOfBlocks) {
            final int blockIndex = blockIndices[i];
            if (blockIndex != DynamicLayout.INVALID_BLOCK_INDEX) {
                mTextRenderNodes[blockIndex].isDirty = true;
            }
            if (blockEndLines[i] >= lastLine)
                break;
            i++;
        }
    }
}
Also used : DynamicLayout(android.text.DynamicLayout) Paint(android.graphics.Paint)

Example 14 with DynamicLayout

use of android.text.DynamicLayout in project platform_frameworks_base by android.

the class TextView method makeSingleLayout.

/**
     * @hide
     */
protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth, Layout.Alignment alignment, boolean shouldEllipsize, TruncateAt effectiveEllipsize, boolean useSaved) {
    Layout result = null;
    if (mText instanceof Spannable) {
        result = new DynamicLayout(mText, mTransformed, mTextPaint, wantWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad, mBreakStrategy, mHyphenationFrequency, getKeyListener() == null ? effectiveEllipsize : null, ellipsisWidth);
    } else {
        if (boring == UNKNOWN_BORING) {
            boring = BoringLayout.isBoring(mTransformed, mTextPaint, mTextDir, mBoring);
            if (boring != null) {
                mBoring = boring;
            }
        }
        if (boring != null) {
            if (boring.width <= wantWidth && (effectiveEllipsize == null || boring.width <= ellipsisWidth)) {
                if (useSaved && mSavedLayout != null) {
                    result = mSavedLayout.replaceOrMake(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad);
                } else {
                    result = BoringLayout.make(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad);
                }
                if (useSaved) {
                    mSavedLayout = (BoringLayout) result;
                }
            } else if (shouldEllipsize && boring.width <= wantWidth) {
                if (useSaved && mSavedLayout != null) {
                    result = mSavedLayout.replaceOrMake(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad, effectiveEllipsize, ellipsisWidth);
                } else {
                    result = BoringLayout.make(mTransformed, mTextPaint, wantWidth, alignment, mSpacingMult, mSpacingAdd, boring, mIncludePad, effectiveEllipsize, ellipsisWidth);
                }
            }
        }
    }
    if (result == null) {
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(mTransformed, 0, mTransformed.length(), mTextPaint, wantWidth).setAlignment(alignment).setTextDirection(mTextDir).setLineSpacing(mSpacingAdd, mSpacingMult).setIncludePad(mIncludePad).setBreakStrategy(mBreakStrategy).setHyphenationFrequency(mHyphenationFrequency);
        if (shouldEllipsize) {
            builder.setEllipsize(effectiveEllipsize).setEllipsizedWidth(ellipsisWidth).setMaxLines(mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
        }
        // TODO: explore always setting maxLines
        result = builder.build();
    }
    return result;
}
Also used : BoringLayout(android.text.BoringLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) Spannable(android.text.Spannable)

Example 15 with DynamicLayout

use of android.text.DynamicLayout in project android_frameworks_base by AOSPA.

the class Editor method invalidateTextDisplayList.

/**
     * Invalidates all the sub-display lists that overlap the specified character range
     */
void invalidateTextDisplayList(Layout layout, int start, int end) {
    if (mTextRenderNodes != null && layout instanceof DynamicLayout) {
        final int firstLine = layout.getLineForOffset(start);
        final int lastLine = layout.getLineForOffset(end);
        DynamicLayout dynamicLayout = (DynamicLayout) layout;
        int[] blockEndLines = dynamicLayout.getBlockEndLines();
        int[] blockIndices = dynamicLayout.getBlockIndices();
        final int numberOfBlocks = dynamicLayout.getNumberOfBlocks();
        int i = 0;
        // Skip the blocks before firstLine
        while (i < numberOfBlocks) {
            if (blockEndLines[i] >= firstLine)
                break;
            i++;
        }
        // Invalidate all subsequent blocks until lastLine is passed
        while (i < numberOfBlocks) {
            final int blockIndex = blockIndices[i];
            if (blockIndex != DynamicLayout.INVALID_BLOCK_INDEX) {
                mTextRenderNodes[blockIndex].isDirty = true;
            }
            if (blockEndLines[i] >= lastLine)
                break;
            i++;
        }
    }
}
Also used : DynamicLayout(android.text.DynamicLayout) Paint(android.graphics.Paint)

Aggregations

DynamicLayout (android.text.DynamicLayout)22 Paint (android.graphics.Paint)13 BoringLayout (android.text.BoringLayout)5 Layout (android.text.Layout)5 Spannable (android.text.Spannable)5 StaticLayout (android.text.StaticLayout)5 DisplayListCanvas (android.view.DisplayListCanvas)5 RenderNode (android.view.RenderNode)5 TextPaint (android.text.TextPaint)3 SpannableStringBuilder (android.text.SpannableStringBuilder)2 SuppressLint (android.annotation.SuppressLint)1 DisplayList (android.view.DisplayList)1 HardwareCanvas (android.view.HardwareCanvas)1