package com.angcyo.uiview.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;

import com.angcyo.uiview.R;
import com.angcyo.uiview.resources.ResUtil;
import com.angcyo.uiview.skin.SkinHelper;

/**
 * Copyright (C) 2016,深圳市红鸟网络科技股份有限公司 All rights reserved.
 * 项目名称：
 * 类的描述：
 * 创建人员：Robi
 * 创建时间：2017/05/09 17:44
 * 修改人员：Robi
 * 修改时间：2017/05/09 17:44
 * 修改备注：
 * Version: 1.0.0
 */
public class Button extends RTextView {

    public static final int DEFAULT = 1;
    public static final int ROUND = 2;
    public static final int ROUND_BORDER = 3;

    int mButtonStyle = DEFAULT;

    public Button(Context context) {
        this(context, null);
    }

    public Button(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Button);
        mButtonStyle = typedArray.getInt(R.styleable.Button_r_button_style, DEFAULT);
        typedArray.recycle();

        initButton();
    }

    private void initButton() {
        if (isInEditMode()) {
            setBackgroundColor(Color.BLUE);
        } else {
            if (mButtonStyle == ROUND) {
                setBackground(ResUtil.ripple(SkinHelper.getSkin().getThemeSubColor(),
                        ResUtil.selector(
                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeSubColor(), 300),
                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeDarkColor(), 300)
                        )));
            } else if (mButtonStyle == ROUND_BORDER) {
                setBackground(ResUtil.ripple(SkinHelper.getSkin().getThemeSubColor(),
                        ResUtil.selector(
                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeSubColor(), Color.TRANSPARENT, (int) (1 * density()), 300),
                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeDarkColor(), Color.TRANSPARENT, (int) (1 * density()), 300)
                        )));
                setTextColor(ColorStateList.valueOf(SkinHelper.getSkin().getThemeSubColor()));
            } else {
                setBackground(SkinHelper.getSkin().getThemeMaskBackgroundRoundSelector());
            }
        }
    }

    @Override
    protected void initView() {
        super.initView();

        setGravity(Gravity.CENTER);
        setClickable(true);
        setTextColor(ColorStateList.valueOf(Color.WHITE));
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if ((heightMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.UNSPECIFIED) &&
                getPaddingTop() == 0 && getPaddingBottom() == 0) {
            setMeasuredDimension(getMeasuredWidth(), getResources().getDimensionPixelOffset(R.dimen.default_button_height));
        }
    }
}

@@ -603,24 +603,66 @@
 xtView %7B%0D%0A%0D%0A
+    /**%0D%0A     * %E9%BB%98%E8%AE%A4%E5%B0%B1%E6%98%AF%E5%BE%88%E5%B0%8F%E7%9A%84%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2%E5%A1%AB%E5%85%85%E6%A0%B7%E5%BC%8F%0D%0A     */%0D%0A
     public s
@@ -691,16 +691,51 @@
 T = 1;%0D%0A
+    /**%0D%0A     * %E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2%E5%A1%AB%E5%85%85%E6%A0%B7%E5%BC%8F%0D%0A     */%0D%0A
     publ
@@ -766,16 +766,54 @@
 D = 2;%0D%0A
+    /**%0D%0A     * %E5%8F%AF%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E5%9C%86%E8%A7%92%E8%BE%B9%E6%A1%86%E6%A0%B7%E5%BC%8F%0D%0A     */%0D%0A
     publ
@@ -1379,39 +1379,1045 @@
     
-setBackgroundColor(Color.BLUE);
+if (mButtonStyle == ROUND) %7B%0D%0A                setBackground(ResUtil.ripple(Color.BLUE,%0D%0A                        ResUtil.selector(%0D%0A                                ResUtil.createDrawable(Color.BLUE, 300),%0D%0A                                ResUtil.createDrawable(Color.BLUE, 300)%0D%0A                        )));%0D%0A            %7D else if (mButtonStyle == ROUND_BORDER) %7B%0D%0A                setBackground(ResUtil.ripple(Color.BLUE,%0D%0A                        ResUtil.selector(%0D%0A                                ResUtil.createDrawable(Color.BLUE, Color.TRANSPARENT, (int) (1 * density()), 300),%0D%0A                                ResUtil.createDrawable(Color.BLUE, Color.TRANSPARENT, (int) (1 * density()), 300)%0D%0A                        )));%0D%0A                setTextColor(ColorStateList.valueOf(Color.BLUE));%0D%0A            %7D else %7B%0D%0A                setBackground(ResUtil.generateRippleRoundMaskDrawable(getResources().getDimensionPixelOffset(R.dimen.base_round_little_radius),%0D%0A                        Color.WHITE, Color.BLUE, Color.BLUE));%0D%0A            %7D
 %0D%0A  

add button note