Java Code Examples for android.graphics.Canvas.drawPath()

The following are Jave code examples for showing how to use drawPath() of the android.graphics.Canvas class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: boohee_v5.6   File: MaterialProgressDrawable.java   View Source Code Vote up 6 votes
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
    if (this.mShowArrow) {
        if (this.mArrow == null) {
            this.mArrow = new Path();
            this.mArrow.setFillType(FillType.EVEN_ODD);
        } else {
            this.mArrow.reset();
        }
        float inset = ((float) (((int) this.mStrokeInset) / 2)) * this.mArrowScale;
        float x = (float) ((this.mRingCenterRadius * Math.cos(0.0d)) + ((double) bounds.exactCenterX()));
        float y = (float) ((this.mRingCenterRadius * Math.sin(0.0d)) + ((double) bounds.exactCenterY()));
        this.mArrow.moveTo(0.0f, 0.0f);
        this.mArrow.lineTo(((float) this.mArrowWidth) * this.mArrowScale, 0.0f);
        this.mArrow.lineTo((((float) this.mArrowWidth) * this.mArrowScale) / 2.0f, ((float) this.mArrowHeight) * this.mArrowScale);
        this.mArrow.offset(x - inset, y);
        this.mArrow.close();
        this.mArrowPaint.setColor(this.mCurrentColor);
        c.rotate((startAngle + sweepAngle) - 5.0f, bounds.exactCenterX(), bounds.exactCenterY());
        c.drawPath(this.mArrow, this.mArrowPaint);
    }
}
 
Example 2
Project: RNLearn_Project1   File: ARTShapeShadowNode.java   View Source Code Vote up 6 votes
@Override
public void draw(Canvas canvas, Paint paint, float opacity) {
  opacity *= mOpacity;
  if (opacity > MIN_OPACITY_FOR_DRAW) {
    saveAndSetupCanvas(canvas);
    if (mPath == null) {
      throw new JSApplicationIllegalArgumentException(
          "Shapes should have a valid path (d) prop");
    }
    if (setupFillPaint(paint, opacity)) {
      canvas.drawPath(mPath, paint);
    }
    if (setupStrokePaint(paint, opacity)) {
      canvas.drawPath(mPath, paint);
    }
    restoreCanvas(canvas);
  }
  markUpdateSeen();
}
 
Example 3
Project: LQRWeChat   File: BubbleImageView.java   View Source Code Vote up 6 votes
@Override
protected void onDraw(Canvas canvas) {
    if (getDrawable() == null) {
        return;
    }
    RectF rect = new RectF(getPaddingLeft(), getPaddingTop(), getRight()
            - getLeft() - getPaddingRight(), getBottom() - getTop()
            - getPaddingBottom());

    Path path = new Path();

    if (mArrowLocation == LOCATION_LEFT) {
        leftPath(rect, path);
    } else {
        rightPath(rect, path);
    }

    canvas.drawPath(path, mBitmapPaint);
    drawText(canvas, mAngle);
}
 
Example 4
Project: ucar-weex-core   File: BorderDrawable.java   View Source Code Vote up 6 votes
@Override
public void draw(@NonNull Canvas canvas) {
  canvas.save();
  updateBorderOutline();
  //Shader uses alpha as well.
  mPaint.setAlpha(255);
  if (mPathForBorderOutline != null) {
    int useColor = WXViewUtils.multiplyColorAlpha(mColor, mAlpha);
    if (mShader != null) {
      mPaint.setShader(mShader);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    } else if ((useColor >>> 24) != 0) {
      mPaint.setColor(useColor);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    }
  }
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  drawBorders(canvas);
  mPaint.setShader(null);
  canvas.restore();
}
 
Example 5
Project: SmartRefresh   File: WaveView.java   View Source Code Vote up 6 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final int width = getWidth();
    //重置画笔
    path.reset();
    //绘制贝塞尔曲线
    path.lineTo(0, headHeight);
    path.quadTo(width / 2, headHeight + waveHeight, width, headHeight);
    path.lineTo(width, 0);
    canvas.drawPath(path, paint);
}
 
