package com.rehome.meetingbook.weiget;

/**
 * Create By HuangWenFei
 * 创建日期：2022-12-20 11:43
 * 描述：
 */

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

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.MonthView;

/**
 * 定制高仿魅族日历界面，按你的想象力绘制出各种各样的界面
 *
 */
public class MeiZuMonthView extends MonthView {
    private int mRadius;

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

    @Override
    protected void onPreviewHook() {
        mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
        //FILL 内部填充
        //STROKE 描边
        //FILL_AND_STROKE 内部填充+描边
        mSchemePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    }

    @Override
    protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
        return true;
    }

    @Override
    protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
    }

    @Override
    protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
        //建立文字原点
        float baselineY = mTextBaseLine + y;
        int cx = x + mItemWidth / 2;
        //判断当前日期是否在本月中
        boolean isInRange = isInRange(calendar);
        //判断当前日期是否可用
        boolean isEnable = !onCalendarIntercept(calendar);
        //如果该日期被选中，添加选中样式
        if (isSelected) {
            canvas.drawText(String.valueOf(calendar.getDay()),
                    cx,
                    baselineY,
                    mSelectTextPaint);
        }
        //如果没被选中但是是标注日期
        else if (hasScheme) {
            canvas.drawText(String.valueOf(calendar.getDay()),
                    cx,
                    baselineY,
                    calendar.isCurrentDay() ? mCurDayTextPaint :
                            calendar.isCurrentMonth() && isInRange && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);
        }
        //其他
        else {
            canvas.drawText(String.valueOf(calendar.getDay()),
                    cx,
                    baselineY,
                    calendar.isCurrentDay() ? mCurDayTextPaint :
                            calendar.isCurrentMonth() && isInRange && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);
        }
    }
}