当前位置: 首页>>代码示例>>Java>>正文


Java TextPaint类代码示例

本文整理汇总了Java中android.text.TextPaint的典型用法代码示例。如果您正苦于以下问题:Java TextPaint类的具体用法?Java TextPaint怎么用?Java TextPaint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TextPaint类属于android.text包,在下文中一共展示了TextPaint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTextWidth

import android.text.TextPaint; //导入依赖的package包/类
private static int getTextWidth(@Nullable final CharSequence text, final TextPaint paint) {
    if (TextUtils.isEmpty(text)) {
        return 0;
    }
    final int length = text.length();
    final float[] widths = new float[length];
    final int count;
    final Typeface savedTypeface = paint.getTypeface();
    try {
        paint.setTypeface(getTextTypeface(text));
        count = paint.getTextWidths(text, 0, length, widths);
    } finally {
        paint.setTypeface(savedTypeface);
    }
    int width = 0;
    for (int i = 0; i < count; i++) {
        width += Math.round(widths[i] + 0.5f);
    }
    return width;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:21,代码来源:SuggestionStripLayoutHelper.java

示例2: createUnrestrictedLayout

import android.text.TextPaint; //导入依赖的package包/类
private static Layout createUnrestrictedLayout(@Nonnull TextView view) {
    CharSequence text = view.getText();
    Layout layout = view.getLayout();
    TextPaint paint = layout.getPaint();

    if (SDK_INT >= M) {
        return StaticLayout.Builder
                .obtain(text, 0, text.length(), layout.getPaint(), layout.getWidth())
                .setAlignment(layout.getAlignment())
                .setLineSpacing(view.getLineSpacingExtra(), view.getLineSpacingMultiplier())
                .setIncludePad(view.getIncludeFontPadding())
                .setBreakStrategy(view.getBreakStrategy())
                .setHyphenationFrequency(view.getHyphenationFrequency())
                .build();
    } else {
        return new StaticLayout(
                text,
                paint,
                text.length(),
                layout.getAlignment(),
                view.getLineSpacingMultiplier(),
                view.getLineSpacingExtra(),
                view.getIncludeFontPadding());
    }
}
 
开发者ID:shazam,项目名称:reflow-animator,代码行数:26,代码来源:ReflowTextAnimatorHelper.java

示例3: createContent

import android.text.TextPaint; //导入依赖的package包/类
@Override
public void createContent(InfoBarLayout layout) {
    super.createContent(layout);
    SpannableString message = new SpannableString(mMessageText);
    message.setSpan(
            new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    onLinkClicked();
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);
                }
            }, mInlineLinkRangeStart, mInlineLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    layout.setMessage(message);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:20,代码来源:SearchGeolocationDisclosureInfoBar.java

示例4: onDraw

import android.text.TextPaint; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    TextPaint textPaint = getPaint();
    textPaint.setColor(getCurrentTextColor());
    textPaint.drawableState = getDrawableState();

    canvas.save();

    if (topDown) {
        canvas.translate(getWidth(), 0);
        canvas.rotate(90);
    } else {
        canvas.translate(0, getHeight());
        canvas.rotate(-90);
    }

    canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());

    getLayout().draw(canvas);
    canvas.restore();
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:22,代码来源:VerticalTextView.java

示例5: PendingAppWidgetHostView

import android.text.TextPaint; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public PendingAppWidgetHostView(Context context, LauncherAppWidgetInfo info,
        boolean disabledForSafeMode) {
    super(new ContextThemeWrapper(context, R.style.WidgetContainerTheme));

    mLauncher = Launcher.getLauncher(context);
    mInfo = info;
    mStartState = info.restoreStatus;
    mIconLookupIntent = new Intent().setComponent(info.providerName);
    mDisabledForSafeMode = disabledForSafeMode;

    mPaint = new TextPaint();
    mPaint.setColor(0xFFFFFFFF);
    mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            mLauncher.getDeviceProfile().iconTextSizePx, getResources().getDisplayMetrics()));
    setBackgroundResource(R.drawable.quantum_panel_dark);
    setWillNotDraw(false);

    if (Utilities.ATLEAST_LOLLIPOP) {
        setElevation(getResources().getDimension(R.dimen.pending_widget_elevation));
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:23,代码来源:PendingAppWidgetHostView.java

示例6: initPaintObjects

import android.text.TextPaint; //导入依赖的package包/类
private void initPaintObjects() {

        int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);

        textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setTextSize(labelTextSize);
        if (typeface != null) {
            textPaint.setTypeface(typeface);
        }
        textPaint.setColor(baseColor);
        baseAlpha = textPaint.getAlpha();

        selectorPath = new Path();
        selectorPath.setFillType(Path.FillType.EVEN_ODD);

        selectorPoints = new Point[3];
        for (int i = 0; i < 3; i++) {
            selectorPoints[i] = new Point();
        }
    }
 