Example 6
Project: RNLearn_Project1   File: DrawBorder.java   View Source Code Vote up 5 votes
private void drawRoundedBorders(Canvas canvas) {
  if (mBackgroundColor != 0) {
    PAINT.setColor(mBackgroundColor);
    canvas.drawPath(getPathForBorderRadius(), PAINT);
  }

  drawBorders(canvas);
}
 
Example 7
Project: Fitto   File: GameUtility.java   View Source Code Vote up 5 votes
public void paintTriplet(Triplet triplet, Canvas canvas, Paint tripletPaint,
                         Junction junctionsArray[], Path tripletPath) {
    int junctionNo1 = triplet.getJunctionNo1();
    int junctionNo2 = triplet.getJunctionNo2();
    int junctionNo3 = triplet.getJunctionNo3();

    tripletPath.reset();
    tripletPath.moveTo(junctionsArray[junctionNo1].getX(), junctionsArray[junctionNo1].getY());
    tripletPath.lineTo(junctionsArray[junctionNo2].getX(), junctionsArray[junctionNo2].getY());
    tripletPath.lineTo(junctionsArray[junctionNo3].getX(), junctionsArray[junctionNo3].getY());

    canvas.drawPath(tripletPath, tripletPaint);
}
 
Example 8
Project: microMathematics   File: CustomTextView.java   View Source Code Vote up 5 votes
private void drawVertLine(Canvas c)
{
    path.reset();
    path.moveTo(rect.centerX(), rect.top);
    path.lineTo(rect.centerX(), rect.bottom);
    c.drawPath(path, paint);
}
 
Example 9
Project: Bailan   File: DownloadProgressButton.java   View Source Code Vote up 5 votes
private void drawProgressRectBackground(Canvas canvas, int paintColor) {
    canvas.save();
    canvas.translate(getPaddingLeft(), getPaddingTop());
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(paintColor);
    drawRoundRectPath();
    canvas.drawPath(mRoundRectPath, mPaint);
    canvas.restore();
}
 
Example 10
Project: StrokeLayouts   File: StrokeFrameLayout.java   View Source Code Vote up 5 votes
@Override
protected void onDraw(Canvas canvas) {
    if (excludeSide != EXCLUDE_ALL) {
        canvas.getClipBounds(mDrawRect);
        mPath = PathHelper.calculatePath(this, mPath, mDrawRect, excludeSide);
        canvas.drawPath(mPath, strokePaint);
    }
    super.onDraw(canvas);
}
 
Example 11
Project: GitHub   File: PicassoDrawable.java   View Source Code Vote up 5 votes
private void drawDebugIndicator(Canvas canvas) {
  DEBUG_PAINT.setColor(WHITE);
  Path path = getTrianglePath(0, 0, (int) (16 * density));
  canvas.drawPath(path, DEBUG_PAINT);

  DEBUG_PAINT.setColor(loadedFrom.debugColor);
  path = getTrianglePath(0, 0, (int) (15 * density));
  canvas.drawPath(path, DEBUG_PAINT);
}
 
