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

The following are Jave code examples for showing how to use setShadowLayer() of the android.text.TextPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ASS   File: Util.java   Source Code and License Vote up 6 votes
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;
}
 
Example 2
Project: letv   File: AndroidDisplayer.java   Source Code and License Vote up 6 votes
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
Project: live_master   File: AndroidDisplayer.java   Source Code and License Vote up 6 votes
private synchronized 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 4
Project: GitHub   File: ShadowSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 5
Project: GitHub   File: SpanUtils.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(final TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 6
Project: AndroidUtilCode-master   File: ShadowSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 7
Project: AndroidUtilCode-master   File: SpanUtils.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 8
Project: GSLayout   File: GSShadowSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, color);
}
 
Example 9
Project: aos-Video   File: TextShadowSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, color);
}
 
Example 10
Project: HeadlineNews   File: SpanUtils.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(final TextPaint tp) {
    tp.setShadowLayer(radius, dx, dy, shadowColor);
}
 
Example 11
Project: RNLearn_Project1   File: ShadowStyleSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint textPaint) {
  textPaint.setShadowLayer(mRadius, mDx, mDy, mColor);
}
 
Example 12
Project: RNLearn_Project1   File: ShadowStyleSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint textPaint) {
  textPaint.setShadowLayer(mRadius, mDx, mDy, mColor);
}
 
Example 13
Project: RNLearn_Project1   File: ShadowStyleSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint textPaint) {
  textPaint.setShadowLayer(mRadius, mDx, mDy, mColor);
}
 
Example 14
Project: RNLearn_Project1   File: ShadowStyleSpan.java   Source Code and License Vote up 4 votes
@Override
public void updateDrawState(TextPaint textPaint) {
  textPaint.setShadowLayer(mRadius, mDx, mDy, mColor);
}
 
Example 15
Project: AndroRW   File: MyService.java   Source Code and License Vote up 4 votes
public Bitmap drawMultilineTextToBitmap(Bitmap bitmap, String gText) {
    int scale = 1;
    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }
    // resource bitmaps are imutable,
    // so we need to convert it to mutable one
    bitmap = bitmap.copy(bitmapConfig, true);

    Canvas canvas = new Canvas(bitmap);

    // new antialiased Paint
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    // text color - #3D3D3D
    paint.setColor(Color.rgb(61, 61, 61));
    // text size in pixels
    paint.setTextSize(14 * scale);
    // text shadow
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    // set text width to canvas width minus 16dp padding
    int textWidth = canvas.getWidth() - 16 * scale;

    // init StaticLayout for text
    StaticLayout textLayout = new StaticLayout(
            gText, paint, textWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);

    // get height of multiline text
    int textHeight = textLayout.getHeight();

    // get position of text's top left corner
    float x = (bitmap.getWidth() - textWidth) / 2;
    float y = (bitmap.getHeight() - textHeight) / 2;

    // draw text to the Canvas center
    canvas.save();
    canvas.translate(x, y);
    textLayout.draw(canvas);
    canvas.restore();

    return bitmap;
}