Android Paint - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Paint class.

This code example shows how to use the following methods:setAntiAlias, setColor, setXfermode
This code example shows how to use the following methods:setAntiAlias, setColor, setStyle, setXfermode
        fillPath.addArc(circleRect, 0f, 360f);
 
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
 
        // opaque circle matte 
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawPath(fillPath, mPaint);
 
        // mask in the icon where the bitmap is opaque 
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        canvas.drawBitmap(bitmap, cropRect, circleRect, mPaint);
 
        // prepare paint for frame drawing 
        mPaint.setXfermode(null);
 
        mScale = 1f;
 

9
CodeRank
This code example shows how to use the following methods:
/** 
 * A version of {@link android.graphics.drawable.ColorDrawable} that respects bounds. 
 */ 
public class IcsColorDrawable extends Drawable {
    private int color;
    private final Paint paint = new Paint();
 
    public IcsColorDrawable(ColorDrawable drawable) {
        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bitmap);
        drawable.draw(c);
        this.color = bitmap.getPixel(0, 0);
        bitmap.recycle();
    } 
 
    public IcsColorDrawable(int color) {
        this.color = color;
    } 
 
    @Override public void draw(Canvas canvas) {
9
CodeRank
This code example shows how to use the following methods:setColor, setStyle
This code example shows how to use the following methods:measureText, setTextSize, setTypeface
     * @param view 
     * @param numberOfDigits 
     * @return number width 
     */ 
    public static int getWidth(TextView view, int numberOfDigits) {
        Paint paint = new Paint();
        paint.setTypeface(view.getTypeface());
        paint.setTextSize(view.getTextSize());
        char[] text = new char[numberOfDigits];
        Arrays.fill(text, '0');
        return Math.round(paint.measureText(text, 0, text.length));
    } 
 
    /** 
     * Get octicons typeface 
     * 
     * @param context 
     * @return octicons typeface 
     */ 
    public static Typeface getOcticons(final Context context) {
9
CodeRank
This code example shows how to use the following methods:setAntiAlias, setColor, setDither, setFilterBitmap
            radius = r;
        } 
    } 
 
    public PointCloud(Drawable drawable) {
        mPaint = new Paint();
        mPaint.setFilterBitmap(true);
        mPaint.setColor(Color.rgb(255, 255, 255)); // TODO: make configurable
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
 
        mDrawable = drawable;
        if (mDrawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        } 
    } 
 
    public void setCenter(float x, float y) {
        mCenterX = x;
        mCenterY = y;
9
CodeRank
This code example shows how to use the following methods:setAntiAlias, setColor, setTextSize
        private final Paint mHugePaint;
 
        CustomTextView(Context c) {
            super(c);
 
            mHugePaint = new Paint();
            mHugePaint.setAntiAlias(true);
            mHugePaint.setColor(0xff000000);
            mHugePaint.setTextSize(300f);
        } 
 
        @Override 
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 3000);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
9
CodeRank
This code example shows how to use the following methods:setColor, setStrokeWidth, setStyle
This code example shows how to use the following methods:setAntiAlias
    static class DrawingView extends View {
        private final Paint mPaint;
 
        DrawingView(Context c) {
            super(c);
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            canvas.save();
            canvas.translate(dipToPx(getContext(), 400), dipToPx(getContext(), 200));
            canvas.rotate(45.0f);
            canvas.drawRGB(255, 255, 255);
            mPaint.setColor(0xffff0000);
            canvas.drawRect(-80.0f, -80.0f, 80.0f, 80.0f, mPaint);
            canvas.drawRect(0.0f, 0.0f, 220.0f, 220.0f, mPaint);            
            canvas.restore();
        } 
8
CodeRank
This code example shows how to use the following methods:setAntiAlias, setFakeBoldText, setTextSize
            mHugePaint = new Paint();
            mHugePaint.setAntiAlias(true);
            mHugePaint.setColor(0xff000000);
            mHugePaint.setTextSize(300f);
 
            mEventPaint = new TextPaint();
            mEventPaint.setFakeBoldText(true);
            mEventPaint.setAntiAlias(true);
            mEventPaint.setTextSize(14);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.drawText("Hello OpenGL renderer!", 300, 20, mEventPaint);
             
            mMediumPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mMediumPaint.setStrokeWidth(2.0f);
8
CodeRank

Related Android Paint Questions & Answers:

See Code Examples for Android Paint Methods: