android.graphics.drawable.shapes.PathShape Java Examples

The following examples show how to use android.graphics.drawable.shapes.PathShape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageProcessor.java    From Document-Scanner with GNU General Public License v3.0 5 votes vote down vote up
private void drawDocumentBox(Point[] points, Size stdSize) {

        Path path = new Path();

        HUDCanvasView hud = mMainActivity.getHUD();

        // ATTENTION: axis are swapped

        float previewWidth = (float) stdSize.height;
        float previewHeight = (float) stdSize.width;

        path.moveTo( previewWidth - (float) points[0].y, (float) points[0].x );
        path.lineTo( previewWidth - (float) points[1].y, (float) points[1].x );
        path.lineTo( previewWidth - (float) points[2].y, (float) points[2].x );
        path.lineTo( previewWidth - (float) points[3].y, (float) points[3].x );
        path.close();

        PathShape newBox = new PathShape(path , previewWidth , previewHeight);

        Paint paint = new Paint();
        paint.setColor(Color.argb(64, 0, 255, 0));

        Paint border = new Paint();
        border.setColor(Color.rgb(0, 255, 0));
        border.setStrokeWidth(5);

        hud.clear();
        hud.addShape(newBox, paint, border);
        mMainActivity.invalidateHUD();
    }
 
Example #2
Source File: SignatureView.java    From ResearchStack with Apache License 2.0 5 votes vote down vote up
/**
 * 1. Iterating over the path points, saving them in an array ... not bueno. Try to use
 * {@link android.graphics.PathMeasure} class and get minX and minY from that.
 * <p>
 * 2. Scale bitmap down. Currently drawing at density of device.
 */
public Bitmap createSignatureBitmap() {

    Paint bitmapSigPaint = new Paint(sigPaint);
    bitmapSigPaint.setColor(sigPrintColor);

    RectF sigBounds = new RectF();
    sigPath.computeBounds(sigBounds, true);

    if (sigBounds.width() != 0 && sigBounds.height() != 0) {
        float density = getResources().getDisplayMetrics().density;
        int dipWidth = (int) (sigBounds.width() / density);
        int dipHeight = (int) (sigBounds.height() / density);

        Bitmap returnedBitmap = Bitmap.createBitmap(dipWidth, dipHeight,
                Bitmap.Config.ARGB_4444);

        float minX = Integer.MAX_VALUE;
        float minY = Integer.MAX_VALUE;

        for (LinePathPoint point : sigPoints) {
            minX = Math.min(minX, point.x);
            minY = Math.min(minY, point.y);
        }

        sigPath.offset(-minX, -minY);

        PathShape pathShape = new PathShape(sigPath, sigBounds.width(), sigBounds.height());
        pathShape.resize(dipWidth, dipHeight);

        Canvas canvas = new Canvas(returnedBitmap);
        pathShape.draw(canvas, bitmapSigPaint);

        return returnedBitmap;
    }

    return null;
}
 
Example #3
Source File: MainActivity.java    From md2tv with MIT License 5 votes vote down vote up
public void crossLineButtonClick(View view){
    Path path = new Path();
    path.moveTo(0, 12);
    path.lineTo(100, 88);

    ShapeBackgroundSpan shapeSpan = new ShapeBackgroundSpan(0xFF000000, new PathShape(path, 100, 100), true);
    shapeSpan.setStrokeWidth(6);

    textView.setSelectionSpan(shapeSpan, new ArrowBackgroundSpan(0xFF7373, 0x22000000));
}
 
Example #4
Source File: MainActivity.java    From CurtainSlidingMenu with MIT License 5 votes vote down vote up
public void crossLineButtonClick(View view){
    Path path = new Path();
    path.moveTo(0, 12);
    path.lineTo(100, 88);

    ShapeBackgroundSpan shapeSpan = new ShapeBackgroundSpan(0xFF000000, new PathShape(path, 100, 100), true);
    shapeSpan.setStrokeWidth(6);

    editText.setSelectionSpan(shapeSpan, new ArrowBackgroundSpan(0xFF7373, 0x22000000));
}
 
