Java Code Examples for android.text.TextPaint#setShadowLayer()

The following examples show how to use android.text.TextPaint#setShadowLayer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidDisplayer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
public TextPaint getPaint(BaseDanmaku danmaku, boolean fromWorkerThread) {
    TextPaint paint;
    if (fromWorkerThread) {
        paint = PAINT;
    } else {
        paint = PAINT_DUPLICATE;
        paint.set(PAINT);
    }
    paint.setTextSize(danmaku.textSize);
    applyTextScaleConfig(danmaku, paint);

    //ignore the transparent textShadowColor
    if (!HAS_SHADOW || SHADOW_RADIUS <= 0 || danmaku.textShadowColor == 0) {
        paint.clearShadowLayer();
    } else {
        paint.setShadowLayer(SHADOW_RADIUS, 0, 0, danmaku.textShadowColor);
    }
    paint.setAntiAlias(ANTI_ALIAS);
    return paint;
}
 
Example 2
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 6 votes vote down vote up
private synchronized TextPaint getPaint(BaseDanmaku danmaku, boolean quick) {
    TextPaint paint;
    if (quick) {
        paint = this.PAINT_DUPLICATE;
        paint.set(this.PAINT);
    } else {
        paint = this.PAINT;
    }
    paint.reset();
    paint.setTextSize(danmaku.textSize);
    applyTextScaleConfig(danmaku, paint);
    if (!this.HAS_SHADOW || this.SHADOW_RADIUS <= 0.0f || danmaku.textShadowColor == 0) {
        paint.clearShadowLayer();
    } else {
        paint.setShadowLayer(this.SHADOW_RADIUS, 0.0f, 0.0f, danmaku.textShadowColor);
    }
    paint.setAntiAlias(this.ANTI_ALIAS);
    return paint;
}
 
Example 3
Source File: TextAppearance.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Applies the attributes that affect drawing from TextAppearance to the given TextPaint. Note
 * that not all attributes can be applied to the TextPaint.
 *
 * @see android.text.style.TextAppearanceSpan#updateDrawState(TextPaint)
 */
public void updateDrawState(
    @NonNull Context context,
    @NonNull TextPaint textPaint,
    @NonNull TextAppearanceFontCallback callback) {
  updateMeasureState(context, textPaint, callback);

  textPaint.setColor(
      textColor != null
          ? textColor.getColorForState(textPaint.drawableState, textColor.getDefaultColor())
          : Color.BLACK);
  textPaint.setShadowLayer(
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor != null
          ? shadowColor.getColorForState(textPaint.drawableState, shadowColor.getDefaultColor())
          : Color.TRANSPARENT);
}
 
Example 4
Source File: ZGDanmakuItem.java    From ZGDanmaku with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化画笔
 */
private void initDefaultPainters() {
    mCanvas = new Canvas();

    mPainter = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mPainter.setColor(0xFFFFFFFF);
    mPainter.setTextAlign(Paint.Align.LEFT);
    mPainter.setTextSize(DimensUtils.sp2pixel(mContext, mTextSize));

    mStrokePainter = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mStrokePainter.setColor(0xFF000000);
    mStrokePainter.setTextAlign(Paint.Align.LEFT);
    mStrokePainter.setStyle(Paint.Style.STROKE);
    mStrokePainter.setStrokeWidth(3.0f);
    mStrokePainter.setShadowLayer(3, 0, 0, 0xFF000000);
    mStrokePainter.setTextSize(DimensUtils.sp2pixel(mContext, mTextSize));
}
 
Example 5
Source File: StringTexture.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
public static TextPaint getDefaultPaint(float textSize, int color, boolean hasShadow) {
    TextPaint paint = new TextPaint();
    paint.setTextSize(textSize);
    paint.setAntiAlias(true);
    paint.setColor(color);
    if (hasShadow) {
        paint.setShadowLayer(2f, 0f, 0f, Color.BLACK);
    }
    return paint;
}
 
Example 6
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(final TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 7
Source File: ShadowStyleSpan.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint textPaint) {
  textPaint.setShadowLayer(mRadius, mDx, mDy, mColor);
}
 
Example 8
Source File: BitmapUtils.java    From AndroidWM with Apache License 2.0 4 votes vote down vote up
/**
 * build a bitmap from a text.
 *
 * @return {@link Bitmap} the bitmap return.
 */
