1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| @Override public void draw(@NonNull Canvas canvas) {
if (mDashPathEffect != null) { canvas.drawColor(Color.WHITE, PorterDuff.Mode.CLEAR); canvas.drawColor(Color.WHITE); }
int centerX = mWidth / 2; int centerY = mHeight / 2;
mBgPaint.setColor(Color.GREEN); mBgPaint.setStyle(Paint.Style.FILL); canvas.drawRoundRect(0, 0, mWidth, mHeight, 30, 30, mBgPaint);
canvas.save(); canvas.rotate(90 + mRotate, mWidth / 2f, mHeight / 2f); canvas.drawArc(mRectF, -180, 240, false, mCirclePaint);
canvas.restore();
prepareForkPath(centerX, centerY); canvas.drawPath(mPath, mForkPaint);
if (mDashPathEffect != null) { canvas.drawCircle(centerX, centerY - mMoveHeight, 5, mBallPaint); canvas.drawPath(mGPath, mLinePaint); canvas.drawPath(mGRightPath, mLineRightPaint); } else { canvas.drawCircle(centerX, centerY - mMoveHeight, 10, mBallPaint); }
}
private void prepareForkPath(int centerX, int centerY) { double cos45Value = Math.cos(45 * Math.PI / 180); double sin5Value = Math.sin(45 * Math.PI / 180); float len = mForkLenScale * centerX;
Log.e(TAG, "draw: " + len);
float x1 = (float) (centerX - len * cos45Value); float y1 = (float) (centerY - len * sin5Value);
float x2 = (float) (centerX + len * cos45Value); float y2 = (float) (centerY - len * sin5Value);
float x3 = (float) (centerX + len * cos45Value); float y3 = (float) (centerY + len * sin5Value);
float x4 = (float) (centerX - len * cos45Value); float y4 = (float) (centerY + len * sin5Value);
mPath.reset();
mPath.moveTo(x1, y1); mPath.lineTo(x3, y3); mPath.moveTo(x2, y2); mPath.lineTo(x4, y4); }
|