Search in sources :

Example 26 with StaticLayout

use of android.text.StaticLayout in project bilibili-android-client by HotBitmapGG.

the class OutlineTextView method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Layout layout = new StaticLayout(getText(), mTextPaintOutline, measureWidth(widthMeasureSpec), Layout.Alignment.ALIGN_CENTER, mSpacingMult, mSpacingAdd, mIncludePad);
    int ex = (int) (mBorderSize * 2 + 1);
    setMeasuredDimension(measureWidth(widthMeasureSpec) + ex, measureHeight(heightMeasureSpec) * layout.getLineCount() + ex);
}
Also used : StaticLayout(android.text.StaticLayout) Layout(android.text.Layout) StaticLayout(android.text.StaticLayout) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 27 with StaticLayout

use of android.text.StaticLayout in project UltimateAndroid by cymcsg.

the class AutofitTextView method getLineCount.

private static int getLineCount(CharSequence text, TextPaint paint, float size, float width, DisplayMetrics displayMetrics) {
    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size, displayMetrics));
    StaticLayout layout = new StaticLayout(text, paint, (int) width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
    return layout.getLineCount();
}
Also used : StaticLayout(android.text.StaticLayout)

Example 28 with StaticLayout

use of android.text.StaticLayout in project Etar-Calendar by Etar-Group.

the class DayView method getEventLayout.

/**
     * Return the layout for a numbered event. Create it if not already existing
     */
private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) {
    if (i < 0 || i >= layouts.length) {
        return null;
    }
    StaticLayout layout = layouts[i];
    // re-layout of events at min height)
    if (layout == null || r.width() != layout.getWidth()) {
        SpannableStringBuilder bob = new SpannableStringBuilder();
        if (event.title != null) {
            // MAX - 1 since we add a space
            bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1));
            bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, bob.length(), 0);
            bob.append(' ');
        }
        if (event.location != null) {
            bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length()));
        }
        switch(event.selfAttendeeStatus) {
            case Attendees.ATTENDEE_STATUS_INVITED:
                paint.setColor(event.color);
                break;
            case Attendees.ATTENDEE_STATUS_DECLINED:
                paint.setColor(mEventTextColor);
                paint.setAlpha(Utils.DECLINED_EVENT_TEXT_ALPHA);
                break;
            // Your own events
            case Attendees.ATTENDEE_STATUS_NONE:
            case Attendees.ATTENDEE_STATUS_ACCEPTED:
            case Attendees.ATTENDEE_STATUS_TENTATIVE:
            default:
                paint.setColor(mEventTextColor);
                break;
        }
        // Leave a one pixel boundary on the left and right of the rectangle for the event
        layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true, null, r.width());
        layouts[i] = layout;
    }
    layout.getPaint().setAlpha(mEventsAlpha);
    return layout;
}
Also used : StyleSpan(android.text.style.StyleSpan) StaticLayout(android.text.StaticLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) TextPaint(android.text.TextPaint)

Example 29 with StaticLayout

use of android.text.StaticLayout in project weex-example by KalicyZhou.

the class WXTextDomObject method truncate.

@NonNull
public String truncate(@Nullable String source, @NonNull TextPaint paint, int desired, @Nullable TextUtils.TruncateAt truncateAt) {
    if (!TextUtils.isEmpty(source)) {
        StringBuilder builder;
        Spanned spanned;
        StaticLayout layout;
        for (int i = source.length(); i > 0; i--) {
            builder = new StringBuilder(i + 1);
            builder.append(source, 0, i);
            if (truncateAt != null) {
                builder.append(ELLIPSIS);
            }
            spanned = createSpanned(builder.toString());
            layout = new StaticLayout(spanned, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
            if (layout.getLineCount() <= 1) {
                return spanned.toString();
            }
        }
    }
    return "";
}
Also used : StaticLayout(android.text.StaticLayout) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) NonNull(android.support.annotation.NonNull)

Example 30 with StaticLayout

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

the class SubtitleView method computeMeasurements.

private boolean computeMeasurements(int maxWidth) {
    if (mHasMeasurements && maxWidth == mLastMeasuredWidth) {
        return true;
    }
    // Account for padding.
    final int paddingX = mPaddingLeft + mPaddingRight + mInnerPaddingX * 2;
    maxWidth -= paddingX;
    if (maxWidth <= 0) {
        return false;
    }
    // TODO: Implement minimum-difference line wrapping. Adding the results
    // of Paint.getTextWidths() seems to return different values than
    // StaticLayout.getWidth(), so this is non-trivial.
    mHasMeasurements = true;
    mLastMeasuredWidth = maxWidth;
    mLayout = new StaticLayout(mText, mTextPaint, maxWidth, mAlignment, mSpacingMult, mSpacingAdd, true);
    return true;
}
Also used : 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