Java Code Examples for android.graphics.Path#addRect()

The following examples show how to use android.graphics.Path#addRect() . 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: CropImageView.java    From SimpleCropView with MIT License 6 votes vote down vote up
private void drawOverlay(Canvas canvas) {
  mPaintTranslucent.setAntiAlias(true);
  mPaintTranslucent.setFilterBitmap(true);
  mPaintTranslucent.setColor(mOverlayColor);
  mPaintTranslucent.setStyle(Paint.Style.FILL);
  Path path = new Path();
  RectF overlayRect =
      new RectF((float) Math.floor(mImageRect.left), (float) Math.floor(mImageRect.top),
          (float) Math.ceil(mImageRect.right), (float) Math.ceil(mImageRect.bottom));
  if (!mIsAnimating && (mCropMode == CropMode.CIRCLE || mCropMode == CropMode.CIRCLE_SQUARE)) {
    path.addRect(overlayRect, Path.Direction.CW);
    PointF circleCenter = new PointF((mFrameRect.left + mFrameRect.right) / 2,
        (mFrameRect.top + mFrameRect.bottom) / 2);
    float circleRadius = (mFrameRect.right - mFrameRect.left) / 2;
    path.addCircle(circleCenter.x, circleCenter.y, circleRadius, Path.Direction.CCW);
    canvas.drawPath(path, mPaintTranslucent);
  } else {
    path.addRect(overlayRect, Path.Direction.CW);
    path.addRect(mFrameRect, Path.Direction.CCW);
    canvas.drawPath(path, mPaintTranslucent);
  }
}
 
Example 2
Source File: HighlightView.java    From LockDemo with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (showCircle) {
            drawCircle(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example 3
Source File: CanvasView.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method initializes canvas.
 *
 * @return
 */
public void clear() {
    Path path = new Path();
    path.moveTo(0F, 0F);
    path.addRect(0F, 0F, 1000F, 1000F, Path.Direction.CCW);
    path.close();

    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#303030"));
    paint.setStyle(Paint.Style.FILL);

    if (this.historyPointer == this.pathLists.size()) {
        this.pathLists.add(path);
        this.paintLists.add(paint);
        this.historyPointer++;
    } else {
        // On the way of Undo or Redo
        this.pathLists.set(this.historyPointer, path);
        this.paintLists.set(this.historyPointer, paint);
        this.historyPointer++;

        for (int i = this.historyPointer, size = this.paintLists.size(); i < size; i++) {
            this.pathLists.remove(this.historyPointer);
            this.paintLists.remove(this.historyPointer);
        }
    }

    this.text = "";

    // Clear
    this.invalidate();
}
 
Example 4
Source File: TextElement.java    From cidrawing with Apache License 2.0 5 votes vote down vote up
@Override
protected void calculateBoundingBox() {
    Rect box = new Rect();
    paint.getTextBounds(text, 0, text.length(), box);
    originalBoundingBox = new RectF(box);
    boundingPath = new Path();
    boundingPath.addRect(originalBoundingBox, Path.Direction.CW);
    boundingPath.transform(dataMatrix);
    updateBoundingBox();
}
 
Example 5
Source File: BorderDrawable.java    From weex-uikit with MIT License 5 votes vote down vote up
private void prepareBorderPath(int topPadding,
                               int rightPadding,
                               int bottomPadding,
                               int leftPadding,
                               @NonNull RectF rectF,
                               @NonNull Path path) {
  if (mBorderRadius != null) {
    prepareBorderRadius(rectF);
    float topLeftRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_LEFT_RADIUS);
    float topRightRadius = getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_RIGHT_RADIUS);
    float bottomRightRadius = getBorderRadius(mOverlappingBorderRadius,
                                              BORDER_BOTTOM_RIGHT_RADIUS);
    float bottomLeftRadius = getBorderRadius(mOverlappingBorderRadius,
                                             BORDER_BOTTOM_LEFT_RADIUS);
    path.addRoundRect(
        rectF,
        new float[]{
            topLeftRadius - leftPadding,
            topLeftRadius - topPadding,
            topRightRadius - rightPadding,
            topRightRadius - topPadding,
            bottomRightRadius - rightPadding,
            bottomRightRadius - bottomPadding,
            bottomLeftRadius - leftPadding,
            bottomLeftRadius - bottomPadding
        },
        Path.Direction.CW);
  } else {
    path.addRect(rectF, Path.Direction.CW);
  }
}
 
