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.jaspersoft.android.jaspermobile.widget.AnnotationView.java

private void addPath() {
    Paint annotationPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    annotationPaint.setColor(mColor);/* w ww. j a v a 2s.c o m*/
    annotationPaint.setStyle(Paint.Style.STROKE);
    annotationPaint.setStrokeJoin(Paint.Join.ROUND);
    annotationPaint.setStrokeCap(Paint.Cap.ROUND);

    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    int strokeSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mSize, metrics);
    annotationPaint.setStrokeWidth(strokeSize);

    Path annotationPath = new Path();
    annotationPath.moveTo(mStartX, mStartY);

    mDrawingCache.add(new Pair<>(annotationPaint, annotationPath));
}

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

private void drawScale(Canvas canvas, Boolean Colors, int Count, int Max) {
    RectF faceRect = new RectF();
    faceRect.set(10, 10, 190, 190);//from  w ww  . j  a v  a 2  s.co  m

    Paint scalePaint = new Paint();
    scalePaint.setStyle(Paint.Style.STROKE);
    scalePaint.setColor(getResources().getColor(R.color.WarningGreen));
    scalePaint.setStrokeWidth(1);
    scalePaint.setAntiAlias(true);

    scalePaint.setTextSize(12);
    scalePaint.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/chivo.ttf"));
    scalePaint.setTextAlign(Paint.Align.CENTER);

    float scalePosition = 10;
    RectF scaleRect = new RectF();
    scaleRect.set(faceRect.left + scalePosition, faceRect.top + scalePosition, faceRect.right - scalePosition,
            faceRect.bottom - scalePosition);

    if (!Colors)
        scalePaint.setColor(Color.WHITE);

    scalePaint.setStrokeWidth(2);
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    for (int i = 0; i < Max; ++i) {
        if (Colors) {
            if (i > 20)
                scalePaint.setColor(getResources().getColor(R.color.WarningYellow));

            if (i > 40)
                scalePaint.setColor(getResources().getColor(R.color.WarningOrange));

            if (i > 60)
                scalePaint.setColor(getResources().getColor(R.color.WarningRed));
        }

        canvas.drawLine(100, 20, 100, 18, scalePaint);
        int divisor = 5;

        if (Max > 100)
            divisor = 25;

        if (i % divisor == 0) {
            canvas.drawText(Integer.toString(i), 100, 16, scalePaint);
        }

        canvas.rotate((360.0f / Max), 100, 100);
    }

    canvas.restore();
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

/** Draws a black border over the screenshot of the view passed in. */
private Bitmap getBitmapWithBorder(View v) {
    Bitmap bitmap = getBitmapFromView(v);
    Canvas can = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);
    paint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));

    can.drawBitmap(bitmap, 0, 0, null);//w  w w. j a v  a  2  s .co  m
    can.drawRect(rect, paint);

    return bitmap;
}

From source file:com.concavenp.artistrymuse.BaseAppCompatActivity.java

private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) {

    return new BitmapImageViewTarget(imageView) {
        @Override/*  w ww .  j  ava  2  s. c  o m*/
        protected void setResource(Bitmap bitmap) {

            int bitmapWidth = bitmap.getWidth();
            int bitmapHeight = bitmap.getHeight();
            int borderWidthHalf = 10;
            int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight);
            int newBitmapSquare = bitmapSquareWidth + borderWidthHalf;

            Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare,
                    Bitmap.Config.ARGB_8888);

            // Initialize a new Canvas to draw empty bitmap
            Canvas canvas = new Canvas(roundedBitmap);

            // Calculation to draw bitmap at the circular bitmap center position
            int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth;
            int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight;

            canvas.drawBitmap(bitmap, x, y, null);

            // Initializing a new Paint instance to draw circular border
            Paint borderPaint = new Paint();
            borderPaint.setStyle(Paint.Style.STROKE);
            borderPaint.setStrokeWidth(borderWidthHalf * 2);
            borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null));

            canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint);

            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(),
                    roundedBitmap);
            circularBitmapDrawable.setCircular(true);
            imageView.setImageDrawable(circularBitmapDrawable);

        }
    };
}

