Example usage for android.graphics Paint setStyle

List of usage examples for android.graphics Paint setStyle

Introduction

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

Prototype

public void setStyle(Style style) 

Source Link

Document

Set the paint's style, used for controlling how primitives' geometries are interpreted (except for drawBitmap, which always assumes Fill).

Usage

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

@SuppressWarnings("unused")
private Bitmap RenderLineGraph() {
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    final int color = 0xff0B0B61;
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);/*from  w w  w .  j a v a  2  s  . c o  m*/

    //if(warningEvents > )
    canvas.drawText("100", 0, 10, paint);

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    int CritArray[] = { 5, 4, 6, 10, 10, 6, 4, 4 };
    int curX = 25;

    int divisor = 148 / 10;
    paint.setColor(Color.RED);
    int curY = 148 - (CritArray[0] * divisor);

    for (int a : CritArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int ErrArray[] = { 1, 2, 2, 2, 4, 2, 1, 0 };
    curX = 25;

    paint.setColor(Color.rgb(255, 102, 0));
    curY = 148 - (ErrArray[0] * divisor);

    for (int a : ErrArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    int WarnArray[] = { 0, 2, 4, 8, 10, 4, 2, 2 };
    curX = 25;

    paint.setColor(Color.YELLOW);
    curY = 148 - (WarnArray[0] * divisor);

    Path myPath = new Path();

    for (int a : WarnArray) {
        canvas.drawLine(curX, curY, curX + 32, (148 - (a * divisor)), paint);
        curX += 32;
        curY = 148 - (a * divisor);
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) {

    //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount));
    Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888);

    int width = emptyBmap.getWidth();
    int height = emptyBmap.getHeight();
    Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(charty);
    //final int color = 0xff0B0B61; 
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);//from   ww  w . j av  a  2  s  .  com

    //y
    canvas.drawLine(25, 0, 25, 289, paint);
    //x
    canvas.drawLine(25, 149, 289, 149, paint);

    paint.setAntiAlias(true);
    int Max = 0;

    if (CritCount > ErrCount && CritCount > WarnCount)
        Max = CritCount;
    else if (ErrCount > CritCount && ErrCount > WarnCount)
        Max = ErrCount;
    else if (WarnCount > CritCount && WarnCount > ErrCount)
        Max = WarnCount;
    else
        Max = CritCount;

    if (Max > 0)
        canvas.drawText(Integer.toString(Max), 0, 10, paint);

    if (Max > 1)
        canvas.drawText(Integer.toString(Max / 2), 0, 75, paint);

    canvas.drawText("0", 0, 148, paint);

    double divisor = 148 / (double) Max;

    paint.setAlpha(128);

    Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148);
    paint.setColor(Color.argb(200, 208, 0, 0)); //red

    if (CritCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148);
    paint.setColor(Color.argb(200, 255, 102, 0));//orange

    if (ErrCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148);
    paint.setColor(Color.argb(200, 255, 224, 57)); //yellow
    if (WarnCount > 0)
        canvas.drawRect(new RectF(rect), paint);

    //Return
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    charty.compress(CompressFormat.PNG, 50, out);

    return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size());
}

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//w ww .  j  a v  a 2s  .  co 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:ch.carteggio.ui.ConversationIconLoader.java

/**
 * Calculates a bitmap with a color and a capital letter for contacts without picture.
 *///ww  w. ja v a  2  s.c  o m
private Bitmap calculateFallbackBitmap(String emails[]) {
    Bitmap result = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(result);

    int rgb = CONTACT_DUMMY_COLORS_ARGB[0];

    if (emails.length > 0) {
        calcUnknownContactColor(emails[0]);
    }

    result.eraseColor(rgb);

    String letter = FALLBACK_CONTACT_LETTER;

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setARGB(255, 255, 255, 255);
    paint.setTextSize(mPictureSizeInPx * 3 / 4); // just scale this down a bit
    Rect rect = new Rect();
    paint.getTextBounds(letter, 0, 1, rect);
    float width = paint.measureText(letter);
    canvas.drawText(letter, (mPictureSizeInPx / 2f) - (width / 2f),
            (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint);

    return result;
}

From source file:com.jwetherell.quick_response_code.DecoderActivity.java

protected void drawResultPoints(Bitmap barcode, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_image_border));
        paint.setStrokeWidth(3.0f);/*from w  w  w  .ja  va 2  s .  c o  m*/
        paint.setStyle(Paint.Style.STROKE);
        Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
        canvas.drawRect(border, paint);

        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1]);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A
                || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and
            // metadata
            drawLine(canvas, paint, points[0], points[1]);
            drawLine(canvas, paint, points[2], points[3]);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(point.getX(), point.getY(), paint);
            }
        }
    }
}

From source file:gov.sfmta.sfpark.AnnotationsOverlay.java

