package com.xtp.simple.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.xtp.simple.R;

public class Practice2DrawCircleView extends View implements PracticeBaseView {

    private Paint mPaint = new Paint();

    public Practice2DrawCircleView(Context context) {
        super(context);
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public String getCoreCode() {
        return "canvas.drawCircle(float cx, float cy, float radius, Paint paint);";
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容:使用 canvas.drawCircle() 方法画圆
//        一共四个圆:1.实心圆 2.空心圆 3.蓝色实心圆 4.线宽为 20 的空心圆
        mPaint.setColor(getResources().getColor(R.color.textMain));
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setAntiAlias(false);
        canvas.drawCircle(70, 70, 50, mPaint);

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(1);
        mPaint.setAntiAlias(false);
        canvas.drawCircle(190, 70, 50, mPaint);

        mPaint.setStrokeWidth(10);
        mPaint.setAntiAlias(false);
        canvas.drawCircle(70, 190, 50, mPaint);

        mPaint.setAntiAlias(true);
        canvas.drawCircle(190, 190, 50, mPaint);
    }
}
