package com.example.cloudmusic;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

public class MyView2 extends View {
    Paint paint;
    private static List<String> mList;
    private String mText;

    public MyView2(Context context) {
        super(context);

    }

    public MyView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        if (mList == null) {
            mList = new ArrayList<>();
        }
    }



    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        @SuppressLint("DrawAllocation") Path path = new Path();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(3);
   //     path.moveTo(0, (float) (1000-Double.parseDouble(mList.get(0))*10));
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setColor(Color.rgb(223,162,87));
        paint.setTextSize(20);
        path.moveTo(0,1000-Float.parseFloat(mList.get(0))*10);
        float x = 0.5F;
        int num = -50;
        for (int i = 0; i < mList.size(); i++) {
            float y =  1000-Float.parseFloat(mList.get(i))*10;
            path.lineTo(x*100,y);
            canvas.drawText(mList.get(i)+"°",x*100,y+num,paint);
            paint.setStyle(Paint.Style.FILL);
            canvas.drawCircle(x*100,y,10,paint);
            paint.setStyle(Paint.Style.STROKE);
            x++;
            if ((i+1)%6==0){
                canvas.drawPath(path,paint);
                paint.setColor(Color.rgb(11,146,243));
                path = new Path();
                if (i!=mList.size()-1) {
                    path.moveTo(0, 1000 - Float.parseFloat(mList.get(i + 1)) * 10);
                }
                num = 50;
                x = 0.5F;
            }
        }


    //    mText = "28°";
        paint.reset();


        for (int i = 0; i < mList.size(); i++) {
            float y =  1000-Float.parseFloat(mList.get(i))*10;

        }
//        mText = "Hello World!";
//        paint.reset();
//
//        paint.setStrokeWidth(2);
//        paint.setTextSize(70);
//        canvas.drawText(mText, getWidth()/2, getHeight() / 2, paint);
    }
    public void setData(List<String> list) {
        mList.addAll(list);
    //    invalidate();
    }
//    public void setText(String text) {
//        mText = text;
//        invalidate();
//    }
}
