Search in sources :

Example 51 with StaticLayout

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

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 52 with StaticLayout

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

the class ReflowText method createLayout.

private Layout createLayout(ReflowData data, Context context, boolean enforceMaxLines) {
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(data.textSize);
    paint.setColor(data.textColor);
    paint.setLetterSpacing(data.letterSpacing);
    if (data.fontName != null) {
        paint.setTypeface(FontUtil.get(context, data.fontName));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(data.text, 0, data.text.length(), paint, data.textWidth).setLineSpacing(data.lineSpacingAdd, data.lineSpacingMult).setBreakStrategy(data.breakStrategy);
        if (enforceMaxLines && data.maxLines != -1) {
            builder.setMaxLines(data.maxLines);
            builder.setEllipsize(TextUtils.TruncateAt.END);
        }
        return builder.build();
    } else {
        return new StaticLayout(data.text, paint, data.textWidth, Layout.Alignment.ALIGN_NORMAL, data.lineSpacingMult, data.lineSpacingAdd, true);
    }
}
Also used : StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint)

Example 53 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 54 with StaticLayout

use of android.text.StaticLayout in project MaterialEditText by rengwuxian.

the class MaterialEditText method adjustBottomLines.

/**
   * @return True, if adjustments were made that require the view to be invalidated.
   */
private boolean adjustBottomLines() {
    // Bail out if we have a zero width; lines will be adjusted during next layout.
    if (getWidth() == 0) {
        return false;
    }
    int destBottomLines;
    textPaint.setTextSize(bottomTextSize);
    if (tempErrorText != null || helperText != null) {
        Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
        textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
        destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
    } else {
        destBottomLines = minBottomLines;
    }
    if (bottomLines != destBottomLines) {
        getBottomLinesAnimator(destBottomLines).start();
    }
    bottomLines = destBottomLines;
    return true;
}
Also used : StaticLayout(android.text.StaticLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 55 with StaticLayout

use of android.text.StaticLayout in project MaterialEditText by rengwuxian.

the class MaterialMultiAutoCompleteTextView method adjustBottomLines.

/**
   * @return True, if adjustments were made that require the view to be invalidated.
   */
private boolean adjustBottomLines() {
    // Bail out if we have a zero width; lines will be adjusted during next layout.
    if (getWidth() == 0) {
        return false;
    }
    int destBottomLines;
    textPaint.setTextSize(bottomTextSize);
    if (tempErrorText != null || helperText != null) {
        Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ? Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
        textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
        destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
    } else {
        destBottomLines = minBottomLines;
    }
    if (bottomLines != destBottomLines) {
        getBottomLinesAnimator(destBottomLines).start();
    }
    bottomLines = destBottomLines;
    return true;
}
Also used : StaticLayout(android.text.StaticLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

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