Search in sources :

Example 46 with StaticLayout

use of android.text.StaticLayout in project plaid by nickbutcher.

the class CollapsingTitleLayout method createLayoutPreM.

private void createLayoutPreM(int width, float lineSpacingAdd) {
    layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true);
    lineCount = layout.getLineCount();
    if (lineCount > maxLines) {
        // if it exceeds our max number of lines then truncate the text & recreate the layout
        // minus 2 chars for the ellipse
        int endIndex = layout.getLineEnd(maxLines - 1) - 2;
        displayText = new SpannableStringBuilder(title.subSequence(0, endIndex) + "…");
        layout = new StaticLayout(displayText, paint, width - titleInsetStart - titleInsetEnd, Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingAdd, true);
        lineCount = maxLines;
    }
}
Also used : StaticLayout(android.text.StaticLayout) Point(android.graphics.Point) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 47 with StaticLayout

use of android.text.StaticLayout in project simplefacebook by androidquery.

the class SlimTextView method fillLayout.

private void fillLayout(LayoutString stl, int width) {
    //AQUtility.debug(this.getTextColors().getDefaultColor() + ":" + getPaint().getColor());
    TextPaint paint = getPaint();
    //paint.setColor(getTextColors().getDefaultColor());
    //int width = measureWidth(widthMeasureSpec, str);
    Layout layout = new StaticLayout(stl.str, paint, width, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
    int count = layout.getLineCount();
    //AQUtility.debug("count", count);
    int height = layout.getLineTop(count);
    //AQUtility.debug("dim", width + "x" + height);
    stl.width = width;
    stl.height = height;
    stl.layout = layout;
//AQUtility.debug("fill layout");
}
Also used : StaticLayout(android.text.StaticLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Example 48 with StaticLayout

use of android.text.StaticLayout in project android_frameworks_base by ParanoidAndroid.

the class Editor method chooseSize.

private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
    int wid = tv.getPaddingLeft() + tv.getPaddingRight();
    int ht = tv.getPaddingTop() + tv.getPaddingBottom();
    int defaultWidthInPixels = mTextView.getResources().getDimensionPixelSize(com.android.internal.R.dimen.textview_error_popup_default_width);
    Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
    float max = 0;
    for (int i = 0; i < l.getLineCount(); i++) {
        max = Math.max(max, l.getLineWidth(i));
    }
    /*
         * Now set the popup size to be big enough for the text plus the border capped
         * to DEFAULT_MAX_POPUP_WIDTH
         */
    pop.setWidth(wid + (int) Math.ceil(max));
    pop.setHeight(ht + l.getHeight());
}
Also used : Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) Paint(android.graphics.Paint)

Example 49 with StaticLayout

use of android.text.StaticLayout in project android_frameworks_base by ParanoidAndroid.

the class TextView method makeNewLayout.

/**
     * The width passed in is now the desired layout width,
     * not the full view width with padding.
     * {@hide}
     */