Example 12
Project: CustomWeight   File: GooView.java   View Source Code Vote up 4 votes
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // 画布整体向上偏移
        canvas.translate(0, -Utils.getStatusBarHeight(getResources()));

        stickyRadius = getStickyRadius();

        // 3、根据 dragCenter 动态计算 dragPoint 和 stickyPoint
        // dragPoint: 2圆圆心连线的垂线与 drag 圆的交点
        // stickyPoint: 2圆圆心连线的垂线与 sticky 圆的交点

        float xOffset = dragCenter.x - stickyCenter.x;
        float yOffset = dragCenter.y - stickyCenter.y;

        if (xOffset != 0) {
            // 斜率
            lineK = yOffset / xOffset;
        }
        dragPoint = GeometryUtil.getIntersectionPoints(dragCenter, dragRadius, lineK);
        stickyPoint = GeometryUtil.getIntersectionPoints(stickyCenter, stickyRadius, lineK);
        controlPoint = GeometryUtil.getPointByPercent(dragCenter, stickyCenter, 0.618f);


        // 1、绘制圆
        // 绘制拖拽圆
        canvas.drawCircle(dragCenter.x, dragCenter.y, dragRadius, paint);

        if (!isDragOutOfRange) {
            // 绘制固定圆
            canvas.drawCircle(stickyCenter.x, stickyCenter.y, stickyRadius, paint);
            // 2、使用贝塞尔曲线绘制连接部分
            Path path = new Path();
            // 设置起点
            path.moveTo(stickyPoint[0].x, stickyPoint[0].y);
            // 使用贝塞尔曲线连接
            path.quadTo(controlPoint.x, controlPoint.y, dragPoint[0].x, dragPoint[0].y);
            // 连线
            path.lineTo(dragPoint[1].x, dragPoint[1].y);
            path.quadTo(controlPoint.x, controlPoint.y, stickyPoint[1].x, stickyPoint[1].y);
//        path.close(); // 默认关闭
            canvas.drawPath(path, paint); // 绘制
        }
        // 绘制圈圈,以固定圆圆心为圆心,然后80为半径
        paint.setStyle(Paint.Style.STROKE);// 设置只有边线
        canvas.drawCircle(stickyCenter.x, stickyCenter.y, maxDistance, paint);
        paint.setStyle(Paint.Style.FILL);

    }
 
Example 13
Project: rongyunDemo   File: DragPointView.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.TRANSPARENT);
    if (out) {
        float dr = c2.r / 2 + c2.r * 4 * (brokenProgress / 100f);
        Log.i("info", "dr" + dr);
        canvas.drawCircle(c2.x, c2.y, c2.r / (brokenProgress + 1), paint);
        canvas.drawCircle(c2.x - dr, c2.y - dr, c2.r / (brokenProgress + 2), paint);
        canvas.drawCircle(c2.x + dr, c2.y - dr, c2.r / (brokenProgress + 2), paint);
        canvas.drawCircle(c2.x - dr, c2.y + dr, c2.r / (brokenProgress + 2), paint);
        canvas.drawCircle(c2.x + dr, c2.y + dr, c2.r / (brokenProgress + 2), paint);
    } else {
        // 绘制手指跟踪的圆形
        if (catchBitmap == null || (catchBitmap != null && catchBitmap.isRecycled())) {
            return;
        }
        canvas.drawBitmap(catchBitmap, c2.x - c2.r, c2.y - c2.r, paint);
        path.reset();
        float deltaX = c2.x - c1.x;
        float deltaY = -(c2.y - c1.y);
        double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
        double sin = deltaY / distance;
        double cos = deltaX / distance;
        nearby = distance < c2.r * maxDistance;
        if (nearby && !broken) {
            canvas.drawCircle(c1.x, c1.y, c1.r, paint);
            path.moveTo((float) (c1.x - c1.r * sin), (float) (c1.y - c1.r * cos));
            path.lineTo((float) (c1.x + c1.r * sin), (float) (c1.y + c1.r * cos));
            path.quadTo((c1.x + c2.x) / 2, (c1.y + c2.y) / 2, (float) (c2.x + c2.r * sin), (float) (c2.y + c2.r
                        * cos));
            path.lineTo((float) (c2.x - c2.r * sin), (float) (c2.y - c2.r * cos));
            path.quadTo((c1.x + c2.x) / 2, (c1.y + c2.y) / 2, (float) (c1.x - c1.r * sin), (float) (c1.y - c1.r
                        * cos));
            canvas.drawPath(path, paint);
        } else {
            broken = true; // 已经拉断了
        }
    }

}
 
