Search in sources :

Example 66 with TextPaint

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

the class OutlineTextView method initPaint.

private void initPaint() {
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(getTextSize());
    mTextPaint.setColor(mColor);
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setTypeface(getTypeface());
    mTextPaintOutline = new TextPaint();
    mTextPaintOutline.setAntiAlias(true);
    mTextPaintOutline.setTextSize(getTextSize());
    mTextPaintOutline.setColor(mBorderColor);
    mTextPaintOutline.setStyle(Paint.Style.STROKE);
    mTextPaintOutline.setTypeface(getTypeface());
    mTextPaintOutline.setStrokeWidth(mBorderSize);
}
Also used : TextPaint(android.text.TextPaint)

Example 67 with TextPaint

use of android.text.TextPaint in project AndroidChromium by JackyAndroid.

the class PhysicalWebOptInActivity method getDescriptionText.

private SpannableString getDescriptionText() {
    return SpanApplier.applySpans(getString(R.string.physical_web_optin_description), new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PHYSICAL_WEB_LEARN_MORE_URL));
            // Add the SESSION extra to indicate we want a Chrome custom tab. This
            // allows the help page to open in the same task as the opt-in activity so
            // they can share a back stack.
            String session = null;
            intent.putExtra(EXTRA_CUSTOM_TABS_SESSION, session);
            PhysicalWebOptInActivity.this.startActivity(intent);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            // Color links but do not underline them.
            ds.setColor(ds.linkColor);
        }
    }));
}
Also used : SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) Intent(android.content.Intent) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) TextView(android.widget.TextView) View(android.view.View) TextPaint(android.text.TextPaint)

Example 68 with TextPaint

use of android.text.TextPaint in project AndroidChromium by JackyAndroid.

the class TemplatePreservingTextView method getTruncatedText.

private CharSequence getTruncatedText(int availWidth) {
    final TextPaint paint = getPaint();
    // Calculate the width the template takes.
    final String emptyTemplate = String.format(mTemplate, "");
    final float emptyTemplateWidth = paint.measureText(emptyTemplate);
    // Calculate the available width for the content.
    final float contentWidth = Math.max(availWidth - emptyTemplateWidth, 0.f);
    // Ellipsize the content to the available width.
    CharSequence clipped = TextUtils.ellipsize(mContent, paint, contentWidth, TruncateAt.END);
    // Build the full string, which should fit within availWidth.
    return String.format(mTemplate, clipped);
}
Also used : TextPaint(android.text.TextPaint)

Example 69 with TextPaint

use of android.text.TextPaint 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 70 with TextPaint

use of android.text.TextPaint in project Notes by Elder-Wu.

the class CountDownView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();
    int min = Math.min(width, height);
    //画底盘
    canvas.drawCircle(width / 2, height / 2, min / 2, circlePaint);
    //画边框
    RectF rectF;
    if (width > height) {
        rectF = new RectF(width / 2 - min / 2 + borderWidth / 2, 0 + borderWidth / 2, width / 2 + min / 2 - borderWidth / 2, height - borderWidth / 2);
    } else {
        rectF = new RectF(borderWidth / 2, height / 2 - min / 2 + borderWidth / 2, width - borderWidth / 2, height / 2 - borderWidth / 2 + min / 2);
    }
    canvas.drawArc(rectF, -90, progress, false, borderPaint);
    //画单行居中的文字
    //       canvas.drawText("稍等片刻", width / 2, height / 2 - textPaint.descent() + textPaint.getTextSize() / 2, textPaint);
    canvas.translate(width / 2, height / 2 - staticLayout.getHeight() / 2);
    staticLayout.draw(canvas);
}
Also used : RectF(android.graphics.RectF) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

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