package com.example.cloudmusic;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

public class MyView extends View {

    private Paint paint;

    public MyView(Context context) {
        super(context);
//        paint.setColor(Color.RED);
//        paint.setStrokeWidth(50);
//        paint.setStyle(Paint.Style.STROKE);
        Log.d("1", "MyView: ");
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(20);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND); // 闭合模式 坡底式 BEVEL
                                              // MITER 正常式 ROUND 圆角式
        PathEffect pathEffect = new CornerPathEffect(20);
        paint.setPathEffect(pathEffect);
        Log.d("1", "MyView: ");
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.d("1", "MyView2: ");
      //  canvas.scale(10,10); //放大 画布 10倍
        // paint.setStrokeCap()
        canvas.drawCircle(400,300,200,paint);
        Path path = new Path();  //绘制路径 画一个闭合三角形
        path.moveTo(100,700);
        path.lineTo(300,900);
        path.lineTo(400,600);
        path.lineTo(500,700);
        path.lineTo(600,100);
        canvas.drawPath(path,paint);






       // paint.reset();
       // paint.setStyle(Paint.Style.FILL);
       // paint.setColor(Color.BLUE);
       // canvas.drawCircle(400,300,200,paint);
       // canvas.drawLine(0,0,200,200,paint);
    }
}
