package com.ppg.mylibrary.a;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.Region;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
public class ForegroundView extends View {
public ForegroundView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawCircular(canvas);
canvas.drawColor(Color.parseColor("#80000000"));
drawDashedLineCircular(canvas);
}
private void drawCircular(Canvas canvas) {
float wdith = getWidth() / 4f;
float height = wdith;
float radius = wdith;
Path path = new Path();
path.addCircle(
wdith * 2,
height * 2,
radius,
Path.Direction.CCW);
path.close();
canvas.clipPath(path, Region.Op.DIFFERENCE);
}
private void drawDashedLineCircular(Canvas canvas) {
float wdith = getWidth() / 4f;
float height = wdith;
float radius = wdith;
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setStrokeWidth(getResources().getDisplayMetrics().density * 5);
paint.setColor(Color.WHITE);
PathEffect dashPathEffect = new DashPathEffect(new float[]{
10,
10
},1);
paint.setPathEffect(dashPathEffect);
canvas.drawCircle(
wdith * 2,
height * 2,
radius,
paint);
}
}