Example usage for android.graphics Paint setStrokeWidth

List of usage examples for android.graphics Paint setStrokeWidth

Introduction

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

Prototype

public void setStrokeWidth(float width) 

Source Link

Document

Set the width for stroking.

Usage

From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java

private Paint createImagePaint() {
    Paint imagePaint = new Paint();
    imagePaint.setAntiAlias(true);/*w  w w . j  a va  2  s.  c o  m*/
    imagePaint.setStrokeWidth(this.dp2px(DEFAULT_IMAGE_SECTION_PAINT_WIDTH));
    return imagePaint;
}

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 ww  w .  ja va 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.bamobile.fdtks.util.Tools.java

public static Bitmap getCircularBitmapWithWhiteBorder(Bitmap bitmap, int borderWidth) {
    if (bitmap == null || bitmap.isRecycled()) {
        return null;
    }//from  ww  w.j ava  2s.  co m

    final int width = bitmap.getWidth() + borderWidth;
    final int height = bitmap.getHeight() + borderWidth;

    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(shader);

    Canvas canvas = new Canvas(canvasBitmap);
    float radius = width > height ? ((float) height) / 2f : ((float) width) / 2f;
    canvas.drawCircle(width / 2, height / 2, radius, paint);
    paint.setShader(null);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(borderWidth);
    canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint);
    return canvasBitmap;
}

From source file:pl.itiner.nutiteq.NutiteqMap.java

public Bitmap createMissingTileBitmap(final int tileSize, final String bitmapText, Resources res) {
    Bitmap canvasBitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.RGB_565);
    Canvas imageCanvas = new Canvas(canvasBitmap);

    Paint textPaint = new Paint();
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(16f);//from   w  w  w . ja  v a 2s. co  m

    Paint backgroundPaint = new Paint();
    backgroundPaint.setColor(Color.WHITE);
    backgroundPaint.setStrokeWidth(3);
    imageCanvas.drawRect(0, 0, tileSize, tileSize, backgroundPaint);

    imageCanvas.drawText(bitmapText, tileSize / 2, tileSize / 2, textPaint);

    BitmapDrawable finalImage = new BitmapDrawable(res, canvasBitmap);
    return finalImage.getBitmap();
}

From source file:org.stockchart.core.Appearance.java

public void applyOutline(Paint p) {
    p.reset();/*  www.j a va 2s.  com*/
    p.setShader(null);
    p.setColor(fOutlineColor);
    p.setAntiAlias(fIsAntialias);
    p.setStrokeWidth(fOutlineWidth);
    p.setStyle(Style.STROKE);

    switch (fOutlineStyle) {
    case DASH:
        p.setPathEffect(DASH_EFFECT);
        break;
    default:
        p.setPathEffect(null);
    }
}

From source file:com.coinomi.wallet.ui.ScanActivity.java

public void handleResult(final Result scanResult, final Bitmap thumbnailImage,
        final float thumbnailScaleFactor) {
    vibrator.vibrate(VIBRATE_DURATION);// w w  w  .  jav  a 2 s. co  m

    // superimpose dots to highlight the key features of the qr code
    final ResultPoint[] points = scanResult.getResultPoints();
    if (points != null && points.length > 0) {
        final Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.scan_result_dots));
        paint.setStrokeWidth(10.0f);

        final Canvas canvas = new Canvas(thumbnailImage);
        canvas.scale(thumbnailScaleFactor, thumbnailScaleFactor);
        for (final ResultPoint point : points)
            canvas.drawPoint(point.getX(), point.getY(), paint);
    }

    scannerView.drawResultBitmap(thumbnailImage);

    final Intent result = new Intent();
    result.putExtra(INTENT_EXTRA_RESULT, scanResult.getText());
    setResult(RESULT_OK, result);

    // delayed finish
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    });
}

From source file:com.abhi.barcode.fragment.BarCodeFragment.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*from   w  w w  .j  av a  2 s  . c  o m*/
 * 
 * @param barcode
 *            A bitmap of the captured image.
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private 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);
        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)) {
            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:org.thoughtcrime.securesms.scribbles.widget.MotionView.java

private void initEntityBorder(@NonNull MotionEntity entity) {
    // init stroke
    int strokeSize = getResources().getDimensionPixelSize(R.dimen.scribble_stroke_size);
    Paint borderPaint = new Paint();
    borderPaint.setStrokeWidth(strokeSize);
    borderPaint.setAntiAlias(true);/*from ww  w  .  jav  a  2 s  .c  o m*/
    borderPaint.setColor(getContext().getResources().getColor(R.color.sticker_selected_color));

    entity.setBorderPaint(borderPaint);
}

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 w  w w .  j  av a 2  s  .c om*/

    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.abhi.barcode.frag.libv2.BarcodeFragment.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*ww w .ja  va 2  s  .c  o  m*/
 * 
 * @param barcode
 *            A bitmap of the captured image.
 * @param scaleFactor
 *            amount by which thumbnail was scaled
 * @param rawResult
 *            The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#c099cc00"));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
        } 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], scaleFactor);
            drawLine(canvas, paint, points[2], points[3], scaleFactor);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
            }
        }
    }
}