Example usage for android.graphics Paint setColor

List of usage examples for android.graphics Paint setColor

Introduction

In this page you can find the example usage for android.graphics Paint setColor.

Prototype

public void setColor(@ColorInt int color) 

Source Link

Document

Set the paint's color.

Usage

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @return/*w w w . j a v a 2s . c  o  m*/
 */
private Picture drawBarreds() {
    Picture pictureContent = new Picture();
    Canvas canvasContent = pictureContent.beginRecording(getWidth(), getHeight());
    Paint paintContent = new Paint(Paint.ANTI_ALIAS_FLAG);
    canvasContent.save();

    paintContent.setColor(Color.BLUE);
    paintContent.setStyle(Style.STROKE);
    paintContent.setStrokeWidth(2);
    paintContent.setAlpha(50);

    try {
        cellDimension = block.getCellDimension();
        JSONArray barred = block.getBarred();

        int rows = block.getShape().getInt(0);
        int cols = block.getShape().getInt(1);

        // this code draws all the shape:
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {

                canvasContent.drawRect(cellDimension * j, cellDimension * i, cellDimension * j + cellDimension,
                        cellDimension * i + cellDimension, paintContent);
            }
        }
        paintContent.setColor(Color.RED);
        paintContent.setStyle(Style.FILL);
        paintContent.setAlpha(50);

        for (int i = 0; i < barred.length(); i++) {
            JSONArray pos = barred.getJSONArray(i);
            canvasContent.drawRect(cellDimension * pos.getInt(1), cellDimension * pos.getInt(0),
                    cellDimension * pos.getInt(1) + cellDimension,
                    cellDimension * pos.getInt(0) + cellDimension, paintContent);
        }

        this.paintBoxList(canvasContent, paintContent);

    } catch (JSONException e) {
        e.printStackTrace();
        Log.e("Exception in DrawComponents.drawBarreds", "" + e.getMessage());
    }

    canvasContent.restore();
    pictureContent.endRecording();
    return pictureContent;

}

From source file:com.ifoer.util.NetPOSPrinter.java

public Bitmap drawBitFirst() {
    this.nBitmapFirst = Bitmap.createBitmap(PRINT_WIDTH, 85, Config.RGB_565);
    Canvas canvas = new Canvas(this.nBitmapFirst);
    canvas.drawColor(-1);//from   w  w  w  .ja v  a  2 s.c  om
    Paint p = new Paint();
    p.setColor(DefaultRenderer.BACKGROUND_COLOR);
    p.setTextSize(20.0f);
    canvas.drawText(this.mContext.getResources().getString(C0136R.string.print_launch), 0.0f, 20.0f, p);
    canvas.drawLine(0.0f, 40.0f, 384.0f, 40.0f, p);
    canvas.drawText(
            this.mContext.getResources().getString(C0136R.string.print_automobile_fault_diagnosis_test_report),
            20.0f, 70.0f, p);
    canvas.drawLine(0.0f, 80.0f, 384.0f, 80.0f, p);
    return this.nBitmapFirst;
}

From source file:com.silentcircle.contacts.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *///  ww  w. j a  va  2  s . co m
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            int bCount = (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1)
                    ? bitmap.getRowBytes() * bitmap.getHeight()
                    : bitmap.getByteCount();
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bCount));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java

private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) {
    final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0;
    final float scale1 = scale * 0.75f; // smaller images on the android
    // platform//from www.j av a 2s. c o m

    final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1),
            Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(image);

    final Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStyle(Style.FILL);

    final Paint forgroundPaint = new Paint();
    forgroundPaint.setColor(Color.BLACK);
    forgroundPaint.setStyle(Style.STROKE);
    forgroundPaint.setStrokeWidth(1.0f);
    forgroundPaint.setStrokeCap(Cap.BUTT);
    forgroundPaint.setStrokeJoin(Join.ROUND);
    forgroundPaint.setStrokeMiter(0.0f);

    final Paint curvePaint = new Paint(forgroundPaint);
    curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    curvePaint.setStrokeWidth(2.0f);

    final Paint pointPaint = new Paint(curvePaint);
    pointPaint.setStrokeWidth(5.0f);
    pointPaint.setStyle(Style.FILL_AND_STROKE);

    final Paint helpLinePaint = new Paint(forgroundPaint);
    helpLinePaint.setColor(Color.GRAY);
    helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f));

    final Paint textPaint = new Paint(forgroundPaint);
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    textPaint.setTextSize(12.0f);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setStyle(Style.FILL);

    canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint);
    canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint);

    canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint);
    canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint);
    if (!pitchCurve) {
        canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint);
        canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint);
    }

    if (curve.getPoint() != null) {
        int numPoints = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                numPoints++;
            }
        }

        final double[] xVals = new double[numPoints];
        final double[] yVals = new double[numPoints];

        int i = 0;
        for (final CurvePoint p : curve.getPoint()) {
            if (p.isEnabled()) {
                if (i == 0) {
                    xVals[i] = pitchCurve ? 0 : -100;
                } else if (i == numPoints - 1) {
                    xVals[i] = 100;
                } else {
                    xVals[i] = p.getPosition();
                }
                yVals[i] = p.getValue();

                if (description) {
                    float x0;
                    float y0;
                    if (pitchCurve) {
                        x0 = (float) (5 + xVals[i] * 2 * scale1);
                        y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);
                    } else {
                        x0 = (float) (5 + (100 + xVals[i]) * scale1);
                        y0 = (float) (5 + (125 - yVals[i]) * scale1);
                    }

                    canvas.drawPoint(x0, y0, pointPaint);
                    if (y0 < 5 + 125 * scale1) {
                        canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint);
                    } else {
                        canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint);
                        canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint);
                    }
                }

                i++;
            }
        }

        if (numPoints > 2 && curve.isSmoothing()) {
            final SplineInterpolator s = new SplineInterpolator();
            final PolynomialSplineFunction function = s.interpolate(xVals, yVals);

            float x0 = 5;
            float y0;
            if (pitchCurve) {
                y0 = (float) (5 + (225 - yVals[0] * 2) * scale1);
            } else {
                y0 = (float) (5 + (125 - yVals[0]) * scale1);
            }

            while (x0 < 4 + 200 * scale1) {
                final float x1 = x0 + 1;
                float y1;
                if (pitchCurve) {
                    y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1);
                } else {
                    y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);

                x0 = x1;
                y0 = y1;
            }
        } else {
            for (i = 0; i < numPoints - 1; i++) {
                float x0, y0, x1, y1;

                if (pitchCurve) {
                    x0 = (float) (5 + xVals[i] * 2 * scale1);
                    y0 = (float) (5 + (225 - yVals[i] * 2) * scale1);

                    x1 = (float) (5 + xVals[i + 1] * 2 * scale1);
                    y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1);
                } else {
                    x0 = (float) (5 + (100 + xVals[i]) * scale1);
                    y0 = (float) (5 + (125 - yVals[i]) * scale1);

                    x1 = (float) (5 + (100 + xVals[i + 1]) * scale1);
                    y1 = (float) (5 + (125 - yVals[i + 1]) * scale1);
                }

                canvas.drawLine(x0, y0, x1, y1, curvePaint);
            }
        }
    }

    return image;
}

