package com.cooleshow.teacher.widgets;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;

import com.cooleshow.base.utils.SizeUtils;
import com.cooleshow.teacher.R;

import androidx.recyclerview.widget.RecyclerView;

/**
 * Description:
 * Copyright  : Copyright (c) 2019
 * Company    : 大雅乐盟
 * Author     : r
 * Date       : 2019/10/22 10:07
 */
public class CalendarShrinkDecoration extends RecyclerView.ItemDecoration {
    private int mHeight;
    private Paint mPaint;
    Bitmap mSrcBitmap;
    Context context;

    public CalendarShrinkDecoration(Context context) {
        this.context = context;
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(0xffDFDEDE);
        mPaint.setStrokeWidth(0);
        mPaint.setAntiAlias(true);
        mSrcBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_calendar_shrink);
        mHeight = SizeUtils.dp2px(38);
    }

    public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(canvas, parent, state);
        int mWidth = parent.getWidth();
        mPaint.setStrokeWidth(1);
        mPaint.setColor(0xffffffff);
        canvas.drawRoundRect(new RectF(0, 0, mWidth, mHeight), 0, 0, mPaint);
        int mBitmapHeight = mSrcBitmap.getHeight();
        int mBitmapWidth = mSrcBitmap.getWidth();

        RectF rectF = new RectF(mWidth / 2 - mBitmapWidth / 2, mHeight / 2 - mBitmapHeight / 2, mWidth / 2 + mBitmapWidth / 2, mHeight / 2 + mBitmapHeight / 2);
        canvas.drawBitmap(mSrcBitmap, null, rectF, mPaint);

    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int position = parent.getChildAdapterPosition(view);
        if (position == 0) {
            outRect.top = mHeight;
        }
    }


}