protected void makeNewLayout(int wantWidth, int hintWidth, BoringLayout.Metrics boring, BoringLayout.Metrics hintBoring, int ellipsisWidth, boolean bringIntoView) {
    stopMarquee();
    // Update "old" cached values
    mOldMaximum = mMaximum;
    mOldMaxMode = mMaxMode;
    mHighlightPathBogus = true;
    if (wantWidth < 0) {
        wantWidth = 0;
    }
    if (hintWidth < 0) {
        hintWidth = 0;
    }
    Layout.Alignment alignment = getLayoutAlignment();
    final boolean testDirChange = mSingleLine && mLayout != null && (alignment == Layout.Alignment.ALIGN_NORMAL || alignment == Layout.Alignment.ALIGN_OPPOSITE);
    int oldDir = 0;
    if (testDirChange)
        oldDir = mLayout.getParagraphDirection(0);
    boolean shouldEllipsize = mEllipsize != null && getKeyListener() == null;
    final boolean switchEllipsize = mEllipsize == TruncateAt.MARQUEE && mMarqueeFadeMode != MARQUEE_FADE_NORMAL;
    TruncateAt effectiveEllipsize = mEllipsize;
    if (mEllipsize == TruncateAt.MARQUEE && mMarqueeFadeMode == MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS) {
        effectiveEllipsize = TruncateAt.END_SMALL;
    }
    if (mTextDir == null) {
        mTextDir = getTextDirectionHeuristic();
    }
    mLayout = makeSingleLayout(wantWidth, boring, ellipsisWidth, alignment, shouldEllipsize, effectiveEllipsize, effectiveEllipsize == mEllipsize);
    if (switchEllipsize) {
        TruncateAt oppositeEllipsize = effectiveEllipsize == TruncateAt.MARQUEE ? TruncateAt.END : TruncateAt.MARQUEE;
        mSavedMarqueeModeLayout = makeSingleLayout(wantWidth, boring, ellipsisWidth, alignment, shouldEllipsize, oppositeEllipsize, effectiveEllipsize != mEllipsize);
    }
    shouldEllipsize = mEllipsize != null;
    mHintLayout = null;
    if (mHint != null) {
        if (shouldEllipsize)
            hintWidth = wantWidth;
        if (hintBoring == UNKNOWN_BORING) {
            hintBoring = BoringLayout.isBoring(mHint, mTextPaint, mTextDir, mHintBoring);
            if (hintBoring != null) {
                mHintBoring = hintBoring;
            }
        }
        if (hintBoring != null) {
            if (hintBoring.width <= hintWidth && (!shouldEllipsize || hintBoring.width <= ellipsisWidth)) {
                if (mSavedHintLayout != null) {
                    mHintLayout = mSavedHintLayout.replaceOrMake(mHint, mTextPaint, hintWidth, alignment, mSpacingMult, mSpacingAdd, hintBoring, mIncludePad);
                } else {
                    mHintLayout = BoringLayout.make(mHint, mTextPaint, hintWidth, alignment, mSpacingMult, mSpacingAdd, hintBoring, mIncludePad);
                }
                mSavedHintLayout = (BoringLayout) mHintLayout;
            } else if (shouldEllipsize && hintBoring.width <= hintWidth) {
                if (mSavedHintLayout != null) {
                    mHintLayout = mSavedHintLayout.replaceOrMake(mHint, mTextPaint, hintWidth, alignment, mSpacingMult, mSpacingAdd, hintBoring, mIncludePad, mEllipsize, ellipsisWidth);
                } else {
                    mHintLayout = BoringLayout.make(mHint, mTextPaint, hintWidth, alignment, mSpacingMult, mSpacingAdd, hintBoring, mIncludePad, mEllipsize, ellipsisWidth);
                }
            } else if (shouldEllipsize) {
                mHintLayout = new StaticLayout(mHint, 0, mHint.length(), mTextPaint, hintWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad, mEllipsize, ellipsisWidth, mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
            } else {
                mHintLayout = new StaticLayout(mHint, mTextPaint, hintWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad);
            }
        } else if (shouldEllipsize) {
            mHintLayout = new StaticLayout(mHint, 0, mHint.length(), mTextPaint, hintWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad, mEllipsize, ellipsisWidth, mMaxMode == LINES ? mMaximum : Integer.MAX_VALUE);
        } else {
            mHintLayout = new StaticLayout(mHint, mTextPaint, hintWidth, alignment, mTextDir, mSpacingMult, mSpacingAdd, mIncludePad);
        }
    }
    if (bringIntoView || (testDirChange && oldDir != mLayout.getParagraphDirection(0))) {
        registerForPreDraw();
    }
    if (mEllipsize == TextUtils.TruncateAt.MARQUEE) {
        if (!compressText(ellipsisWidth)) {
            final int height = mLayoutParams.height;
            // start the marquee immediately
            if (height != LayoutParams.WRAP_CONTENT && height != LayoutParams.MATCH_PARENT) {
                startMarquee();
            } else {
                // Defer the start of the marquee until we know our width (see setFrame())
                mRestartMarquee = true;
            }
        }
    }
    // CursorControllers need a non-null mLayout
    if (mEditor != null)
        mEditor.prepareCursorControllers();
}
Also used : BoringLayout(android.text.BoringLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) DynamicLayout(android.text.DynamicLayout) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TruncateAt(android.text.TextUtils.TruncateAt)

Example 50 with StaticLayout

use of android.text.StaticLayout in project MPAndroidChart by PhilJay.

the class Utils method drawMultilineText.

public static void drawMultilineText(Canvas c, String text, float x, float y, TextPaint paint, FSize constrainedToSize, MPPointF anchor, float angleDegrees) {
    StaticLayout textLayout = new StaticLayout(text, 0, text.length(), paint, (int) Math.max(Math.ceil(constrainedToSize.width), 1.f), Layout.Alignment.ALIGN_NORMAL, 1.f, 0.f, false);
    drawMultilineText(c, textLayout, x, y, paint, anchor, angleDegrees);
}
Also used : StaticLayout(android.text.StaticLayout)

Aggregations

StaticLayout (android.text.StaticLayout)80 TextPaint (android.text.TextPaint)56 Paint (android.graphics.Paint)45 Layout (android.text.Layout)21 DynamicLayout (android.text.DynamicLayout)9 RectF (android.graphics.RectF)6 Bitmap (android.graphics.Bitmap)3 NonNull (android.support.annotation.NonNull)3 BoringLayout (android.text.BoringLayout)3 SpannableStringBuilder (android.text.SpannableStringBuilder)3 KeyEvent (android.view.KeyEvent)3 MotionEvent (android.view.MotionEvent)3 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)3 SuppressLint (android.annotation.SuppressLint)2 Canvas (android.graphics.Canvas)2 Rect (android.graphics.Rect)2 Spanned (android.text.Spanned)2 TruncateAt (android.text.TextUtils.TruncateAt)2 StyleSpan (android.text.style.StyleSpan)2 Animator (android.animation.Animator)1