From source file:com.raspi.chatapp.util.Notification.java

private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) {
    Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    RectF mInnerRectF = new RectF();
    mInnerRectF.set(0, 0, width, width);
    mInnerRectF.offset(0, 0);//from w ww  .j a va  2s . c  o m

    Paint mBgPaint = new Paint();
    mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setStyle(Paint.Style.FILL);
    mBgPaint.setColor(bgColor);

    TextPaint mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(Color.WHITE);
    mTitleTextPaint.setTextSize(width * 0.8f);

    float centerX = mInnerRectF.centerX();
    float centerY = mInnerRectF.centerY();

    int xPos = (int) centerX;
    int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2);

    if (round)
        c.drawOval(mInnerRectF, mBgPaint);
    else
        c.drawRect(mInnerRectF, mBgPaint);
    c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint);

    return b;
}

From source file:com.astuetz.viewpager.extensions.IndicatorLineView.java

protected synchronized void onDraw(Canvas canvas) {

    super.onDraw(canvas);

    final Paint linePaint = mLinePaint;

    final int color = Color.argb(mAlpha, Color.red(mLineColor), Color.green(mLineColor),
            Color.blue(mLineColor));

    linePaint.setColor(color);

    // draw the line
    canvas.drawRect(mLineLeft, 0, mLineLeft + mLineWidth, getMeasuredHeight(), linePaint);

}

From source file:com.alex.view.loop.IndicatorView.java

/**
 * //from ww  w .jav a 2  s .  com
 *
 * @param color ??
 * @return
 */
private Bitmap makeIndicatorBp(int color) {
    Bitmap normalBp = Bitmap.createBitmap(mRadius * 2, mRadius * 2, Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(color);
    Canvas canvas = new Canvas(normalBp);
    canvas.drawCircle(mRadius, mRadius, mRadius, paint);
    return normalBp;
}

From source file:com.gj.administrator.gjerp.view.CircleIndicator.java

private void createTabItems() {
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        OvalShape circle = new OvalShape();
        ShapeDrawable drawable = new ShapeDrawable(circle);
        ShapeHolder shapeHolder = new ShapeHolder(drawable);
        Paint paint = drawable.getPaint();
        paint.setColor(mIndicatorBackground);
        paint.setAntiAlias(true);//from  ww w  . jav a  2s .  com
        shapeHolder.setPaint(paint);
        tabItems.add(shapeHolder);
    }
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.parseColor("#2099FF"));
    paint.setStyle(Paint.Style.FILL);

    //handle.getLeft() + TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics())
    int bubbleRight = bubble.getRight();

    int center = (getWidth() - bubbleRight) / 2;

    canvas.drawRect(/*from   w  w  w. j  ava2 s .c o  m*/
            bubbleRight + center, 0, center + bubbleRight + TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.6f, getResources().getDisplayMetrics()),
            getHeight(), paint);
}

From source file:com.gj.administrator.gjerp.view.CircleIndicator.java

private void createMovingItem() {
    OvalShape circle = new OvalShape();
    ShapeDrawable drawable = new ShapeDrawable(circle);
    movingItem = new ShapeHolder(drawable);
    Paint paint = drawable.getPaint();
    paint.setColor(mIndicatorSelectedBackground);
    paint.setAntiAlias(true);//  w  w  w.  j  a v  a 2  s. c o  m

    switch (mIndicatorMode) {
    case INSIDE:
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        break;
    case OUTSIDE:
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
        break;
    case SOLO:
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        break;
    }

    movingItem.setPaint(paint);
}