下面列出了怎么用android.graphics.ComposePathEffect的API类实例代码及写法,或者点击链接到github查看源代码。
public Border build() {
checkNotBuilt();
mResourceResolver = null;
if (mNumPathEffects == MAX_PATH_EFFECTS) {
mBorder.mPathEffect = new ComposePathEffect(mPathEffects[0], mPathEffects[1]);
} else if (mNumPathEffects > 0) {
mBorder.mPathEffect = mPathEffects[0];
}
if (mBorder.mPathEffect != null && !Border.equalValues(mBorder.mEdgeWidths)) {
throw new IllegalArgumentException(
"Borders do not currently support different widths with a path effect");
}
return mBorder;
}
@Test
public void testEffectSetting() {
final ComponentContext c = new ComponentContext(getApplicationContext());
Border border = Border.create(c).dashEffect(new float[] {1f, 1f}, 0f).build();
assertThat(border.mPathEffect).isInstanceOf(DashPathEffect.class);
border = Border.create(c).discreteEffect(1f, 0f).build();
assertThat(border.mPathEffect).isInstanceOf(DiscretePathEffect.class);
border =
Border.create(c)
.pathDashEffect(new Path(), 0f, 0f, PathDashPathEffect.Style.ROTATE)
.build();
assertThat(border.mPathEffect).isInstanceOf(PathDashPathEffect.class);
border = Border.create(c).discreteEffect(1f, 1f).dashEffect(new float[] {1f, 2f}, 1f).build();
assertThat(border.mPathEffect).isInstanceOf(ComposePathEffect.class);
}
protected CiPaint assignPaint() {
CiPaint paint = new CiPaint(drawingContext.getPaint());
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
if (smoothRadius > 0) {
CornerPathEffect effect = new CornerPathEffect(smoothRadius);
if (paint.getPathEffect() == null) {
paint.setPathEffect(effect);
} else {
ComposePathEffect composeEffect = new ComposePathEffect(paint.getPathEffect(), effect);
paint.setPathEffect(composeEffect);
}
}
return paint;
}
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();
}
private PathEffect getCornerDashPathEffect(int strokeWidth) {
PathEffect dash = getDashPathEffect(strokeWidth);
PathEffect corner = new CornerPathEffect(strokeWidth);
return new ComposePathEffect(dash, corner);
}