Example #5
Source File: DocumentGraphic.java    From CVScanner with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw the graphic on the supplied canvas.  Drawing should use the following methods to
 * convert to view coordinates for the graphics that are drawn:
 * <ol>
 * <li>{@link GraphicOverlay.Graphic#scaleX(float)} and {@link GraphicOverlay.Graphic#scaleY(float)} adjust the size of
 * the supplied value from the preview scale to the view scale.</li>
 * <li>{@link GraphicOverlay.Graphic#translateX(float)} and {@link GraphicOverlay.Graphic#translateY(float)} adjust the
 * coordinate from the preview's coordinate system to the view coordinate system.</li>
 * </ol>
 *
 * @param canvas drawing canvas
 */
@Override
public void draw(Canvas canvas) {
    //TODO fix the coordinates see http://zhengrui.github.io/android-coordinates.html

    if(scannedDoc != null && scannedDoc.detectedQuad != null){
        //boolean isPortrait = Util.isPortraitMode(mOverlay.getContext());
        Path path = new Path();

        /*
        Log.d("DOC-GRAPHIC", "IsPortrait? " + isPortrait);

        float tlX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[0].y):translateX((float) scannedDoc.detectedQuad.points[0].x);
        float tlY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[0].x):translateY((float) scannedDoc.detectedQuad.points[0].y);

        Log.d("DOC-GRAPHIC", "Top left: x: " + scannedDoc.detectedQuad.points[0].x + ", y: " + scannedDoc.detectedQuad.points[0].y
                + " -> x: " + tlX + ", y: " + tlY);

        float blX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[1].y):translateX((float) scannedDoc.detectedQuad.points[1].x);
        float blY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[1].x):translateY((float) scannedDoc.detectedQuad.points[1].y);

        Log.d("DOC-GRAPHIC", "Bottom left: x: " + scannedDoc.detectedQuad.points[1].x + ", y: " + scannedDoc.detectedQuad.points[1].y
                + " -> x: " + blX + ", y: " + blY);

        float brX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[2].y):translateX((float) scannedDoc.detectedQuad.points[2].x);
        float brY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[2].x):translateY((float) scannedDoc.detectedQuad.points[2].y);

        Log.d("DOC-GRAPHIC", "Bottom right: x: " + scannedDoc.detectedQuad.points[2].x + ", y: " + scannedDoc.detectedQuad.points[2].y
                + " -> x: " + brX + ", y: " + brY);

        float trX = isPortrait? translateY((float) scannedDoc.detectedQuad.points[3].y):translateX((float) scannedDoc.detectedQuad.points[3].x);
        float trY = isPortrait? translateX((float) scannedDoc.detectedQuad.points[3].x):translateY((float) scannedDoc.detectedQuad.points[3].y);

        Log.d("DOC-GRAPHIC", "Top right: x: " + scannedDoc.detectedQuad.points[3].x + ", y: " + scannedDoc.detectedQuad.points[3].y
                + " -> x: " + trX + ", y: " + trY);
        */
        int frameWidth = scannedDoc.getImage().getMetadata().getHeight();

        path.moveTo(((float)(frameWidth - scannedDoc.detectedQuad.points[0].y)), ((float)scannedDoc.detectedQuad.points[0].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[1].y)), ((float)scannedDoc.detectedQuad.points[1].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[2].y)), ((float)scannedDoc.detectedQuad.points[2].x));
        path.lineTo(((float)(frameWidth - scannedDoc.detectedQuad.points[3].y)), ((float)scannedDoc.detectedQuad.points[3].x));
        path.close();

        PathShape shape = new PathShape(path, scannedDoc.getImage().getMetadata().getHeight(), scannedDoc.getImage().getMetadata().getWidth());
        shape.resize(canvas.getWidth(), canvas.getHeight());

        shape.draw(canvas, bodyPaint);
        shape.draw(canvas, borderPaint);

        //canvas.drawPath(path, borderPaint);
        //canvas.drawPath(path, bodyPaint);

        Log.d("DOC-GRAPHIC", "DONE DRAWING");
    }
}
 
Example #6
Source File: ImageProcessor.java    From react-native-documentscanner-android with MIT License 3 votes vote down vote up
private void drawDocumentBox(Point[] points, Size stdSize) {

        Path path = new Path();

        HUDCanvasView hud = mMainActivity.getHUD();

        // ATTENTION: axis are swapped

        float previewWidth = (float) stdSize.height;
        float previewHeight = (float) stdSize.width;

        path.moveTo( previewWidth - (float) points[0].y, (float) points[0].x );
        path.lineTo( previewWidth - (float) points[1].y, (float) points[1].x );
        path.lineTo( previewWidth - (float) points[2].y, (float) points[2].x );
        path.lineTo( previewWidth - (float) points[3].y, (float) points[3].x );
        path.close();

        PathShape newBox = new PathShape(path , previewWidth , previewHeight);

        Paint paint = new Paint();
        paint.setColor(Color.argb(180, 66, 165, 245));

        Paint border = new Paint();
        border.setColor(Color.rgb(66, 165, 245));
        border.setStrokeWidth(5);

        hud.clear();
        hud.addShape(newBox, paint, border);
        mMainActivity.invalidateHUD();


    }