@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //无效果 mEffects[0] = null; //拐角处变得圆滑 mEffects[1] = new CornerPathEffect(30); //线段上就会产生许多杂点 mEffects[2] = new DiscretePathEffect(3.0F, 5.0F); //绘制虚线 mEffects[3] = new DashPathEffect(new float[] { 20, 10, 5, 10 }, 0); Path path = new Path(); path.addRect(0, 0, 8, 8, Path.Direction.CCW); //设置点的图形,即方形点的虚线,圆形点的虚线 mEffects[4] = new PathDashPathEffect(path, 12, 0, PathDashPathEffect.Style.ROTATE); //组合PathEffect mEffects[5] = new ComposePathEffect(mEffects[3], mEffects[1]); for (int i = 0; i < mEffects.length; i++) { mPaint.setPathEffect(mEffects[i]); canvas.drawPath(mPath, mPaint); canvas.translate(0, 200); } }
@Override Paint initPaint() { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.MITER); paint.setStrokeCap(Paint.Cap.SQUARE); paint.setStrokeMiter(0.2f); paint.setPathEffect(new DiscretePathEffect(2, 2)); return paint; }
private void initPaint() { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(5); mPaint.setColor(Color.RED); mPath = new Path(); mPath.moveTo(0, 0); for(int i = 0;i<=30;i++){ mPath.lineTo(i*35, (float)Math.random()*100); } mEffects = new PathEffect[7]; mEffects[0] = null; mEffects[1] = new CornerPathEffect(10); mEffects[2] = new DiscretePathEffect(3.0F, 5.0F); mEffects[3] = new DashPathEffect(new float[] { 20, 10, 5, 10 }, mPhase); Path path = new Path(); path.addRect(0, 0, 8, 8, Path.Direction.CCW); mEffects[4] = new PathDashPathEffect(path, 12, mPhase, PathDashPathEffect.Style.ROTATE); mEffects[5] = new ComposePathEffect(mEffects[2], mEffects[4]); mEffects[6] = new SumPathEffect(mEffects[4], mEffects[3]); }
private void init(Context context) { mainTitlePaint = new Paint(); mainTitlePaint.setColor(ContextCompat.getColor(context, R.color.white)); mainTitlePaint.setTextAlign(Paint.Align.CENTER); mainTitlePaint.setTextSize(DensityUtils.sp2px(context, MAIN_TITLE_FONT_SIZE_SP)); mainTitleOffsetY = -(mainTitlePaint.getFontMetrics().ascent + mainTitlePaint.getFontMetrics().descent) / 2; mainTitlePaint.setAntiAlias(true); circleColor = ContextCompat.getColor(context, R.color.whiteTransparent); subTitlePaint = new Paint(); subTitlePaint.setColor(circleColor); subTitlePaint.setTextSize(DensityUtils.sp2px(context, SUB_TITLE_FONT_SIZE_SP)); subTitleOffsetY = DensityUtils.sp2px(context, SUB_TITLE_FONT_OFFSET_DP); subTitleSeparator = getResources().getString(R.string.sub_title_separator); subTitlePaint.setAntiAlias(true); bigCirclePaint = new Paint(); bigCirclePaint.setStrokeWidth(DensityUtils.dp2px(context, BIG_CIRCLE_SIZE)); bigCirclePaint.setStyle(Paint.Style.STROKE); bigCirclePaint.setAntiAlias(true); blurPaint = new Paint(bigCirclePaint); blurSize = DensityUtils.dp2px(context, CIRCLE_BLUR_SIZE); PathEffect pathEffect1 = new CornerPathEffect(DensityUtils.dp2px(getContext(), BIG_CIRCLE_SHAKE_RADIUS)); PathEffect pathEffect2 = new DiscretePathEffect(DensityUtils.dp2px(getContext(), BIG_CIRCLE_SHAKE_RADIUS), DensityUtils.dp2px(getContext(), BIG_CIRCLE_SHAKE_OFFSET)); PathEffect pathEffect = new ComposePathEffect(pathEffect1, pathEffect2); bigCirclePaint.setPathEffect(pathEffect); dottedCirclePaint = new Paint(); dottedCirclePaint.setStrokeWidth(DensityUtils.dp2px(context, DOTTED_CIRCLE_WIDTH)); dottedCirclePaint.setColor(ContextCompat.getColor(context, R.color.whiteTransparent)); dottedCirclePaint.setStyle(Paint.Style.STROKE); float gagPx = DensityUtils.dp2px(context, DOTTED_CIRCLE_GAG); dottedCirclePaint.setPathEffect(new DashPathEffect(new float[]{gagPx, gagPx}, 0)); dottedCirclePaint.setAntiAlias(true); solidCirclePaint = new Paint(); solidCirclePaint.setStrokeWidth(DensityUtils.dp2px(context, SOLID_CIRCLE_WIDTH)); solidCirclePaint.setColor(ContextCompat.getColor(context, R.color.white)); solidCirclePaint.setStyle(Paint.Style.STROKE); solidCirclePaint.setStrokeCap(Paint.Cap.ROUND); solidCirclePaint.setAntiAlias(true); dotPaint = new Paint(); dotPaint.setStrokeWidth(DensityUtils.dp2px(context, DOT_SIZE)); dotPaint.setStrokeCap(Paint.Cap.ROUND); dotPaint.setColor(ContextCompat.getColor(context, R.color.white)); dotPaint.setAntiAlias(true); backgroundBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.bg_step_law); // 设置手表 icon 的大小 watchBitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon_headview_watch); float scale = DensityUtils.dp2px(context, WATCH_SIZE) / watchBitmap.getWidth(); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); watchBitmap = Bitmap.createBitmap(watchBitmap, 0, 0, watchBitmap.getWidth(), watchBitmap.getHeight(), matrix, true); watchOffset = DensityUtils.sp2px(context, WATCH_OFFSET_DP); fireworksCircle = new FireworksCircleGraphics(context); animationThread = new AnimationThread(); animationThread.start(); }