Example usage for android.graphics Path reset

List of usage examples for android.graphics Path reset

Introduction

In this page you can find the example usage for android.graphics Path reset.

Prototype

public void reset() 

Source Link

Document

Clear any lines and curves from the path, making it empty.

Usage

From source file:Main.java

public static void drawBorder(int width, int height, Canvas canvas, Paint paint, Path workingPath) {

    paint.setStyle(Paint.Style.STROKE);
    workingPath.reset();
    workingPath.moveTo(0, 0);//from  w w w . ja  va 2 s  .  com
    workingPath.lineTo(width, 0);
    workingPath.lineTo(width, height);
    workingPath.lineTo(0, height);
    workingPath.lineTo(0, 0);
    workingPath.close();

    canvas.drawPath(workingPath, paint);

}

From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.MarkerDrawable.java

private void computePath(Rect bounds) {
    final float currentScale = mCurrentScale;
    final Path path = mPath;
    final RectF rect = mRect;
    final Matrix matrix = mMatrix;

    path.reset();
    int totalSize = Math.min(bounds.width(), bounds.height());

    float initial = mClosedStateSize;
    float destination = totalSize;
    float currentSize = initial + (destination - initial) * currentScale;

    float halfSize = currentSize / 2f;
    float inverseScale = 1f - currentScale;
    float cornerSize = halfSize * inverseScale;
    float[] corners = new float[] { halfSize, halfSize, halfSize, halfSize, halfSize, halfSize, cornerSize,
            cornerSize };//  ww w . java2s  .c  om
    rect.set(bounds.left, bounds.top, bounds.left + currentSize, bounds.top + currentSize);
    path.addRoundRect(rect, corners, Path.Direction.CCW);
    matrix.reset();
    matrix.postRotate(-45, bounds.left + halfSize, bounds.top + halfSize);
    matrix.postTranslate((bounds.width() - currentSize) / 2, 0);
    float hDiff = (bounds.bottom - currentSize - mExternalOffset) * inverseScale;
    matrix.postTranslate(0, hDiff);
    path.transform(matrix);
}

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void drawShadow(Canvas canvas, float _sunPosX, float _sunPosY) {
    tmpSunPositionVector.setPosition(_sunPosX, _sunPosY);
    shadowPath.reset();/*from  ww w.j  av  a 2 s. c  om*/
    for (int i = 0; i < vertexArray.size(); i++) {
        Path tmpPath = shadowPaths.get(i);
        tmpPath.reset();

        AVector v1 = vertexArray.get(i);
        AVector v2 = vertexArray.get(i == getVertCount() - 1 ? 0 : i + 1);

        tmpPath.moveTo(v2.getX(), v2.getY());
        tmpPath.lineTo(v1.getX(), v1.getY());

        // Current shadow vertex
        AVector tmpShadowVector = AVector.sub(v1, tmpSunPositionVector);
        tmpShadowVector.normalize();
        tmpShadowVector.multiply(600.0f);
        tmpShadowVector.add(v1);

        tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY());

        // Current shadow vertex
        tmpShadowVector = AVector.sub(v2, tmpSunPositionVector);
        tmpShadowVector.normalize();
        tmpShadowVector.multiply(600.0f);
        tmpShadowVector.add(v2);

        tmpPath.lineTo(tmpShadowVector.getX(), tmpShadowVector.getY());
        tmpPath.close();

        shadowPath.op(tmpPath, Path.Op.UNION);
    }
    canvas.drawPath(shadowPath, shadowPathPaint);
}

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void parseJSON(String jsonFile) {
    if (jsonFile != null) {
        // Load all the JSONs with the numbers information
        try {/*w w  w .jav  a 2s. co m*/
            JSONObject obj = new JSONObject(loadJSONFromAsset(jsonFile));
            Log.d(TAG, "SHAPE SHADOW JSON FILE " + jsonFile + ": LOADED");

            id = obj.getString("id");

            JSONArray jsonPathData;
            JSONArray jsonShadowData;

            if (!id.equals("5")) {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    try {
                        JSONObject elem = jsonPathData.getJSONObject(i);
                        String type = elem.getString("type");
                        JSONArray data = elem.getJSONArray("data");
                        if (type.equals("move")) {
                            shapePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("line")) {
                            shapePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                        } else if (type.equals("bezier")) {
                            shapePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                    (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                    (float) data.getInt(5));
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "JSON ELEM EXCEPTION" + e.getMessage() + "");
                    }
                }
                shapePath.close();

                Random r = new Random();
                r.nextGaussian();

                JSONArray holesContainer = obj.getJSONArray("holes");
                Path holePath = new Path();
                for (int i = 0; i < holesContainer.length(); i++) {
                    JSONObject jsonInside = holesContainer.getJSONObject(i);
                    JSONArray hole = jsonInside.getJSONArray("data");
                    holePath.reset();
                    for (int j = 0; j < hole.length(); j++) {
                        try {
                            JSONObject elem = hole.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                holePath.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                holePath.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                holePath.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON HOLE EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    holePath.close();
                    shapePath.op(holePath, Path.Op.DIFFERENCE);
                }

                pathTransform.reset();
                pathTransform.setScale(scale + 0.04f, scale + 0.04f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX - 0.3f, positionY - 0.3f);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                int shadowTmpX;
                int shadowTmpY;

                shadowPaths.clear();
                vertexArray.clear();

                for (int i = 0; i < jsonShadowData.length(); i += 2) {
                    shadowTmpX = jsonShadowData.getInt(i);
                    shadowTmpY = jsonShadowData.getInt(i + 1);
                    addVertex(shadowTmpX, shadowTmpY);
                }
            } else {
                jsonPathData = obj.getJSONArray("path");
                jsonShadowData = obj.getJSONArray("shadow");

                Log.d(TAG, "JSON PATH DATA LENGTH: " + jsonPathData.length() + "");
                Log.d(TAG, "JSON SHADOW DATA LENGTH: " + jsonShadowData.length() + "");

                shapePath.reset();
                for (int i = 0; i < jsonPathData.length(); i++) {
                    JSONArray cords = jsonPathData.getJSONArray(i);
                    Path chunk = new Path();
                    chunk.reset();
                    for (int j = 0; j < cords.length(); j++) {
                        try {
                            JSONObject elem = cords.getJSONObject(j);
                            String type = elem.getString("type");
                            JSONArray data = elem.getJSONArray("data");
                            if (type.equals("move")) {
                                chunk.moveTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("line")) {
                                chunk.lineTo((float) data.getInt(0), (float) data.getInt(1));
                            } else if (type.equals("bezier")) {
                                chunk.cubicTo((float) data.getInt(0), (float) data.getInt(1),
                                        (float) data.getInt(2), (float) data.getInt(3), (float) data.getInt(4),
                                        (float) data.getInt(5));
                            }
                        } catch (JSONException e) {
                            Log.d(TAG, "JSON 5 NUMBER ELEM EXCEPTION" + e.getMessage() + "");
                        }
                    }
                    chunk.close();
                    shapePath.op(chunk, Path.Op.UNION);
                }

                pathTransform.reset();
                pathTransform.setScale(scale, scale);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                pathTransform.setTranslate(positionX, positionY);
                shapePath.transform(pathTransform);
                boundsPath.transform(pathTransform);

                shadowPaths.clear();
                vertexArray.clear();

                int shadowTmpX;
                int shadowTmpY;
                for (int i = 0; i < jsonShadowData.length(); i++) {
                    JSONArray coords = jsonShadowData.getJSONArray(i);
                    for (int j = 0; j < coords.length(); j += 2) {
                        shadowTmpX = coords.getInt(j);
                        shadowTmpY = coords.getInt(j + 1);
                        addVertex((float) shadowTmpX, (float) shadowTmpY);
                    }

                }
            }
        } catch (JSONException e) {
            Log.d(TAG, "JSON ROOT EXCEPTION" + e.getMessage() + "");
        }
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (mDebugMode) {
        mPaint.setStyle(Style.FILL_AND_STROKE);
        final Path path = new Path();

        path.reset();
        mCellsRegion.getBoundaryPath(path);
        path.close();// w  w  w. j a  v a2  s .  c om
        mPaint.setColor(0x660000cc);
        canvas.drawPath(path, mPaint);

        path.reset();
        mFreeCellsRegion.getBoundaryPath(path);
        path.close();
        mPaint.setColor(0x66cc0000);
        canvas.drawPath(path, mPaint);
    }

    if (mRootView == null) {
        drawCellGrid(canvas);
    }
    super.dispatchDraw(canvas);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) {
    final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f);
    final int color = applyAlpha(mSelectorColor, alpha);

    // Calculate the current radius at which to place the selection circle.
    final int selRadius = mSelectorRadius;
    final int selLength = mCircleRadius - mTextInset[index];
    final double selAngleRad = Math.toRadians(mSelectionDegrees[index % 2]);
    final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad);
    final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad);

    // Draw the selection circle.
    final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);/*from w  w w.  j ava2 s .c om*/
    canvas.drawCircle(selCenterX, selCenterY, selRadius, paint);

    // If needed, set up the clip path for later.
    if (selectorPath != null) {
        selectorPath.reset();
        selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW);
    }

    // Draw the dot if we're between two items.
    final boolean shouldDrawDot = mSelectionDegrees[index % 2] % 30 != 0;
    if (shouldDrawDot) {
        final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT];
        dotPaint.setColor(mSelectorDotColor);
        canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint);
    }

    // Shorten the line to only go from the edge of the center dot to the
    // edge of the selection circle.
    final double sin = Math.sin(selAngleRad);
    final double cos = Math.cos(selAngleRad);
    final int lineLength = selLength - selRadius;
    final int centerX = mXCenter + (int) (mCenterDotRadius * sin);
    final int centerY = mYCenter - (int) (mCenterDotRadius * cos);
    final float linePointX = centerX + (int) (lineLength * sin);
    final float linePointY = centerY - (int) (lineLength * cos);

    // Draw the line.
    final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE];
    linePaint.setColor(color);
    linePaint.setStrokeWidth(mSelectorStroke);
    canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint);
}