开发者ID:mityung,项目名称:XERUNG,代码行数:23,代码来源:MaterialSpinner.java

示例7: generateStaticLayout

import android.text.TextPaint; //导入依赖的package包/类
public static StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
    int addedChars = 0;
    StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    for (int a = 0; a < linesCount; a++) {
        Layout.Directions directions = layout.getLineDirections(a);
        if (layout.getLineLeft(a) != 0 || layout.isRtlCharAt(layout.getLineStart(a)) || layout.isRtlCharAt(layout.getLineEnd(a))) {
            maxWidth = smallWidth;
        }
        int pos = layout.getLineEnd(a);
        if (pos == text.length()) {
            break;
        }
        pos--;
        if (stringBuilder.charAt(pos + addedChars) == ' ') {
            stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
        } else if (stringBuilder.charAt(pos + addedChars) != '\n') {
            stringBuilder.insert(pos + addedChars, "\n");
            addedChars++;
        }
        if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
            break;
        }
    }
    return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:27,代码来源:ChatMessageCell.java

示例8: init

import android.text.TextPaint; //导入依赖的package包/类
private void init() {
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setColor(mTextColor);
    if (mTextSizePx <= 0) {
        mTextSizePx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                DEFAULT_FONT_SIZE_SP, getResources().getDisplayMetrics());
    }
    mTextPaint.setTextSize(mTextSizePx);
    mTypeface = MongolFont.get(MongolFont.QAGAN, mContext);
    mTextPaint.setTypeface(mTypeface);
    mTextPaint.linkColor = Color.BLUE;

    // initialize the layout, but the height still needs to be set
    final CharSequence text = mTextStorage.getGlyphText();
    mLayout = new MongolLayout(text, 0, text.length(), mTextPaint, 0, Gravity.TOP, 1, 0, false, Integer.MAX_VALUE);

}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:19,代码来源:MongolTextView.java

示例9: TextRun

import android.text.TextPaint; //导入依赖的package包/类
TextRun(int offset, int length, boolean isRotated, boolean isSpanned) {

            this.offset = offset;
            this.length = length;
            this.isRotated = isRotated;

            TextPaint wp;
            if (isSpanned) {
                wp = mWorkPaint;
                wp.set(mPaint);
                MetricAffectingSpan[] spans = ((Spanned) mText).getSpans(offset, offset + length, MetricAffectingSpan.class);
                for(MetricAffectingSpan span : spans) {
                    span.updateDrawState(wp);
                }
            } else {
                wp = mPaint;
            }

            // just record the normal non-rotated values here
            // measure and draw will take rotation into account
            measuredWidth = wp.measureText(mText, offset, offset + length);
            measuredHeight = wp.getFontMetrics().bottom - wp.getFontMetrics().top;
        }
 
开发者ID:suragch,项目名称:mongol-library,代码行数:24,代码来源:MongolTextLine.java

示例10: getOverlayBitmap2

import android.text.TextPaint; //导入依赖的package包/类
public static Bitmap getOverlayBitmap2(Context context, Bitmap bitmap, String text) {
    Bitmap result = bitmap.copy(bitmap.getConfig(), true);
    float scale = context.getResources().getDisplayMetrics().density;
    Canvas canvas = new Canvas(result);

    TextPaint mTextPaint = new TextPaint();
    mTextPaint.setTextSize((int) (12 * scale));
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setAlpha(204);
    mTextPaint.setShadowLayer(5f, 0f, 1f, Color.DKGRAY);

    StaticLayout mTextLayout = new StaticLayout(text, mTextPaint, canvas.getWidth() - Util.dpToPx(87), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.3f, true);
    canvas.save();

    float textX = (canvas.getWidth() / 2) - (mTextLayout.getWidth() / 2);
    float textY = result.getHeight() - Util.dpToPx(72);

    canvas.translate(textX, textY);
    mTextLayout.draw(canvas);
    canvas.restore();
    return result;
}
 