Example 14
Project: GitHub   File: RoundedCornersDrawable.java   View Source Code Vote up 4 votes
@Override
public void draw(Canvas canvas) {
  Rect bounds = getBounds();
  switch (mType) {
    case CLIPPING:
      int saveCount = canvas.save();
      // clip, note: doesn't support anti-aliasing
      mPath.setFillType(Path.FillType.EVEN_ODD);
      canvas.clipPath(mPath);
      super.draw(canvas);
      canvas.restoreToCount(saveCount);
      break;
    case OVERLAY_COLOR:
      super.draw(canvas);
      mPaint.setColor(mOverlayColor);
      mPaint.setStyle(Paint.Style.FILL);
      mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
      canvas.drawPath(mPath, mPaint);

      if (mIsCircle) {
        // INVERSE_EVEN_ODD will only draw inverse circle within its bounding box, so we need to
        // fill the rest manually if the bounds are not square.
        float paddingH = (bounds.width() - bounds.height() + mBorderWidth) / 2f;
        float paddingV = (bounds.height() - bounds.width() + mBorderWidth) / 2f;
        if (paddingH > 0) {
          canvas.drawRect(bounds.left, bounds.top, bounds.left + paddingH, bounds.bottom, mPaint);
          canvas.drawRect(
              bounds.right - paddingH,
              bounds.top,
              bounds.right,
              bounds.bottom,
              mPaint);
        }
        if (paddingV > 0) {
          canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.top + paddingV, mPaint);
          canvas.drawRect(
              bounds.left,
              bounds.bottom - paddingV,
              bounds.right,
              bounds.bottom,
              mPaint);
        }
      }
      break;
  }

  if (mBorderColor != Color.TRANSPARENT) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(mBorderColor);
    mPaint.setStrokeWidth(mBorderWidth);
    mPath.setFillType(Path.FillType.EVEN_ODD);
    canvas.drawPath(mBorderPath, mPaint);
  }
}
 
Example 15
Project: SetupWizardLibCompat   File: GlifPatternDrawable.java   View Source Code Vote up 4 votes
private void renderOnCanvas(Canvas canvas, float scale) {
    canvas.save();
    canvas.scale(scale, scale);

    mTempPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));

    // Draw the pattern by creating the paths, adjusting the colors and drawing them. The path
    // values are extracted from the SVG of the pattern file.

    if (sPatternPaths == null) {
        sPatternPaths = new Path[NUM_PATHS];
        // Lightness values of the pattern, range 0 - 255
        sPatternLightness = new int[] { 10, 40, 51, 66, 91, 112, 130 };

        Path p = sPatternPaths[0] = new Path();
        p.moveTo(1029.4f, 357.5f);
        p.lineTo(1366f, 759.1f);
        p.lineTo(1366f, 0f);
        p.lineTo(1137.7f, 0f);
        p.close();

        p = sPatternPaths[1] = new Path();
        p.moveTo(1138.1f, 0f);
        p.rLineTo(-144.8f, 768f);
        p.rLineTo(372.7f, 0f);
        p.rLineTo(0f, -524f);
        p.cubicTo(1290.7f, 121.6f, 1219.2f, 41.1f, 1178.7f, 0f);
        p.close();

        p = sPatternPaths[2] = new Path();
        p.moveTo(949.8f, 768f);
        p.rCubicTo(92.6f, -170.6f, 213f, -440.3f, 269.4f, -768f);
        p.lineTo(585f, 0f);
        p.rLineTo(2.1f, 766f);
        p.close();

        p = sPatternPaths[3] = new Path();
        p.moveTo(471.1f, 768f);
        p.rMoveTo(704.5f, 0f);
        p.cubicTo(1123.6f, 563.3f, 1027.4f, 275.2f, 856.2f, 0f);
        p.lineTo(476.4f, 0f);
        p.rLineTo(-5.3f, 768f);
        p.close();

        p = sPatternPaths[4] = new Path();
        p.moveTo(323.1f, 768f);
        p.moveTo(777.5f, 768f);
        p.cubicTo(661.9f, 348.8f, 427.2f, 21.4f, 401.2f, 25.4f);
        p.lineTo(323.1f, 768f);
        p.close();

        p = sPatternPaths[5] = new Path();
        p.moveTo(178.44286f, 766.85714f);
        p.lineTo(308.7f, 768f);
        p.cubicTo(381.7f, 604.6f, 481.6f, 344.3f, 562.2f, 0f);
        p.lineTo(0f, 0f);
        p.close();

        p = sPatternPaths[6] = new Path();
        p.moveTo(146f, 0f);
        p.lineTo(0f, 0f);
        p.lineTo(0f, 768f);
        p.lineTo(394.2f, 768f);
        p.cubicTo(327.7f, 475.3f, 228.5f, 201f, 146f, 0f);
        p.close();
    }

    for (int i = 0; i < NUM_PATHS; i++) {
        // Color is 0xAARRGGBB, so alpha << 24 will create a color with (alpha)% black.
        // Although the color components don't really matter, since the backing bitmap cache is
        // ALPHA_8.
        mTempPaint.setColor(sPatternLightness[i] << 24);
        canvas.drawPath(sPatternPaths[i], mTempPaint);
    }

    canvas.restore();
    mTempPaint.reset();
}
 
