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:info.tellmetime.TellmetimeActivity.java

/**
 * Generates rainbow gradient and sets it as #mSeekBarHighlight progress drawable.
 *//*from w  w w .ja v  a  2 s  . c  o  m*/
private void drawRainbow() {
    float gradientWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 256,
            getResources().getDisplayMetrics());
    int[] colors = { 0xFFFFFFFF, 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF,
            0xFF888888, 0xFF000000 };
    LinearGradient rainbowGradient = new LinearGradient(0f, 0f, gradientWidth, 0f, colors, null,
            Shader.TileMode.CLAMP);
    float r = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    ShapeDrawable shape = new ShapeDrawable(
            new RoundRectShape(new float[] { r, r, r, r, r, r, r, r }, null, null));
    shape.getPaint().setShader(rainbowGradient);
    mSeekBarHighlight.setProgressDrawable(shape);

    // Generate bitmap with the same rainbow gradient and cache it for later use to retrieve color at given position.
    Bitmap bitmap = Bitmap.createBitmap((int) gradientWidth, 1, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setShader(rainbowGradient);
    canvas.drawRect(0, 0, gradientWidth, 1, paint);
    mRainbow = bitmap;

    // Set max value to gradient's width and restore relative position.
    mSeekBarHighlight.setMax((int) (gradientWidth - 1));
    mSeekBarHighlight.setProgress((int) ((gradientWidth - 1) * mHighlightPosition));
}

From source file:android.support.wear.widget.drawer.PageIndicatorView.java

private void updateDotPaint(Paint dotPaint, Paint shadowPaint, float baseRadius, float shadowRadius, int color,
        int shadowColor) {
    float radius = baseRadius + shadowRadius;
    float shadowStart = baseRadius / radius;
    Shader gradient = new RadialGradient(0, 0, radius,
            new int[] { shadowColor, shadowColor, Color.TRANSPARENT }, new float[] { 0f, shadowStart, 1f },
            TileMode.CLAMP);//from w w w  .j  av  a 2s .  c om

    shadowPaint.setShader(gradient);
    dotPaint.setColor(color);
    dotPaint.setStyle(Style.FILL);
}

From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java

@NonNull
private Bitmap buildMarkerBitmap(@NonNull Context c) {
    // Oh, this is going to be FUN.
    int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size);
    float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius);

    Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setAntiAlias(true);//w  w w . ja v a  2 s.c o  m

    KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation);

    // Draw the pin line first.  That goes from the bottom-center up to
    // wherever the radius and length take us.
    float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue();
    float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue();
    paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke));
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.BLACK);

    canvas.drawLine(dim / 2, dim, topX, topY, paint);

    // On the top of that line, fill in a circle.
    paint.setColor(pinData.getColor());
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(topX, topY, radius, paint);

    // And outline it.
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(topX, topY, radius, paint);

    return bitmap;
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_rectangle(Paint paint, int x, int y, int w, int h) {
    Rect r = new Rect(x, y, x + w, y + h);
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);/*from  w w  w  .  j  a  va 2 s  .  c o m*/
    //paint.setStrokeWidth(0);
    draw_canvas.drawRect(r, paint);
}

From source file:com.tiange.hz.wheelview.widget.WheelView.java

/**
 * Draws rect for current value/*from w  w  w  .j  a va  2  s  .  c o  m*/
 * @param canvas the canvas for drawing
 */
private void drawCenterRect(Canvas canvas) {
    int center = getHeight() / 2;
    int offset = (int) (getItemHeight() / 2 * 1.2);
    if (centerDrawable != null) {
        centerDrawable.setBounds(0, center - offset, getWidth(), center + offset);
        centerDrawable.draw(canvas);
    }
    //dip2px
    if (wheelForegroundColor != Color.TRANSPARENT) {
        Paint paint = new Paint();
        paint.setColor(wheelForegroundColor);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(0, center - offset, getWidth(), center + offset), paint);
    }

    if (wheelForeDividerColor != Color.TRANSPARENT) {
        //wheelForeDividerWidth==

        Paint paint = new Paint();
        paint.setColor(wheelForeDividerColor);
        canvas.drawLine(0, center - offset, getWidth(), center - offset, paint);
        canvas.drawLine(0, center + offset, getWidth(), center + offset, paint);
    }
}

From source file:com.diedrico.diedricoapp.PicMenuActivity.java

License:asdf