开发者ID:SinsangMarket,项目名称:ASS,代码行数:23,代码来源:Util.java

示例11: initPaint

import android.text.TextPaint; //导入依赖的package包/类
/**
 * define paints
 */
private void initPaint() {
    // round rectangle paint
    mStrokePaint = new Paint();
    mStrokePaint.setColor(mSelectedColor);
    mStrokePaint.setStyle(Paint.Style.STROKE);
    mStrokePaint.setAntiAlias(true);
    mStrokePaint.setStrokeWidth(mStrokeWidth);
    // selected paint
    mFillPaint = new Paint();
    mFillPaint.setColor(mSelectedColor);
    mFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mStrokePaint.setAntiAlias(true);
    // selected text paint
    mSelectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mSelectedTextPaint.setTextSize(mTextSize);
    mSelectedTextPaint.setColor(mSelectedColor);
    mStrokePaint.setAntiAlias(true);
    // unselected text paint
    mUnselectedTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mUnselectedTextPaint.setTextSize(mTextSize);
    mUnselectedTextPaint.setColor(0xffffffff);
    mStrokePaint.setAntiAlias(true);
    mTextHeightOffset = -(mSelectedTextPaint.ascent() + mSelectedTextPaint.descent()) * 0.5f;
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:28,代码来源:SwitchMultiButton.java

示例12: init

import android.text.TextPaint; //导入依赖的package包/类
private void init() {
    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    if (mTextSizePx <= 0) {
        mTextSizePx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                DEFAULT_FONT_SIZE_SP, getResources().getDisplayMetrics());
    }
    mTextPaint.setTextSize(mTextSizePx);
    mTextPaint.setColor(mTextColor);
    mTypeface = MongolFont.get(MongolFont.QAGAN, mContext);
    mTextPaint.setTypeface(mTypeface);
    mRenderer = MongolCode.INSTANCE;
    if (mUnicodeText == null) {
        mUnicodeText = "";
    }
    mGlyphText = mRenderer.unicodeToMenksoft(mUnicodeText);
}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:18,代码来源:MongolLabel.java

示例13: onDraw

import android.text.TextPaint; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas){
    TextPaint textPaint = getPaint();
    textPaint.setColor(getCurrentTextColor());
    textPaint.drawableState = getDrawableState();

    canvas.save();

    if(topDown){
        canvas.translate(getWidth(), 0);
        canvas.rotate(90);
    }else {
        canvas.translate(0, getHeight());
        canvas.rotate(-90);
    }


    canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());

    getLayout().draw(canvas);
    canvas.restore();
}
 
开发者ID:andresth,项目名称:Kandroid,代码行数:23,代码来源:VerticalTextView.java

示例14: AboutLinkCell

import android.text.TextPaint; //导入依赖的package包/类
public AboutLinkCell(Context context) {
    super(context);

    textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(AndroidUtilities.dp(16));
    textPaint.setColor(0xff000000);
    textPaint.linkColor = Theme.MSG_LINK_TEXT_COLOR;
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

    urlPaint = new Paint();
    urlPaint.setColor(Theme.MSG_LINK_SELECT_BACKGROUND_COLOR);
    urlPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 16, 5, LocaleController.isRTL ? 16 : 0, 0));
    setWillNotDraw(false);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:19,代码来源:AboutLinkCell.java

示例15: addTab

import android.text.TextPaint; //导入依赖的package包/类
/**
 * 添加指示器
 *
 * @param position
 * @param title
 */
private void addTab(final int position, CharSequence title) {
    TextView tvTab = new TextView(context);
    tvTab.setText(title);
    tvTab.setTextColor(textColor);
    tvTab.setTextSize(textSize);
    tvTab.setGravity(Gravity.CENTER);
    if(isIndicatorTextBold){
        TextPaint tp = tvTab.getPaint();
        tp.setFakeBoldText(true);
    }
    tvTab.setSingleLine();
    tvTab.setFocusable(true);
    tvTab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(position);
        }
    });
    tvTab.setPadding(indicatorMargin, 0, indicatorMargin, 0);
    container.addView(tvTab, position, expandedTabLayoutParams);
}
 
开发者ID:xfangfang,项目名称:NeuTV,代码行数:28,代码来源:TabStrip.java


注:本文中的android.text.TextPaint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。