private void buildClippingCorners() { mCornerPath.reset(); RectF oval = new RectF(0, 0, mCornerRadius * 2, mCornerRadius * 2); mCornerPath.setFillType(Path.FillType.EVEN_ODD); mCornerPath.moveTo(0, 0); mCornerPath.lineTo(0, mCornerRadius); mCornerPath.arcTo(oval, 180f, 90f, true); mCornerPath.lineTo(0, 0); mCornerPath.close(); } }
public void rightPath(RectF rect, Path path) { path.moveTo(mAngle, rect.top); path.lineTo(rect.width(), rect.top); path.arcTo(new RectF(rect.right - mAngle * 2 - mArrowWidth, rect.top, rect.right - mArrowWidth, mAngle * 2 + rect.top), 270, 90); path.lineTo(rect.right - mArrowWidth, mArrowTop); path.lineTo(rect.right, mArrowTop - mArrowOffset); path.lineTo(rect.right - mArrowWidth, mArrowTop + mArrowHeight); path.lineTo(rect.right - mArrowWidth, rect.height() - mAngle); path.arcTo(new RectF(rect.right - mAngle * 2 - mArrowWidth, rect.bottom - mAngle * 2, rect.right - mArrowWidth, rect.bottom), 0, 90); path.lineTo(rect.left, rect.bottom); path.arcTo(new RectF(rect.left, rect.bottom - mAngle * 2, mAngle * 2 + rect.left, rect.bottom), 90, 90); path.lineTo(rect.left, rect.top); path.arcTo(new RectF(rect.left, rect.top, mAngle * 2 + rect.left, mAngle * 2 + rect.top), 180, 90); path.close(); }
public void leftPath(RectF rect, Path path) { path.moveTo(mAngle + mArrowWidth, rect.top); path.lineTo(rect.width(), rect.top); path.arcTo(new RectF(rect.right - mAngle * 2, rect.top, rect.right, mAngle * 2 + rect.top), 270, 90); path.lineTo(rect.right, rect.top); path.arcTo(new RectF(rect.right - mAngle * 2, rect.bottom - mAngle * 2, rect.right, rect.bottom), 0, 90); path.lineTo(rect.left + mArrowWidth, rect.bottom); path.arcTo(new RectF(rect.left + mArrowWidth, rect.bottom - mAngle * 2, mAngle * 2 + rect.left + mArrowWidth, rect.bottom), 90, 90); path.lineTo(rect.left + mArrowWidth, mArrowTop + mArrowHeight); path.lineTo(rect.left, mArrowTop - mArrowOffset); path.lineTo(rect.left + mArrowWidth, mArrowTop); path.lineTo(rect.left + mArrowWidth, rect.top); path.arcTo(new RectF(rect.left + mArrowWidth, rect.top, mAngle * 2 + rect.left + mArrowWidth, mAngle * 2 + rect.top), 180, 90); path.close(); }
@Override protected void onSizeChanged(int width, int height, int oldw, int oldh) { int centerX = width / 2; int centerY = height / 2; innerPadding = (int) (paramInnerPadding * width / 100); outerPadding = (int) (paramOuterPadding * width / 100); arrowPointerSize = (int) (paramArrowPointerSize * width / 100); valueSliderWidth = (int) (paramValueSliderWidth * width / 100); outerWheelRadius = width / 2 - outerPadding - arrowPointerSize; innerWheelRadius = outerWheelRadius - valueSliderWidth; colorWheelRadius = innerWheelRadius - innerPadding; outerWheelRect.set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius); innerWheelRect.set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius); colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2); gradientRotationMatrix = new Matrix(); gradientRotationMatrix.preRotate(270, width / 2, height / 2); colorViewPath.arcTo(outerWheelRect, 270, -180); colorViewPath.arcTo(innerWheelRect, 90, 180); valueSliderPath.arcTo(outerWheelRect, 270, 180); valueSliderPath.arcTo(innerWheelRect, 90, -180); }
mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mTrackPath.lineTo(mDrawRect.left, y + halfStroke); mTrackPath.close(); mTrackPath.arcTo(mTempRect, -angle, angle * 2); mTrackPath.lineTo(mDrawRect.right, y + halfStroke); mTrackPath.close(); mTrackPath.arcTo(mTempRect, 180 - angle2, angle2 * 2); mTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mTrackPath.close(); mTrackPath.arcTo(mTempRect, angle2, -angle2 * 2); mTrackPath.arcTo(mTempRect, -angle, angle * 2); mTrackPath.close();
position.x + halfWidth, position.y + halfHeight); path.arcTo(rect, 0, 90, false); position.x - halfWidth + 2 * radius, position.y + halfHeight); path.arcTo(rect, 90, 90, false); position.x - halfWidth + 2 * radius, position.y - halfHeight + 2 * radius); path.arcTo(rect, 180, 90, false); position.x + halfWidth, position.y - halfHeight + 2 * radius); path.arcTo(rect, 270, 90, false);
public void updateCorner(float radius){ mRadius = radius; Rect bounds = getBounds(); mPath.reset(); if(radius == 0) mPath.addRect(bounds.left, bounds.top, bounds.right, bounds.bottom, Path.Direction.CW); else { RectF rect = new RectF(); mPath.moveTo(bounds.left, bounds.top - radius); rect.set(bounds.left, bounds.top, bounds.left + radius * 2, bounds.top + radius * 2); mPath.arcTo(rect, 180, 90, false); mPath.lineTo(bounds.right - radius, bounds.top); rect.set(bounds.right - radius * 2, bounds.top, bounds.right, bounds.top + radius * 2); mPath.arcTo(rect, 270, 90, false); mPath.lineTo(bounds.right, bounds.bottom); mPath.lineTo(bounds.left, bounds.bottom); mPath.close(); } invalidateSelf(); }
} else { rect.set(0, 0, ts * 2, ts * 2); path.arcTo(rect, -180, 90, false); } else { rect.set(width - te * 2, 0, width, te * 2); path.arcTo(rect, -90, 90, false); } else { rect.set(width - be * 2, height - be * 2, width, height); path.arcTo(rect, 0, 90, false); } else { rect.set(0, height - bs * 2, bs * 2, height); path.arcTo(rect, 90, 90, false);
@Override protected void onBoundsChange(Rect bounds) { int width = bounds.width(); int height = bounds.height(); RectF rectF = mTempRectF; Path path = mPath; path.reset(); if (width > height) { int radius = height / 2; path.moveTo(bounds.right - radius, bounds.top); rectF.set(bounds.right - height, bounds.top, bounds.right, bounds.bottom); path.arcTo(rectF, -90.0f, 180.0f, false); path.lineTo(bounds.left + radius, bounds.bottom); rectF.set(bounds.left, bounds.top, bounds.left + height, bounds.bottom); path.arcTo(rectF, 90.0f, 180.0f, false); path.lineTo(bounds.right - radius, bounds.top); } else if (width == height) { path.addCircle(bounds.centerX(), bounds.centerY(), width / 2, Path.Direction.CW); } else { // TODO } }
if(x > mDrawRect.left){ mTempRect.set(mDrawRect.left, y - halfStroke, mDrawRect.left + mTrackSize, y + halfStroke); mLeftTrackPath.arcTo(mTempRect, 90, 180); mLeftTrackPath.lineTo(x, y - halfStroke); mLeftTrackPath.lineTo(x, y + halfStroke); mRightTrackPath.arcTo(mTempRect, 270, 180); mRightTrackPath.lineTo(x, y + halfStroke); mRightTrackPath.lineTo(x, y - halfStroke); mLeftTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mLeftTrackPath.lineTo(mDrawRect.left, y + halfStroke); mLeftTrackPath.close(); mRightTrackPath.arcTo(mTempRect, -angle, angle * 2); mRightTrackPath.lineTo(mDrawRect.right, y + halfStroke); mRightTrackPath.close(); mLeftTrackPath.arcTo(mTempRect, 180 - angle2, angle2 * 2); mLeftTrackPath.arcTo(mTempRect, 180 + angle, -angle * 2); mLeftTrackPath.close(); mRightTrackPath.arcTo(mTempRect, angle2, -angle2 * 2); mRightTrackPath.arcTo(mTempRect, -angle, angle * 2); mRightTrackPath.close();
path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius, bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 0, -359); path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius, bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 1, -359); path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius, bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 2, -2);
@Override public void draw(Canvas canvas) { canvas.save(); canvas.rotate(mDegrees, canvas.getWidth() / 2, canvas.getHeight() / 2); mPath.reset(); float d = Math.min(canvas.getWidth(), canvas.getHeight()); float left = dp2px(DEFAULT_BORDER_WIDTH); float top = dp2px(DEFAULT_BORDER_WIDTH); float right = (d - dp2px(DEFAULT_BORDER_WIDTH)); float bottom = (d - dp2px(DEFAULT_BORDER_WIDTH)); mBounds.set(left, top, right, bottom); mPath.arcTo(mBounds, DEFAULT_START_ANGLE, mAngle, true); mPaint.setAlpha(mAlpha); canvas.drawPath(mPath, mPaint); canvas.restore(); } }
mTempRect.set(nCx - nRadius, nCy - nRadius, nCx + nRadius, nCy + nRadius); path.moveTo(x1, y1); path.arcTo(mTempRect, 180 - angle, 180 + angle * 2); nRadius = (float)distance(nCx, nCy, x2, y2); mTempRect.set(nCx - nRadius, nCy - nRadius, nCx + nRadius, nCy + nRadius); path.arcTo(mTempRect, angle, angle2 - angle); angle2 = (float)(Math.atan2(y1 - nCy, x1 - nCx) * 180 / Math.PI); mTempRect.set(nCx - nRadius, nCy - nRadius, nCx + nRadius, nCy + nRadius); path.arcTo(mTempRect, angle + (float)Math.PI / 4, angle2 - angle);
mHeaderBackground.lineTo(0, mCornerRadius); mRect.set(0, 0, mCornerRadius * 2, mCornerRadius * 2); mHeaderBackground.arcTo(mRect, 180f, 90f, false); mHeaderBackground.lineTo(mHeaderRealWidth - mCornerRadius, 0); mRect.set(mHeaderRealWidth - mCornerRadius * 2, 0, mHeaderRealWidth, mCornerRadius * 2); mHeaderBackground.arcTo(mRect, 270f, 90f, false); mHeaderBackground.lineTo(mHeaderRealWidth, mHeaderRealHeight); mHeaderBackground.close(); mHeaderBackground.lineTo(0, mCornerRadius); mRect.set(0, 0, mCornerRadius * 2, mCornerRadius * 2); mHeaderBackground.arcTo(mRect, 180f, 90f, false); mHeaderBackground.lineTo(mHeaderRealWidth, 0); mHeaderBackground.lineTo(mHeaderRealWidth, mHeaderRealHeight);
mHeaderSecondaryBackground.lineTo(0, mCornerRadius); mRect.set(0, 0, mCornerRadius * 2, mCornerRadius * 2); mHeaderSecondaryBackground.arcTo(mRect, 180f, 90f, false); mHeaderSecondaryBackground.lineTo(mHeaderRealWidth - mCornerRadius, 0); mRect.set(mHeaderRealWidth - mCornerRadius * 2, 0, mHeaderRealWidth, mCornerRadius * 2); mHeaderSecondaryBackground.arcTo(mRect, 270f, 90f, false); mHeaderSecondaryBackground.lineTo(mHeaderRealWidth, mHeaderSecondaryHeight); mHeaderSecondaryBackground.close(); mHeaderSecondaryBackground.lineTo(0, mCornerRadius); mRect.set(0, 0, mCornerRadius * 2, mCornerRadius * 2); mHeaderSecondaryBackground.arcTo(mRect, 180f, 90f, false); mHeaderSecondaryBackground.lineTo(mHeaderRealWidth, 0); mHeaderSecondaryBackground.lineTo(mHeaderRealWidth, mHeaderSecondaryHeight);
mCornerShadowTopPath.setFillType(Path.FillType.EVEN_ODD); mCornerShadowTopPath.moveTo(shadowHorizontal + mCornerRadius, shadowTop); mCornerShadowTopPath.arcTo(topInnerBounds, 270f, -90f, true); mCornerShadowTopPath.rLineTo(-shadowHorizontal, 0); mCornerShadowTopPath.lineTo(0, mCornerRadius); mCornerShadowTopPath.arcTo(topOuterBounds, 180f, 90f, true); mCornerShadowTopPath.lineTo(shadowHorizontal + mCornerRadius, 0); mCornerShadowTopPath.rLineTo(0, shadowTop); mCornerShadowBottomPath.setFillType(Path.FillType.EVEN_ODD); mCornerShadowBottomPath.moveTo(shadowHorizontal + mCornerRadius, shadowBottom); mCornerShadowBottomPath.arcTo(bottomInnerBounds, 270f, -90f, true); mCornerShadowBottomPath.rLineTo(-shadowHorizontal, 0); mCornerShadowBottomPath.lineTo(0, mCornerRadius); mCornerShadowBottomPath.arcTo(bottomOuterBounds, 180f, 90f, true); mCornerShadowBottomPath.lineTo(shadowHorizontal + mCornerRadius, 0); mCornerShadowBottomPath.rLineTo(0, shadowBottom);
mPathBuffer.arcTo(roundedCircleBox, startAngleOuter + 180, -180); mPathBuffer.arcTo( circleBox, startAngleOuter, float y = center.y + (radius - roundedRadius) * (float) Math.sin(endAngleInner * Utils.FDEG2RAD); roundedCircleBox.set(x - roundedRadius, y - roundedRadius, x + roundedRadius, y + roundedRadius); mPathBuffer.arcTo(roundedCircleBox, endAngleInner, 180); } else mPathBuffer.lineTo( center.y + innerRadius * (float) Math.sin(endAngleInner * Utils.FDEG2RAD)); mPathBuffer.arcTo( mInnerRectBuffer, endAngleInner,
@Test public void arcTo1() { Path path = new Path(); assertThat(path.isEmpty()).isTrue(); RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM); path.arcTo(oval, 0.0f, 30.0f, true); assertThat(path.isEmpty()).isFalse(); }
@Test public void arcTo2() { Path path = new Path(); assertThat(path.isEmpty()).isTrue(); RectF oval = new RectF(LEFT, TOP, RIGHT, BOTTOM); path.arcTo(oval, 0.0f, 30.0f); assertThat(path.isEmpty()).isFalse(); }