public static Bitmap textAsBitmap(Context context, WatermarkText watermarkText) {
    TextPaint watermarkPaint = new TextPaint();
    watermarkPaint.setColor(watermarkText.getTextColor());
    watermarkPaint.setStyle(watermarkText.getTextStyle());

    if (watermarkText.getTextAlpha() >= 0 && watermarkText.getTextAlpha() <= 255) {
        watermarkPaint.setAlpha(watermarkText.getTextAlpha());
    }

    float value = (float) watermarkText.getTextSize();
    int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            value, context.getResources().getDisplayMetrics());
    watermarkPaint.setTextSize(pixel);

    if (watermarkText.getTextShadowBlurRadius() != 0
            || watermarkText.getTextShadowXOffset() != 0
            || watermarkText.getTextShadowYOffset() != 0) {
        watermarkPaint.setShadowLayer(watermarkText.getTextShadowBlurRadius(),
                watermarkText.getTextShadowXOffset(),
                watermarkText.getTextShadowYOffset(),
                watermarkText.getTextShadowColor());
    }

    if (watermarkText.getTextFont() != 0) {
        Typeface typeface = ResourcesCompat.getFont(context, watermarkText.getTextFont());
        watermarkPaint.setTypeface(typeface);
    }

    watermarkPaint.setAntiAlias(true);
    watermarkPaint.setTextAlign(Paint.Align.LEFT);
    watermarkPaint.setStrokeWidth(5);

    float baseline = (int) (-watermarkPaint.ascent() + 1f);
    Rect bounds = new Rect();
    watermarkPaint.getTextBounds(watermarkText.getText(),
            0, watermarkText.getText().length(), bounds);

    int boundWidth = bounds.width() + 20;
    int mTextMaxWidth = (int) watermarkPaint.measureText(watermarkText.getText());
    if (boundWidth > mTextMaxWidth) {
        boundWidth = mTextMaxWidth;
    }
    StaticLayout staticLayout = new StaticLayout(watermarkText.getText(),
            0, watermarkText.getText().length(),
            watermarkPaint, mTextMaxWidth, android.text.Layout.Alignment.ALIGN_NORMAL, 2.0f,
            2.0f, false);

    int lineCount = staticLayout.getLineCount();
    int height = (int) (baseline + watermarkPaint.descent() + 3) * lineCount;
    Bitmap image = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    if (boundWidth > 0 && height > 0) {
        image = Bitmap.createBitmap(boundWidth, height, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(image);
    canvas.drawColor(watermarkText.getBackgroundColor());
    staticLayout.draw(canvas);
    return image;
}
 
Example 9
Source File: SpanUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(final TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 10
Source File: TitleBitmapFactory.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * @param context   The current Android's context.
 * @param incognito Whether the title are for incognito mode.
 * @param nullFaviconResourceId A drawable resource id of a default favicon.
 */
public TitleBitmapFactory(Context context, boolean incognito, int nullFaviconResourceId) {
    mNullFaviconResourceId = nullFaviconResourceId;

    Resources res = context.getResources();
    int textColor = ApiCompatibilityUtils.getColor(res, incognito
            ? R.color.compositor_tab_title_bar_text_incognito
            : R.color.compositor_tab_title_bar_text);
    int shadowColor = ApiCompatibilityUtils.getColor(res, incognito
            ? R.color.compositor_tab_title_bar_shadow_incognito
            : R.color.compositor_tab_title_bar_shadow);
    int shadowXOffset = res.getDimensionPixelOffset(incognito
            ? R.dimen.compositor_tab_title_bar_shadow_x_offset_incognito
            : R.dimen.compositor_tab_title_bar_shadow_x_offset);
    int shadowYOffset = res.getDimensionPixelOffset(incognito
            ? R.dimen.compositor_tab_title_bar_shadow_y_offset_incognito
            : R.dimen.compositor_tab_title_bar_shadow_y_offset);
    float textSize = res.getDimension(R.dimen.compositor_tab_title_text_size);

    boolean fakeBoldText = res.getBoolean(R.bool.compositor_tab_title_fake_bold_text);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(textColor);
    if (shadowXOffset != 0 && shadowYOffset != 0) {
        mTextPaint.setShadowLayer(0.001f, shadowXOffset, shadowYOffset, shadowColor);
    }
    mTextPaint.setTextSize(textSize);
    mTextPaint.setFakeBoldText(fakeBoldText);
    mTextPaint.density = res.getDisplayMetrics().density;

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;

    mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_title_favicon_size);
    mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight);

    int width = res.getDisplayMetrics().widthPixels;
    int height = res.getDisplayMetrics().heightPixels;
    mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height));

    // Set the favicon dimension here.
    mFaviconDimension = Math.min(mMaxWidth, mFaviconDimension);
}
 
Example 11
Source File: DialogEditVanityLength.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, color);
}
 
Example 12
Source File: DialogFragmentFancyQrCodePager.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, color);
}