From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Paint createShadowPaint(int left, int top, int width, int height, int shadowStrokeWidth) {
    List<PointF> points = getPoints(width, height);
    PointF fromPoint = new PointF(left + points.get(0).x, top + points.get(0).y);
    PointF toPoint = new PointF(left + points.get(1).x, top + points.get(1).y);

    PointF midpoint = new PointF((fromPoint.x + toPoint.x) * 0.5f, (fromPoint.y + toPoint.y) * 0.5f);

    PointF vector = new PointF(fromPoint.x - midpoint.x, fromPoint.y - midpoint.y);

    PointF rotatedVector = new PointF(vector.y, -vector.x);

    float vectorLength = (float) Math.sqrt((vector.x * vector.x) + (vector.y * vector.y));

    PointF shadowVector = new PointF(rotatedVector.x * (shadowStrokeWidth * 0.5f) / vectorLength,
            rotatedVector.y * (shadowStrokeWidth * 0.5f) / vectorLength);

    LinearGradient gradient = new LinearGradient(midpoint.x, midpoint.y, midpoint.x + shadowVector.x,
            midpoint.y + shadowVector.y, Color.argb(100, 0, 0, 0), Color.argb(0, 0, 0, 0), TileMode.MIRROR);

    Paint paint = new Paint();
    paint.setStyle(Style.STROKE);
    paint.setShader(gradient);/*from  w  w w . j a va 2s  . c o m*/
    paint.setStrokeWidth(shadowStrokeWidth);
    paint.setStrokeCap(Cap.SQUARE);

    return paint;
}

From source file:com.lemon.lime.MainActivity.java

private void addBarGraphRenderers() {
    Paint paint = new Paint();
    paint.setStrokeWidth(50f);
    paint.setAntiAlias(true);/*from   w w  w  .  j av  a  2 s.  com*/
    paint.setColor(Color.argb(200, 56, 138, 252));
    BarGraphRenderer barGraphRendererBottom = new BarGraphRenderer(16, paint, false);
    mVisualizerView.addRenderer(barGraphRendererBottom);

    Paint paint2 = new Paint();
    paint2.setStrokeWidth(12f);
    paint2.setAntiAlias(true);
    paint2.setColor(Color.argb(200, 181, 111, 233));
    BarGraphRenderer barGraphRendererTop = new BarGraphRenderer(4, paint2, true);
    mVisualizerView.addRenderer(barGraphRendererTop);
}

From source file:org.madmatrix.zxing.android.CaptureActivity.java

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of
 * the barcode./*www.j av a2  s  .c om*/
 * 
 * @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(getResources().getColor(R.color.result_points));
        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) {
                if (point != null) {
                    canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
                }
            }
        }
    }
}

From source file:ucsc.hci.rankit.DynamicListView.java

/** Draws a black border over the screenshot of the view passed in. */
private Bitmap getBitmapWithBorder(View v) {
    Bitmap bitmap = getBitmapFromView(v);
    Canvas can = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);
    paint.setColor(Color.WHITE);/*from  w  w  w  .  java 2  s  .  c o  m*/

    can.drawBitmap(bitmap, 0, 0, null);
    can.drawRect(rect, paint);

    return bitmap;
}

From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java

/**
 * Draw Two Checkboxes/*from  ww w. ja  v a 2  s  .  com*/
 * @param left left location of leftmost box
 * @param top top location
 * @param paint Paint Object
 * @param isSecondBold true if second square should be bold
 * @param isYes true if Yes checkbox is ticked
 */
private void drawBox(float left, float top, Paint paint, boolean isSecondBold, Take5Data.CheckValue isYes) {

    int right = (int) left + BOX_WIDTH;
    int bottom = (int) top + BOX_WIDTH;

    if (isSecondBold) {
        paint.setStrokeWidth(.7f);
        can.drawRect(left, top, right, bottom, paint);
        paint.setStrokeWidth(1.5f);
        can.drawRect(left + 22, top, right + 22, bottom, paint);
    } else {
        paint.setStrokeWidth(1.5f);
        can.drawRect(left, top, right, bottom, paint);
        paint.setStrokeWidth(.7f);
        can.drawRect(left + 22, top, right + 22, bottom, paint);
    }

    if (isYes == Take5Data.CheckValue.YES) {
        drawCheck(left, top, paint);
    } else if (isYes == Take5Data.CheckValue.NO) {
        drawCheck(left + 22, top, paint);
    }
    paint.setStrokeWidth(.5f);
}

From source file:com.yaozu.object.widget.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);// w w  w.  j  a va  2 s. c  o m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabsContainer.setGravity(Gravity.CENTER_VERTICAL); // ?
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    //scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    mScrollOffset = dm.widthPixels / 2;
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);

    // add by hangl begin
    tabPaddingVertical = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingVertical, dm);
    // add by hangl end

    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabTextSize, dm); // change sp to dp

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    a.recycle();
    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_tabTextColor, tabTextColor);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabTextSize, tabTextSize);

    // add by hangl begin
    tabTextColorNormal = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextNormalColor, tabTextColorNormal);
    tabTextColorSelected = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextSelectedColor,
            tabTextColorSelected);
    tabPaddingVertical = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingVertical,
            tabPaddingVertical);
    expandViewWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsExpandViewWidth,
            expandViewWidth);
    // add by hangl end

    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    Paint dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}