package com.wasu.cs.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import cn.com.wasu.main.R;


/**
 * Created by jeepc on 2016/8/26.
 */

public class TimeLineView extends View {

    private int size;
    private Context mContext;
    private Rect mRect;

    public int getRadius() {
        return radius;
    }

    public void setRadius(int radius) {
        this.radius = radius;
    }

    private int radius;
    private boolean isFirst = false;

    public Paint getPaintCircle() {
        return paintCircle;
    }

    public void setPaintCircleColor(String color) {
        paintCircle.setColor(Color.parseColor(color));
        this.invalidate();
    }

    private Paint paintLine;
    private Paint paintCircle;

    public void setSize(int size) {
        this.size = size;
    }
    public void setIsFirst(boolean isFirst) {
        this.isFirst = isFirst;
    }

    public TimeLineView(Context context) {
        super(context);
        this.mContext = context;
        init(mContext);
    }

    public TimeLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        init(mContext);
    }

    private void init(Context context) {
        mRect = new Rect();
        paintLine = new Paint();
        paintLine.setColor(Color.parseColor("#7fffffff"));
        paintCircle = new Paint();
        paintCircle.setColor(Color.parseColor("#7fffffff"));
        paintCircle.setAntiAlias(true);
        radius = (int) getResources().getDimension(R.dimen.d_5dp);
    }

    private void addOne() {

    }

    /*public void setHighlight(int index){
        this.getc
    }*/

    private int offset = (int)getResources().getDimension(R.dimen.d_8dp);

    @Override
    protected void onDraw(Canvas canvas) {
        mRect = canvas.getClipBounds();
        if(!isFirst){
            drawLineFirst(canvas, mRect,paintLine);
        }
        drawLine(canvas, mRect,radius,paintLine);
        drawCircle(canvas,mRect,radius,paintCircle);
        super.onDraw(canvas);
    }

    private void drawLine(Canvas canvas, Rect rect,int radius,Paint paintLine) {
        canvas.drawLine(rect.centerX(), rect.top+2*radius+offset, rect.centerX(), rect.bottom,paintLine);
    }
    private void drawLineFirst(Canvas canvas, Rect rect,Paint paintLine) {
        canvas.drawLine(rect.centerX(), rect.top, rect.centerX(),offset,paintLine);
    }
    private void drawCircle(Canvas canvas, Rect rect,int radius,Paint paintCircle) {
        canvas.drawCircle(rect.centerX(),radius+offset,radius,paintCircle);
    }

}
