Search in sources :

Example 61 with TextPaint

use of android.text.TextPaint in project DanmakuFlameMaster by Bilibili.

the class ViewCacheStuffer method measure.

@Override
public void measure(BaseDanmaku danmaku, TextPaint paint, boolean fromWorkerThread) {
    int viewType = getItemViewType(danmaku.index, danmaku);
    List<VH> viewHolders = mViewHolderArray.get(viewType);
    if (viewHolders == null) {
        viewHolders = new ArrayList<>();
        viewHolders.add(onCreateViewHolder(viewType));
        viewHolders.add(onCreateViewHolder(viewType));
        viewHolders.add(onCreateViewHolder(viewType));
        mViewHolderArray.put(viewType, viewHolders);
    }
    VH viewHolder = viewHolders.get(0);
    // TODO displayerConfig or TextPaint
    onBindViewHolder(viewType, viewHolder, danmaku, null, paint);
    viewHolder.measure(View.MeasureSpec.makeMeasureSpec(mMaximumWidthPixels, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(mMaximumHeightPixels, View.MeasureSpec.AT_MOST));
    viewHolder.layout(0, 0, viewHolder.getMeasureWidth(), viewHolder.getMeasureHeight());
    danmaku.paintWidth = viewHolder.getMeasureWidth();
    danmaku.paintHeight = viewHolder.getMeasureHeight();
}
Also used : TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 62 with TextPaint

use of android.text.TextPaint in project Android-Bootstrap by Bearded-Hen.

the class BootstrapDrawableFactory method createBadgeDrawable.

public static Drawable createBadgeDrawable(Context context, BootstrapBrand brand, int width, int height, String badgeText, boolean insideAnObject) {
    if (badgeText == null) {
        return null;
    } else {
        Paint badgePaint = new Paint();
        Rect canvasBounds = new Rect();
        TextPaint badgeTextPaint = new TextPaint();
        badgePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        badgeTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        badgeTextPaint.setTextAlign(Paint.Align.CENTER);
        badgeTextPaint.setTextSize((float) (height * 0.7));
        if (insideAnObject) {
            badgePaint.setColor(brand.defaultTextColor(context));
            badgeTextPaint.setColor(brand.defaultFill(context));
        } else {
            badgePaint.setColor(brand.defaultFill(context));
            badgeTextPaint.setColor(brand.defaultTextColor(context));
        }
        int rectLength = (int) badgeTextPaint.measureText(badgeText);
        Bitmap canvasBitmap = Bitmap.createBitmap(width + rectLength, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(canvasBitmap);
        canvas.getClipBounds(canvasBounds);
        int firstCircleDx = canvasBounds.left + canvasBounds.height() / 2;
        int circleDy = canvasBounds.height() / 2;
        int circleRadius = canvasBounds.height() / 2;
        int secondCircleDx = firstCircleDx + rectLength;
        Rect rect = new Rect();
        rect.left = firstCircleDx;
        rect.top = 0;
        rect.right = rect.left + rectLength;
        rect.bottom = canvasBounds.height();
        canvas.drawCircle(firstCircleDx, circleDy, circleRadius, badgePaint);
        canvas.drawRect(rect, badgePaint);
        canvas.drawCircle(secondCircleDx, circleDy, circleRadius, badgePaint);
        canvas.drawText(badgeText, canvasBounds.width() / 2, canvasBounds.height() / 2 - ((badgeTextPaint.descent() + badgeTextPaint.ascent()) / 2), badgeTextPaint);
        return new BitmapDrawable(context.getResources(), canvasBitmap);
    }
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Example 63 with TextPaint

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

the class RegionTypeDetailsActivity method measureTabLayoutTextWidth.

public void measureTabLayoutTextWidth(int position) {
    String titleName = titles.get(position);
    TextView titleView = mSlidingTab.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float v = paint.measureText(titleName);
    mSlidingTab.setIndicatorWidth(v / 3);
}
Also used : TextView(android.widget.TextView) TextPaint(android.text.TextPaint)

Example 64 with TextPaint

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

the class VideoDetailsActivity method measureTabLayoutTextWidth.

private void measureTabLayoutTextWidth(int position) {
    String title = titles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
Also used : TextView(android.widget.TextView) TextPaint(android.text.TextPaint)

Example 65 with TextPaint

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

the class TotalStationSearchActivity method measureTabLayoutTextWidth.

private void measureTabLayoutTextWidth(int position) {
    String title = titles.get(position);
    TextView titleView = mSlidingTabLayout.getTitleView(position);
    TextPaint paint = titleView.getPaint();
    float textWidth = paint.measureText(title);
    mSlidingTabLayout.setIndicatorWidth(textWidth / 3);
}
Also used : TextView(android.widget.TextView) RxTextView(com.jakewharton.rxbinding.widget.RxTextView) TextPaint(android.text.TextPaint)

Aggregations

TextPaint (android.text.TextPaint)216 Paint (android.graphics.Paint)86 StaticLayout (android.text.StaticLayout)29 View (android.view.View)17 Bitmap (android.graphics.Bitmap)14 Typeface (android.graphics.Typeface)14 TypedArray (android.content.res.TypedArray)12 SpannableString (android.text.SpannableString)12 RectF (android.graphics.RectF)11 Spanned (android.text.Spanned)11 TextView (android.widget.TextView)11 Rect (android.graphics.Rect)8 StyleSpan (android.text.style.StyleSpan)8 ClickableSpan (android.text.style.ClickableSpan)7 PackageManager (android.content.pm.PackageManager)6 Canvas (android.graphics.Canvas)6 IBinder (android.os.IBinder)6 SpannableStringBuilder (android.text.SpannableStringBuilder)6 Context (android.content.Context)5 Resources (android.content.res.Resources)5