Example 16
Project: CornerLabelView   File: CornerLabelView.java   View Source Code Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //将原点移动到画布中心
    canvas.translate(mHalfWidth, mHalfWidth);
    //根据角标位置旋转画布
    canvas.rotate(position * 90);

    if (sideLength > mHalfWidth * 2) {
        sideLength = mHalfWidth * 2;
    }

    //绘制角标背景
    mPath.moveTo(-mHalfWidth, -mHalfWidth);
    mPath.lineTo(sideLength - mHalfWidth, -mHalfWidth);
    mPath.lineTo(mHalfWidth, mHalfWidth - sideLength);
    mPath.lineTo(mHalfWidth, mHalfWidth);
    mPath.close();
    canvas.drawPath(mPath, mPaint);

    //绘制文字前画布旋转45度
    canvas.rotate(45);
    //角标实际高度
    int h1 = (int) (Math.sqrt(2) / 2.0 * sideLength);
    int h2 = (int) -(mTextPaint.ascent() + mTextPaint.descent());
    //文字绘制坐标
    int x = (int) -mTextPaint.measureText(text) / 2;
    int y;
    if (marginLeanSide >= 0) { //使用clv:margin_lean_side属性时
        if (position == 1 || position == 2) {
            if (h1 - (marginLeanSide - mTextPaint.ascent()) < (h1 - h2) / 2) {
                y = -(h1 - h2) / 2;
            } else {
                y = (int) -(h1 - (marginLeanSide - mTextPaint.ascent()));
            }
        } else {
            if (marginLeanSide < mTextPaint.descent()) {
                marginLeanSide = (int) mTextPaint.descent();
            }

            if (marginLeanSide > (h1 - h2) / 2) {
                marginLeanSide = (h1 - h2) / 2;
            }
            y = -marginLeanSide;
        }
    } else { //默认情况下
        if (sideLength > mHalfWidth) {
            sideLength = mHalfWidth;
        }
        y = (int) (-Math.sqrt(2) / 2.0 * sideLength + h2) / 2;
    }

    //如果角标在右下、左下则进行画布平移、翻转,已解决绘制的文字显示问题
    if (position == 1 || position == 2) {
        canvas.translate(0, (float) (-Math.sqrt(2) / 2.0 * sideLength));
        canvas.scale(-1, -1);
    }
    //绘制文字
    canvas.drawText(text, x, y, mTextPaint);
}
 
Example 17
Project: Android-Music-Player   File: thumbRing.java   View Source Code Vote up 0 votes
public void draw(Canvas canvas) {
 			if(drawing){
				canvas.drawPath(S0, P0);
			}
		} 
Example 18
Project: Android-Music-Player   File: selecttitleBack.java   View Source Code Vote up 0 votes
public void draw(Canvas canvas) {
 			if(drawing){
				canvas.drawPath(S0, P0);
			}
		} 
Example 19
Project: Android-Music-Player   File: fileInfoIcon.java   View Source Code Vote up 0 votes
public void draw(Canvas canvas) {
 			if(drawing){
				canvas.drawPath(S0, P0);
				canvas.drawPath(S1, P1);
				canvas.drawPath(S2, P2);
			}
		} 
Example 20
Project: Android-Music-Player   File: genreIcon.java   View Source Code Vote up 0 votes
public void draw(Canvas canvas) {
 			if(drawing){
				canvas.drawPath(S0, P0);
				canvas.drawPath(S1, P1);
				canvas.drawPath(S2, P2);
			}
		}