package com.skyacer.material.materialswitches;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.CompoundButton;

/**
 * Created by Wayne on 15/12/23.
 */
public class CheckBox extends CompoundButton {

    private int mUncheckedColor;
    private int mCheckedColor;
    private int mPointColor;
    private int mTickColor;
    private int mCheckBoxWidth;
    private int mCheckBoxHeight;
    private int mCornerRadius;
    private int mBorderWidth;
    private int mThumbCircleSize;
    private int mTickWidth;
    private int mThumbCircleRadius;
    private int mTickLeftRightPadding;
    private int mTickTopPadding;
    private int mTickBottomPadding;


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

    public CheckBox(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray attributes = context.obtainStyledAttributes(attrs,R.styleable.CheckBox);
        mUncheckedColor = attributes.getColor(R.styleable.CheckBox_checkbox_unchecked_color
                ,ContextCompat.getColor(context,R.color.checkbox_unchecked_color));
        mCheckedColor = attributes.getColor(R.styleable.CheckBox_checkbox_checked_color
                , ContextCompat.getColor(context,R.color.checkbox_checked_color));
        attributes.recycle();
        mTickColor = ContextCompat.getColor(context,R.color.checkbox_tick_color);
        mCheckBoxWidth = getResources().getDimensionPixelSize(R.dimen.checkbox_width);
        mCheckBoxHeight = getResources().getDimensionPixelSize(R.dimen.checkbox_height);
        mCornerRadius = getResources().getDimensionPixelSize(R.dimen.checkbox_corner_radius);
        mThumbCircleSize = getResources().getDimensionPixelSize(R.dimen.checkbox_thumb_circle_size);
        mBorderWidth = getResources().getDimensionPixelSize(R.dimen.checkbox_border_width);
        mTickWidth = getResources().getDimensionPixelSize(R.dimen.checkbox_tick_width);
        mThumbCircleRadius = getResources().getDimensionPixelSize(R.dimen.checkbox_thumb_circle_radius);
        mTickLeftRightPadding = getResources().getDimensionPixelSize(R.dimen.checkbox_tick_left_right_padding);
        mTickTopPadding = getResources().getDimensionPixelSize(R.dimen.checkbox_tick_top_padding);
        mTickBottomPadding = getResources().getDimensionPixelSize(R.dimen.checkbo_tick_bottom_padding);

    }


}

@@ -112,16 +112,78 @@
 dArray;%0A
+import android.graphics.Color;%0Aimport android.graphics.RectF;%0A
 import a
@@ -2651,16 +2651,1753 @@
 dding);%0A
+    %7D%0A%0A    @Override%0A    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) %7B%0A        int size;%0A        int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);%0A        int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);%0A        if(widthSpecMode == MeasureSpec.EXACTLY)%7B%0A            if (widthSpecSize %3C mCheckBoxWidth)%7B%0A                size = mCheckBoxWidth;%0A            %7D else %7B%0A                size = widthSpecSize;%0A            %7D%0A        %7D   else %7B%0A            size = mCheckBoxWidth;%0A        %7D%0A%0A        widthMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);%0A        int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);%0A        int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);%0A        if (heightSpecMode == MeasureSpec.EXACTLY)%7B%0A            if (heightSpecSize %3C mCheckBoxHeight)%7B%0A                size = mCheckBoxHeight;%0A            %7Delse %7B%0A                size = heightSpecSize;%0A            %7D%0A        %7Delse %7B%0A            size = mCheckBoxHeight;%0A        %7D%0A%0A        heightMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);%0A        super.onMeasure(widthMeasureSpec, heightMeasureSpec);%0A    %7D%0A%0A    private RectF getRectFrame()%7B%0A        RectF rectF = new RectF();%0A        rectF.left = (getWidth() - mThumbCircleSize) / 2;%0A        rectF.top = (getHeight() - mThumbCircleSize) / 2;%0A        rectF.right = (getWidth() - mThumbCircleSize) / 2 + mThumbCircleSize;%0A%0A        return rectF;%0A    %7D%0A%0A    private int thumbCircleColor(int color)%7B%0A        int alpha = Math.round(Color.alpha(color) * 0.3f);%0A        int red = Color.red(color);%0A        int green = Color.green(color);%0A        int blue = Color.blue(color);%0A        return Color.argb(alpha,red,green,blue);
 %0A    %7D%0A%0A

add some method in CheckBox