private PicAnalyzer.AsyncResponse analyzerFinished() { //We receive the important points and lines, we have to paint them
    return new PicAnalyzer.AsyncResponse() {
        @Override//from  w  ww .j  a v a 2 s  .  co  m
        public void processFinish(List<PointVector> points, List<LineVector> lines, List<Double> planos) {
            //Set that the analyzer finished
            analyzerFinished = Boolean.TRUE;

            //Save the points in another var, if the user select that there are errors in the scan, he can select the points and lines manually
            allPoints = points;
            allLines = lines;

            //First we have to delete the short lines, we get the top module and then we discard the short ones
            Collections.sort(lines, new Comparator<LineVector>() {
                @Override
                public int compare(LineVector line1, LineVector line2) {
                    return (line1.getModuleTwoDimensionalVector() - line2.getModuleTwoDimensionalVector() >= 0)
                            ? -1
                            : 1;
                }
            });

            landLine = lines.get(0); //This is the landLine
            double minModule = lines.get(0).getModuleTwoDimensionalVector() / 6;

            for (LineVector linevector : new ArrayList<>(lines)) {
                if (linevector.getModuleTwoDimensionalVector() < minModule) {
                    lines.remove(linevector);
                }
            }

            pointDiedrico = new ArrayList<>();
            lineDiedrico = new ArrayList<>();

            ////Delete the wrong lines, the ones that don't have x's view and y's view respectively (cota and alejamiento). Then we differ between if it is a line(in diedrico) or a plane
            for (int j = 1; j < lines.size(); j++) { //Start in 1 because in 0 the line is the landLine
                LineVector line1 = lines.get(j);
                for (int k = 1; k < lines.size(); k++) {
                    LineVector line2 = lines.get(k);

                    if (line1.equals(line2)) {
                        if (k == lines.size() - 1) { //The last line of the list
                            lines.remove(k);
                            j--;
                            break;
                        }
                        continue;
                    }

                    if (line1.getLineYA() > lines.get(0).getYEquation(line1.getLineXA())
                            && line2.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())
                            || line2.getLineYA() > lines.get(0).getYEquation(line1.getLineXA())
                                    && line1.getLineYA() < lines.get(0).getYEquation(line1.getLineXA())) {
                        if (line1.getLineXA() > line2.getLineXA() - 50
                                && line1.getLineXA() < line2.getLineXA() + 50) { //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue
                            if (line1.getLineYA() > landLine.getLineYA()) {//We store the cota and alejamiento, the cota is the line over the landline
                                lineDiedrico.add(new LineDiedrico(line1, line2));
                            } else {
                                lineDiedrico.add(new LineDiedrico(line2, line1));
                            }

                            lines.remove(k);
                            lines.remove(j);

                            j--;
                            break;
                        }
                    }

                    if (k == lines.size() - 1) { //The line doesn't have a couple
                        lines.remove(j);
                        j--;
                    }
                }
            }

            //Also, boofcv finds a lot of useless points near the lines, so we have to delete them
            Iterator<LineVector> lineVectorIterator = lines.iterator();
            while (lineVectorIterator.hasNext()) {
                LineVector lineVector = lineVectorIterator.next();

                points = Stream.of(points)
                        .filter((PointVector point) -> point
                                .getPointY() < lineVector.getYEquation(point.getPointX()) - 15
                                || point.getPointY() > lineVector.getYEquation(point.getPointX()) + 15)
                        .toList();
            }

            //Then we have to delete the groups of points and take only one of them
            for (int j = 0; j < points.size(); j++) {
                PointVector point1 = points.get(j);
                for (int k = 0; k < points.size(); k++) {
                    PointVector point2 = points.get(k);

                    if (point1.equals(point2)) {
                        continue;
                    }

                    if (point1.getPointX() > point2.getPointX() - 20
                            && point1.getPointX() < point2.getPointX() + 20
                            && point1.getPointY() > point2.getPointY() - 20
                            && point1.getPointY() < point2.getPointY() + 20) { //Has found a result, then we delete the points from the list
                        points.remove(k);
                        k--;
                    }
                }
            }

            //Delete the wrong point, the ones that don't have x's view and y's view respectively (cota and alejamiento). The correct points will be in pointDiedrico
            for (int j = 0; j < points.size(); j++) {
                PointVector point1 = points.get(j);
                for (int k = 0; k < points.size(); k++) {
                    PointVector point2 = points.get(k);

                    if (point1.equals(point2)) {
                        if (k == points.size() - 1) { //The last point of the list
                            points.remove(k);
                            j--;
                            break;
                        }
                        continue;
                    }

                    if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())
                            && point2.getPointY() < lines.get(0).getYEquation(point2.getPointX())
                            || point2.getPointY() > lines.get(0).getYEquation(point2.getPointX())
                                    && point1.getPointY() < lines.get(0).getYEquation(point1.getPointX())) {
                        if (point1.getPointX() > point2.getPointX() - 15
                                && point1.getPointX() < point2.getPointX() + 15) {
                            //Has found a result, then we delete the points from the list, and put them in pointDiedricoList and we continue
                            if (point1.getPointY() > lines.get(0).getYEquation(point1.getPointX())) { //We store the cota and alejamiento, the cota is the point over the landline
                                pointDiedrico.add(new PointDiedrico(point1, point2));
                            } else {
                                pointDiedrico.add(new PointDiedrico(point2, point1));
                            }

                            points.remove(k);
                            points.remove(j);

                            j--;
                            break;
                        }
                    }

                    if (k == points.size() - 1) { //The point doesn't have a couple
                        points.remove(j);
                        j--;
                    }
                }
            }

            int indexColors = 0; //Counter for the color array
            int[] colors = context.getResources().getIntArray(R.array.rainbow);

            Paint paintMax;
            paintMax = new Paint();
            paintMax.setStyle(Paint.Style.FILL);

            Canvas canvas = new Canvas(thresholdingBitmap);

            for (int i = 0; i < pointDiedrico.size(); i++) {
                paintMax.setColor(colors[indexColors++]);
                if (indexColors >= colors.length)
                    indexColors = 0;

                canvas.drawCircle(pointDiedrico.get(i).getX().getPointX(),
                        pointDiedrico.get(i).getX().getPointY(), 3, paintMax);
                canvas.drawCircle(pointDiedrico.get(i).getY().getPointX(),
                        pointDiedrico.get(i).getY().getPointY(), 3, paintMax);
            }

            //Paint the landLine with color blue
            paintMax.setColor(Color.BLUE);
            canvas.drawLine(lines.get(0).getLineXA(), lines.get(0).getLineYA(), lines.get(0).getLineXB(),
                    lines.get(0).getLineYB(), paintMax);

            //Paint the interesting lines
            for (int i = 0; i < lineDiedrico.size(); i++) {
                paintMax.setColor(colors[indexColors++]);
                if (indexColors >= colors.length)
                    indexColors = 0;
                canvas.drawLine(lineDiedrico.get(i).getX().getLineXA(), lineDiedrico.get(i).getX().getLineYA(),
                        lineDiedrico.get(i).getX().getLineXB(), lineDiedrico.get(i).getX().getLineYB(),
                        paintMax);
                canvas.drawLine(lineDiedrico.get(i).getY().getLineXA(), lineDiedrico.get(i).getY().getLineYA(),
                        lineDiedrico.get(i).getY().getLineXB(), lineDiedrico.get(i).getY().getLineYB(),
                        paintMax);
            }

            imageView.setImageBitmap(thresholdingBitmap);
        }
    };
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polygon(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);//  w ww . j a v a 2s .co m
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.FILL);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    Path path = new Path();
    path.moveTo(c[5], c[6]);
    for (int i = 7; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_polyline(Paint paint, int[] c) {
    paint.setStrokeWidth(c[0]);/*from  ww  w. j  a  va  2s .c  o m*/
    paint.setARGB(c[1], c[2], c[3], c[4]);
    paint.setStyle(Paint.Style.STROKE);
    //paint.setAntiAlias(true);
    //paint.setStrokeWidth(0);
    int ndashes = c[5];
    float[] intervals = new float[ndashes + (ndashes % 2)];
    for (int i = 0; i < ndashes; i++) {
        intervals[i] = c[6 + i];
    }

    if ((ndashes % 2) == 1) {
        intervals[ndashes] = intervals[ndashes - 1];
    }

    if (ndashes > 0) {
        paint.setPathEffect(new android.graphics.DashPathEffect(intervals, 0.0f));
    }

    Path path = new Path();
    path.moveTo(c[6 + ndashes], c[7 + ndashes]);
    for (int i = 8 + ndashes; i < c.length; i += 2) {
        path.lineTo(c[i], c[i + 1]);
    }
    //global_path.close();
    draw_canvas.drawPath(path, paint);
    paint.setPathEffect(null);
}

From source file:org.navitproject.navit.NavitGraphics.java

protected void draw_text(Paint paint, int x, int y, String text, int size, int dx, int dy, int bgcolor) {
    int oldcolor = paint.getColor();
    Path path = null;/*from  www .j  a v a2 s. c o m*/

    paint.setTextSize(size / 15);
    paint.setStyle(Paint.Style.FILL);

    if (dx != 0x10000 || dy != 0) {
        path = new Path();
        path.moveTo(x, y);
        path.rLineTo(dx, dy);
        paint.setTextAlign(android.graphics.Paint.Align.LEFT);
    }

    if (bgcolor != 0) {
        paint.setStrokeWidth(3);
        paint.setColor(bgcolor);
        paint.setStyle(Paint.Style.STROKE);
        if (path == null) {
            draw_canvas.drawText(text, x, y, paint);
        } else {
            draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
        }
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(oldcolor);
    }

    if (path == null) {
        draw_canvas.drawText(text, x, y, paint);
    } else {
        draw_canvas.drawTextOnPath(text, path, 0, 0, paint);
    }
    paint.clearShadowLayer();
}