package com.casic.dcms.widgets.datepicker;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.casic.dcms.R;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;

/**
 * 不可选日期斜线
 */
public class LineTextView extends AppCompatTextView {
    private Paint mPaint;
    private Context context;

    public LineTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStrokeWidth(QMUIDisplayHelper.dp2px(context, 1));
        mPaint.setColor(getResources().getColor(R.color.punishColor));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //斜线坐标
        int startX, startY, endX, endY;

        //视图宽高
        int width = getWidth();
        int height = getHeight();

        //计算坐标
        startX = width;
        startY = QMUIDisplayHelper.dp2px(context, 2);
        endX = 0;
        endY = height - QMUIDisplayHelper.dp2px(context, 3);
        //画斜线
        canvas.drawLine(startX, startY, endX, endY, mPaint);
    }
}
