package com.example.choix;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.provider.MediaStore;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RadioGroup;
import android.graphics.Path;

import androidx.annotation.Nullable;

public class Choix extends View{
    private Paint paint;
    private RadioGroup radioGroup;

    public Choix(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        radioGroup = getRootView().findViewById(R.id.groupe);
        choixListener cl = new choixListener(this);
        getRootView().findViewById(R.id.groupe).findViewById(R.id.croix).setOnClickListener(cl);
        getRootView().findViewById(R.id.groupe).findViewById(R.id.carre).setOnClickListener(cl);
        getRootView().findViewById(R.id.groupe).findViewById(R.id.rond).setOnClickListener(cl);
        getRootView().findViewById(R.id.groupe).findViewById(R.id.triangle).setOnClickListener(cl);

        if(radioGroup.getCheckedRadioButtonId() == R.id.carre) {
            super.onDraw(canvas);
            paint.setARGB(255, 210, 210, 90);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);
            canvas.drawRect(100, 100, 300, 300, paint);
        }
        else if(radioGroup.getCheckedRadioButtonId() == R.id.rond) {
            super.onDraw(canvas);
            paint.setARGB(255, 210, 210, 90);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);
            canvas.drawCircle(200,200,100,paint);
        }
        else if(radioGroup.getCheckedRadioButtonId() == R.id.triangle) {
            super.onDraw(canvas);
            paint.setARGB(255, 0, 255, 0);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);



            canvas.drawLine( 200, 100, 300, 300, paint);
            canvas.drawLine( 300, 300, 100, 300, paint);
            canvas.drawLine( 100, 300, 200, 100, paint);
        }
        else{
            super.onDraw(canvas);
            paint.setARGB(255, 0, 0, 255);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);

            canvas.drawLine(100, 100, 300, 300, paint);
            canvas.drawLine(100, 300, 300, 100, paint);
        }


    }
}