Search in sources :

Example 51 with TextPaint

use of android.text.TextPaint in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChartGridView method makeLabel.

private Layout makeLabel(CharSequence text) {
    final Resources res = getResources();
    final TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    paint.density = res.getDisplayMetrics().density;
    paint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);
    paint.setColor(mLabelColor);
    paint.setTextSize(mLabelSize);
    return new StaticLayout(text, paint, (int) Math.ceil(Layout.getDesiredWidth(text, paint)), Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true);
}
Also used : Resources(android.content.res.Resources) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint)

Example 52 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.

the class PackageItemInfo method loadSafeLabel.

/**
     * Same as {@link #loadLabel(PackageManager)} with the addition that
     * the returned label is safe for being presented in the UI since it
     * will not contain new lines and the length will be limited to a
     * reasonable amount. This prevents a malicious party to influence UI
     * layout via the app label misleading the user into performing a
     * detrimental for them action. If the label is too long it will be
     * truncated and ellipsized at the end.
     *
     * @param pm A PackageManager from which the label can be loaded; usually
     * the PackageManager from which you originally retrieved this item
     * @return Returns a CharSequence containing the item's label. If the
     * item does not have a label, its name is returned.
     *
     * @hide
     */
@SystemApi
@NonNull
public CharSequence loadSafeLabel(@NonNull PackageManager pm) {
    // loadLabel() always returns non-null
    String label = loadLabel(pm).toString();
    // strip HTML tags to avoid <br> and other tags overwriting original message
    String labelStr = Html.fromHtml(label).toString();
    // If the label contains new line characters it may push the UI
    // down to hide a part of it. Labels shouldn't have new line
    // characters, so just truncate at the first time one is seen.
    final int labelLength = labelStr.length();
    int offset = 0;
    while (offset < labelLength) {
        final int codePoint = labelStr.codePointAt(offset);
        final int type = Character.getType(codePoint);
        if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
            labelStr = labelStr.substring(0, offset);
            break;
        }
        // replace all non-break space to " " in order to be trimmed
        if (type == Character.SPACE_SEPARATOR) {
            labelStr = labelStr.substring(0, offset) + " " + labelStr.substring(offset + Character.charCount(codePoint));
        }
        offset += Character.charCount(codePoint);
    }
    labelStr = labelStr.trim();
    if (labelStr.isEmpty()) {
        return packageName;
    }
    TextPaint paint = new TextPaint();
    paint.setTextSize(42);
    return TextUtils.ellipsize(labelStr, paint, MAX_LABEL_SIZE_PX, TextUtils.TruncateAt.END);
}
Also used : TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint) SystemApi(android.annotation.SystemApi) NonNull(android.annotation.NonNull)

Example 53 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.

the class BiDiTestViewDrawText method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final int width = getWidth();
    final int height = getHeight();
    final TextPaint paint = new TextPaint();
    paint.setTextSize(mSize);
    paint.setColor(mColor);
    paint.setTextAlign(Align.CENTER);
    canvas.drawText(mText, width / 2, height * 2 / 3, paint);
}
Also used : TextPaint(android.text.TextPaint) TextPaint(android.text.TextPaint)

Example 54 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.

the class TextAppearanceSpan method updateMeasureState.

@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;
        if (tf != null) {
            style = tf.getStyle();
        }
        style |= mStyle;
        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }
        int fake = style & ~tf.getStyle();
        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }
        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }
        ds.setTypeface(tf);
    }
    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
Also used : Typeface(android.graphics.Typeface) TextPaint(android.text.TextPaint)

Example 55 with TextPaint

use of android.text.TextPaint in project android_frameworks_base by ResurrectionRemix.

the class SubtitleView method onDraw.

@Override
protected void onDraw(Canvas c) {
    final StaticLayout layout = mLayout;
    if (layout == null) {
        return;
    }
    final int saveCount = c.save();
    final int innerPaddingX = mInnerPaddingX;
    c.translate(mPaddingLeft + innerPaddingX, mPaddingTop);
    final int lineCount = layout.getLineCount();
    final Paint textPaint = mTextPaint;
    final Paint paint = mPaint;
    final RectF bounds = mLineBounds;
    if (Color.alpha(mBackgroundColor) > 0) {
        final float cornerRadius = mCornerRadius;
        float previousBottom = layout.getLineTop(0);
        paint.setColor(mBackgroundColor);
        paint.setStyle(Style.FILL);
        for (int i = 0; i < lineCount; i++) {
            bounds.left = layout.getLineLeft(i) - innerPaddingX;
            bounds.right = layout.getLineRight(i) + innerPaddingX;
            bounds.top = previousBottom;
            bounds.bottom = layout.getLineBottom(i);
            previousBottom = bounds.bottom;
            c.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
        }
    }
    final int edgeType = mEdgeType;
    if (edgeType == CaptionStyle.EDGE_TYPE_OUTLINE) {
        textPaint.setStrokeJoin(Join.ROUND);
        textPaint.setStrokeWidth(mOutlineWidth);
        textPaint.setColor(mEdgeColor);
        textPaint.setStyle(Style.FILL_AND_STROKE);
        for (int i = 0; i < lineCount; i++) {
            layout.drawText(c, i, i);
        }
    } else if (edgeType == CaptionStyle.EDGE_TYPE_DROP_SHADOW) {
        textPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mEdgeColor);
    } else if (edgeType == CaptionStyle.EDGE_TYPE_RAISED || edgeType == CaptionStyle.EDGE_TYPE_DEPRESSED) {
        final boolean raised = edgeType == CaptionStyle.EDGE_TYPE_RAISED;
        final int colorUp = raised ? Color.WHITE : mEdgeColor;
        final int colorDown = raised ? mEdgeColor : Color.WHITE;
        final float offset = mShadowRadius / 2f;
        textPaint.setColor(mForegroundColor);
        textPaint.setStyle(Style.FILL);
        textPaint.setShadowLayer(mShadowRadius, -offset, -offset, colorUp);
        for (int i = 0; i < lineCount; i++) {
            layout.drawText(c, i, i);
        }
        textPaint.setShadowLayer(mShadowRadius, offset, offset, colorDown);
    }
    textPaint.setColor(mForegroundColor);
    textPaint.setStyle(Style.FILL);
    for (int i = 0; i < lineCount; i++) {
        layout.drawText(c, i, i);
    }
    textPaint.setShadowLayer(0, 0, 0, 0);
    c.restoreToCount(saveCount);
}
Also used : RectF(android.graphics.RectF) StaticLayout(android.text.StaticLayout) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) 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