Example 6
Source File: CanvasView.java    From Memento with MIT License 5 votes vote down vote up
/**
 * This method initializes canvas.
 *
 * @return
 */
public void clear() {
    Path path = new Path();
    path.moveTo(0F, 0F);
    path.addRect(0F, 0F, 1000F, 1000F, Path.Direction.CCW);
    path.close();

    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.FILL);

    if (this.historyPointer == this.pathLists.size()) {
        this.pathLists.add(path);
        this.paintLists.add(paint);
        this.historyPointer++;
    } else {
        // On the way of Undo or Redo
        this.pathLists.set(this.historyPointer, path);
        this.paintLists.set(this.historyPointer, paint);
        this.historyPointer++;

        for (int i = this.historyPointer, size = this.paintLists.size(); i < size; i++) {
            this.pathLists.remove(this.historyPointer);
            this.paintLists.remove(this.historyPointer);
        }
    }

    this.text = "";

    // Clear
    this.invalidate();
}
 
Example 7
Source File: HighlightView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example 8
Source File: HighlightView.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (showCircle) {
            drawCircle(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example 9
Source File: HighlightView.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (showCircle) {
            drawCircle(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example 10
Source File: SmartSelectSprite.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Path generateOutlinePolygonPath(
        final List<RoundedRectangleShape> rectangles) {
    final Path path = new Path();
    for (final RoundedRectangleShape shape : rectangles) {
        final Path rectanglePath = new Path();
        rectanglePath.addRect(shape.mBoundingRectangle, Path.Direction.CW);
        path.op(rectanglePath, Path.Op.UNION);
    }
    return path;
}
 
Example 11
Source File: ShiftDrawable.java    From CoolIndicator with MIT License 5 votes vote down vote up
private void updateBounds() {
    final Rect b = getBounds();
    final int width = (int) ((float) b.width() * getLevel() / MAX_LEVEL);
    final float radius = b.height() / 2f;
    mVisibleRect.set(b.left, b.top, b.left + width, b.height());

    // draw round to head of progressbar. I know it looks stupid, don't blame me now.
    mPath = new Path();
    mPath.addRect(b.left, b.top, b.left + width - radius, b.height(), Path.Direction.CCW);
    mPath.addCircle(b.left + width - radius, radius, radius, Path.Direction.CCW);
}
 
Example 12
Source File: DrawElement.java    From cidrawing with Apache License 2.0 5 votes vote down vote up
public Path getTouchableArea() {
    Path path = new Path();
    if (getBoundingBox() != null) {
        path.addRect(getBoundingBox(), Path.Direction.CW);
    }
    return path;
}
 
Example 13
Source File: HighlightView.java    From MyBlogDemo with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example 14
Source File: DrawElement.java    From cidrawing with Apache License 2.0 5 votes vote down vote up
/**
 * Return the actual bounding box of the graphics without transformation
 *
 * @return
 */
public RectF getOuterBoundingBox() {
    if (boundingBox != null) {
        Path path = new Path();
        path.addRect(boundingBox, Path.Direction.CW);
        path.transform(getDisplayMatrix());
        RectF box = new RectF();
        path.computeBounds(box, true);
        return box;
    }
    return new RectF();
}
 
Example 15
Source File: DingRegionManager.java    From CombineBitmap with Apache License 2.0 5 votes vote down vote up
@Override
public Region[] calculateRegion(int size, int subSize, int gap, int count) {
    Region[] regions = new Region[count];
    Region globalRegion = new Region(0, 0, size, size);

    int[][] dxy = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};

    for (int i = 0; i < count; i++) {
        float width = size;
        float height = size;

        if (count == 2 || (count == 3 && i == 0)) {
            width = (size - gap) / 2;
            height = size;
        } else if ((count == 3 && (i == 1 || i == 2)) || count == 4) {
            width = (size - gap) / 2;
            height = (size - gap) / 2;
        }

        int dx = dxy[i][0];
        int dy = dxy[i][1];

        float left = dx * (size + gap) / 2.0f;
        float top = dy * (size + gap) / 2.0f;
        float right = left + width;
        float bottom = top + height;
        Path path = new Path();
        path.addRect(left, top, right, bottom, Path.Direction.CW);

        Region region = new Region();
        region.setPath(path, globalRegion);

        regions[i] = region;
    }
    return regions;
}
 
Example 16
Source File: LanesStyleKit.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
public static void drawLaneStraight(Canvas canvas, RectF targetFrame, ResizingBehavior resizing, int primaryColor, PointF size) {
  // General Declarations
  Stack<Matrix> currentTransformation = new Stack<Matrix>();
  currentTransformation.push(new Matrix());
  Paint paint = CacheForLaneStraight.paint;

  // Local Variables
  float expression = Math.min(size.x / 30f, size.y / 30f);

  // Resize to Target Frame
  canvas.save();
  RectF resizedFrame = CacheForLaneStraight.resizedFrame;
  LanesStyleKit.resizingBehaviorApply(resizing, CacheForLaneStraight.originalFrame, targetFrame, resizedFrame);
  canvas.translate(resizedFrame.left, resizedFrame.top);
  canvas.scale(resizedFrame.width() / 30f, resizedFrame.height() / 30f);

  // Frame
  RectF frame = CacheForLaneStraight.frame;
  frame.set(0f, 0f, size.x, size.y);

  // Group
  {
    RectF group = CacheForLaneStraight.group;
    group.set(0f, 0f, 12.02f, 24f);
    canvas.save();
    canvas.translate(9f, 3f);
    currentTransformation.peek().postTranslate(9f, 3f);
    canvas.scale(expression, expression);
    currentTransformation.peek().postScale(expression, expression);

    // Rectangle
    RectF rectangleRect = CacheForLaneStraight.rectangleRect;
    rectangleRect.set(4f, 8f, 8f, 24f);
    Path rectanglePath = CacheForLaneStraight.rectanglePath;
    rectanglePath.reset();
    rectanglePath.addRect(rectangleRect, Path.Direction.CW);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(rectanglePath, paint);

    // Bezier
    RectF bezierRect = CacheForLaneStraight.bezierRect;
    bezierRect.set(0f, 0f, 12.02f, 9.99f);
    Path bezierPath = CacheForLaneStraight.bezierPath;
    bezierPath.reset();
    bezierPath.moveTo(group.left + group.width() * 0.33372f, group.top + group.height() * 0.4135f);
    bezierPath.lineTo(group.left + group.width() * 0.33414f, group.top + group.height() * 0.36075f);
    bezierPath.lineTo(group.left + group.width() * 0.33397f, group.top + group.height() * 0.36096f);
    bezierPath.cubicTo(group.left + group.width() * 0.33397f, group.top + group.height() * 0.35842f, group.left + group.width() * 0.33364f, group.top + group.height() * 0.35542f, group.left + group.width() * 0.33364f, group.top + group.height() * 0.35262f);
    bezierPath.cubicTo(group.left + group.width() * 0.33364f, group.top + group.height() * 0.3405f, group.left + group.width() * 0.31766f, group.top + group.height() * 0.33075f, group.left + group.width() * 0.29345f, group.top + group.height() * 0.33075f);
    bezierPath.cubicTo(group.left + group.width() * 0.29096f, group.top + group.height() * 0.33075f, group.left + group.width() * 0.28796f, group.top + group.height() * 0.33079f, group.left + group.width() * 0.28563f, group.top + group.height() * 0.331f);
    bezierPath.lineTo(group.left + group.width() * 0.28588f, group.top + group.height() * 0.33087f);
    bezierPath.lineTo(group.left + group.width() * 0.05882f, group.top + group.height() * 0.37217f);
    bezierPath.lineTo(group.left + group.width() * 0.05916f, group.top + group.height() * 0.37212f);
    bezierPath.cubicTo(group.left + group.width() * 0.05416f, group.top + group.height() * 0.37312f, group.left + group.width() * 0.04867f, group.top + group.height() * 0.37371f, group.left + group.width() * 0.04293f, group.top + group.height() * 0.37371f);
    bezierPath.cubicTo(group.left + group.width() * 0.01922f, group.top + group.height() * 0.37371f, group.left, group.top + group.height() * 0.36408f, group.left, group.top + group.height() * 0.35221f);
    bezierPath.cubicTo(group.left, group.top + group.height() * 0.346f, group.left + group.width() * 0.00516f, group.top + group.height() * 0.34033f, group.left + group.width() * 0.01356f, group.top + group.height() * 0.33642f);
    bezierPath.lineTo(group.left + group.width() * 0.01331f, group.top + group.height() * 0.3365f);
    bezierPath.lineTo(group.left + group.width() * 0.50046f, group.top);
    bezierPath.lineTo(group.left + group.width() * 0.98669f, group.top + group.height() * 0.33908f);
    bezierPath.lineTo(group.left + group.width() * 0.98644f, group.top + group.height() * 0.339f);
    bezierPath.cubicTo(group.left + group.width() * 0.99484f, group.top + group.height() * 0.34292f, group.left + group.width(), group.top + group.height() * 0.34862f, group.left + group.width(), group.top + group.height() * 0.35483f);
    bezierPath.cubicTo(group.left + group.width(), group.top + group.height() * 0.36671f, group.left + group.width() * 0.98078f, group.top + group.height() * 0.37629f, group.left + group.width() * 0.95707f, group.top + group.height() * 0.37629f);
    bezierPath.cubicTo(group.left + group.width() * 0.95133f, group.top + group.height() * 0.37629f, group.left + group.width() * 0.94584f, group.top + group.height() * 0.37575f, group.left + group.width() * 0.94084f, group.top + group.height() * 0.37471f);
    bezierPath.lineTo(group.left + group.width() * 0.94118f, group.top + group.height() * 0.37475f);
    bezierPath.lineTo(group.left + group.width() * 0.71412f, group.top + group.height() * 0.33346f);
    bezierPath.lineTo(group.left + group.width() * 0.71437f, group.top + group.height() * 0.33358f);
    bezierPath.cubicTo(group.left + group.width() * 0.71204f, group.top + group.height() * 0.33342f, group.left + group.width() * 0.70904f, group.top + group.height() * 0.33333f, group.left + group.width() * 0.70655f, group.top + group.height() * 0.33333f);
    bezierPath.cubicTo(group.left + group.width() * 0.68234f, group.top + group.height() * 0.33333f, group.left + group.width() * 0.66636f, group.top + group.height() * 0.34308f, group.left + group.width() * 0.66636f, group.top + group.height() * 0.35521f);
    bezierPath.cubicTo(group.left + group.width() * 0.66636f, group.top + group.height() * 0.358f, group.left + group.width() * 0.66603f, group.top + group.height() * 0.361f, group.left + group.width() * 0.66603f, group.top + group.height() * 0.36354f);
    bezierPath.lineTo(group.left + group.width() * 0.66586f, group.top + group.height() * 0.36338f);
    bezierPath.lineTo(group.left + group.width() * 0.66628f, group.top + group.height() * 0.41608f);

    paint.reset();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    bezierPath.setFillType(Path.FillType.EVEN_ODD);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(primaryColor);
    canvas.drawPath(bezierPath, paint);

    canvas.restore();
  }

  canvas.restore();
}
 
Example 17
Source File: ComposedFrame.java    From Tehreer-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a path that contains a set of rectangles covering the specified selection range.
 *
 * @param charStart The index to the first character of selection in source text.
 * @param charEnd The index after the first character of selection in source text.
 * @return A path that contains a set of rectangles covering the specified selection range.
 *
 * @throws IllegalArgumentException if <code>charStart</code> is less than frame start, or
 *         <code>charEnd</code> is greater than frame end, or <code>charStart</code> is greater
 *         than <code>charEnd</code>.
 */
public @NonNull Path generateSelectionPath(int charStart, int charEnd) {
    checkSubRange(charStart, charEnd);

    Path selectionPath = new Path();

    int firstIndex = getLineIndexForChar(charStart);
    int lastIndex = getLineIndexForChar(charEnd);

    ComposedLine firstLine = lineList.get(firstIndex);
    ComposedLine lastLine = lineList.get(lastIndex);

    float firstTop = firstLine.getTop();
    float lastBottom = lastLine.getBottom();

    if (firstLine == lastLine) {
        addSelectionParts(firstLine, charStart, charEnd, firstTop, lastBottom, selectionPath);
    } else {
        float frameLeft = 0.0f;
        float frameRight = mWidth;

        float firstBottom = firstLine.getBottom();
        float lastTop = lastLine.getTop();

        // Select each intersecting part of first line.
        addSelectionParts(firstLine, charStart, firstLine.getCharEnd(),
                          firstTop, firstBottom, selectionPath);

        // Select trailing padding of first line.
        if ((lastLine.getParagraphLevel() & 1) == 1) {
            selectionPath.addRect(frameLeft, firstTop,
                                  firstLine.getLeft(), firstBottom, Path.Direction.CW);
        } else {
            selectionPath.addRect(firstLine.getRight(), firstTop,
                                  frameRight, firstBottom, Path.Direction.CW);
        }

        // Select whole part of each mid line.
        for (int i = firstIndex + 1; i < lastIndex; i++) {
            ComposedLine midLine = lineList.get(i);
            float midTop = midLine.getTop();
            float midBottom = midLine.getBottom();

            selectionPath.addRect(frameLeft, midTop,
                                  frameRight, midBottom, Path.Direction.CW);
        }

        // Select leading padding of last line.
        if ((lastLine.getParagraphLevel() & 1) == 1) {
            selectionPath.addRect(lastLine.getRight(), lastTop,
                                  frameRight, lastBottom, Path.Direction.CW);
        } else {
            selectionPath.addRect(frameLeft, lastTop,
                                  lastLine.getLeft(), lastBottom, Path.Direction.CW);
        }

        // Select each intersecting part of last line.
        addSelectionParts(lastLine, lastLine.getCharStart(), charEnd,
                          lastTop, lastBottom, selectionPath);
    }

    return selectionPath;
}
 
Example 18
Source File: BaseImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/**
     * get clip path of StyleDrawable
     *
     * @return
     */
    Path getClipPath() {
//        if (mPath == null) {
//            mPath = new Path();
//        }
        mPath = new Path();
        Rect rect = mStyleDrawable.getBounds();
        float radius = mStyleDrawable.getCornerRadius();
        float[] radii = mStyleDrawable.getCornerRadii();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (radii == null || radii.length == 0) {
                mPath.addRoundRect(rect.left, rect.top, rect.right, rect.bottom, radius, radius,
                        Path.Direction.CW);
            } else {
                mPath.addRoundRect(rect.left, rect.top, rect.right, rect.bottom, radii,
                        Path.Direction.CW);
            }
        } else {
            if (radii == null || radii.length == 0) {
                mPath.addCircle(rect.left + radius, rect.top + radius, radius, Path.Direction.CW);
                mPath.addCircle(rect.right - radius, rect.top + radius, radius, Path.Direction.CW);
                mPath.addCircle(rect.right - radius, rect.bottom - radius, radius, Path.Direction.CW);
                mPath.addCircle(rect.left + radius, rect.bottom - radius, radius, Path.Direction.CW);
                mPath.addRect(rect.left + radius, rect.top, rect.right - radius, rect.bottom, Path.Direction.CW);
                mPath.addRect(rect.left, rect.top + radius, rect.right, rect.bottom - radius, Path.Direction.CW);
            } else {
                float topLeftX = radii[0], topLeftY = radii[1];
                float topRightX = radii[2], topRightY = radii[3];
                float bottomLeftX = radii[4], bottomLeftY = radii[5];
                float bottomRightX = radii[6], bottomRightY = radii[7];
                mPath.addCircle(rect.left + topLeftX, rect.top + topLeftY, topLeftY, Path.Direction.CW);
                mPath.addCircle(rect.right - topRightX, rect.top + topRightY, topRightY, Path.Direction.CW);
                mPath.addCircle(rect.right - bottomLeftX, rect.bottom - bottomLeftY, bottomLeftY, Path.Direction.CW);
                mPath.addCircle(rect.left + bottomRightX, rect.bottom - bottomRightY, bottomRightY, Path.Direction.CW);
                mPath.addRect(rect.left + topLeftX, rect.top, rect.right - topRightX, rect.bottom, Path.Direction.CW);
                mPath.addRect(rect.left, rect.top + topLeftY, rect.right, rect.bottom - bottomLeftY, Path.Direction.CW);
            }

        }
        return mPath;
    }
 
Example 19
Source File: RectElement.java    From cidrawing with Apache License 2.0 4 votes vote down vote up
@Override
protected Path createShapePath() {
    Path path = new Path();
    path.addRect(shapeBox, Path.Direction.CW);
    return path;
}
 
Example 20
Source File: PathMeasureView.java    From zone-sdk with MIT License 3 votes vote down vote up
private void testGetSegment(Canvas canvas, boolean startWithMoveTo) {

        Path path = new Path();                                     // 创建Path并添加了一个矩形
        path.addRect(-200, -200, 200, 200, Path.Direction.CW);

        Path dst = new Path();                                      // 创建用于存储截取后内容的 Path
        dst.lineTo(-300, -300);                                     // <--- 在 dst 中添加一条线段

        PathMeasure measure = new PathMeasure(path, false);         // 将 Path 与 PathMeasure 关联

        measure.getSegment(200, 600, dst, startWithMoveTo);                   // 截取一部分 并使用 moveTo 保持截取得到的 Path 第一个点的位置不变

        canvas.drawPath(dst, mDeafultPaint);
    }