public void draw(Canvas canvas, MapView mapv, boolean shadow) {
    if (shadow) {
        return;/*from   w  ww .  j a va 2 s  .co  m*/
    }

    Projection projection = mapv.getProjection();

    Point from = new Point();
    Point to = new Point();

    Paint mPaint = new Paint();
    mPaint.setStyle(Style.STROKE);
    mPaint.setAntiAlias(true);
    mPaint.setStrokeWidth(6);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    // could have NPE:
    try {
        for (MyAnnotation a : MainScreenActivity.annotations) {
            if (a.onStreet) {
                projection.toPixels(a.nw, from);
                projection.toPixels(a.se, to);
                if (MainScreenActivity.showPrice) {
                    mPaint.setColor(a.blockColorPrice);
                    canvas.drawLine(from.x, from.y, to.x, to.y, mPaint);
                } else {
                    // new: no more availability data on blockfaces.
                    // mPaint.setColor(a.blockColorAvailability);
                }
            }
        }
    } catch (NullPointerException npe) {
        // oh sadface! just ignore.
    }

    super.draw(canvas, mapv, shadow);
}

From source file:com.android.example.alwaysonstopwatch.StopwatchActivity.java

@Override
public void onEnterAmbient(Bundle ambientDetails) {
    Log.d(TAG, "ENTER Ambient");
    super.onEnterAmbient(ambientDetails);

    if (mRunning) {
        mActiveModeUpdateHandler.removeMessages(R.id.msg_update);
        mNotice.setVisibility(View.VISIBLE);
    }/*from   www .j  a  va2  s .  c o m*/

    mActiveClockUpdateHandler.removeMessages(R.id.msg_update);

    mTimeView.setTextColor(Color.WHITE);
    Paint textPaint = mTimeView.getPaint();
    textPaint.setAntiAlias(false);
    textPaint.setStyle(Paint.Style.STROKE);
    textPaint.setStrokeWidth(2);

    mStartStopButton.setVisibility(View.INVISIBLE);
    mResetButton.setVisibility(View.INVISIBLE);
    mBackground.setBackgroundColor(Color.BLACK);

    mClockView.setTextColor(Color.WHITE);
    mClockView.getPaint().setAntiAlias(false);

    updateDisplayAndSetRefresh();
}

From source file:com.android.example.alwaysonstopwatch.StopwatchActivity.java

@Override
public void onExitAmbient() {
    Log.d(TAG, "EXIT Ambient");
    super.onExitAmbient();

    if (mRunning) {
        mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent);
    }//from  www .  j  a v  a  2s  . c  o  m

    mTimeView.setTextColor(mActiveForegroundColor);
    Paint textPaint = mTimeView.getPaint();
    textPaint.setAntiAlias(true);
    textPaint.setStyle(Paint.Style.FILL);

    mStartStopButton.setVisibility(View.VISIBLE);
    mResetButton.setVisibility(View.VISIBLE);
    mBackground.setBackgroundColor(mActiveBackgroundColor);

    mClockView.setTextColor(mActiveForegroundColor);
    mClockView.getPaint().setAntiAlias(true);

    mActiveClockUpdateHandler.sendEmptyMessage(R.id.msg_update);

    if (mRunning) {
        mNotice.setVisibility(View.INVISIBLE);
        updateDisplayAndSetRefresh();
    }
}

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(/* w  ww . j  a  va  2  s  .  com*/
            bubbleRight + center, 0, center + bubbleRight + TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.6f, getResources().getDisplayMetrics()),
            getHeight(), paint);
}

From source file:com.google.blockly.android.ui.AbstractBlockView.java

/**
 * This is a developer testing function subclasses can call to draw dots at the model's location
 * of all connections on this block.  Never called by default.
 *
 * @param c The canvas to draw on./*from ww  w .  j a va 2s .  c  om*/
 */
protected void drawConnectorCenters(Canvas c) {
    List<Connection> connections = mBlock.getAllConnections();
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    for (int i = 0; i < connections.size(); i++) {
        Connection conn = connections.get(i);
        if (conn.inDragMode()) {
            if (conn.isConnected()) {
                paint.setColor(Color.RED);
            } else {
                paint.setColor(Color.MAGENTA);
            }
        } else {
            if (conn.isConnected()) {
                paint.setColor(Color.GREEN);
            } else {
                paint.setColor(Color.CYAN);
            }
        }

        // Compute connector position relative to this view from its offset to block origin in
        // Workspace coordinates.
        mTempWorkspacePoint.set(conn.getPosition().x - mBlock.getPosition().x,
                conn.getPosition().y - mBlock.getPosition().y);
        mHelper.workspaceToVirtualViewDelta(mTempWorkspacePoint, mTempConnectionPosition);
        if (mHelper.useRtl()) {
            // In RTL mode, add block view size to x coordinate. This is counter-intuitive, but
            // equivalent to "x = size - (-x)", with the inner negation "-x" undoing the
            // side-effect of workspaceToVirtualViewDelta reversing the x coordinate. This is,
            // the addition mirrors the re-negated in-block x coordinate w.r.t. the right-hand
            // side of the block view, which is the origin of the block in RTL mode.
            mTempConnectionPosition.x += mBlockViewSize.x;
        }
        c.drawCircle(mTempConnectionPosition.x, mTempConnectionPosition.y, 10, paint);
    }
}