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();

    }

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

        setGravity(Gravity.CENTER);
        setClickable(true);
        setTextColor(ColorStateList.valueOf(Color.WHITE));
        if (isInEditMode()) {
            setBackgroundColor(Color.BLUE);
        } else {
            if (mButtonStyle == ROUND) {
                setBackground(ResUtil.selector());
            } else if (mButtonStyle == ROUND_BORDER) {
            } else {
                setBackground(SkinHelper.getSkin().getThemeMaskBackgroundRoundSelector());
            }
        }
    }

    @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));
        }
    }
}

@@ -1160,34 +1160,42 @@
     
-%7D%0D%0A%0D%0A    @Override
+    initButton();%0D%0A    %7D%0D%0A
 %0D%0A    pr
 otec
@@ -1186,31 +1186,29 @@
  %7D%0D%0A%0D%0A    pr
-otec
+iva
 te
-d
  void initVi
@@ -1205,20 +1205,22 @@
 oid init
-View
+Button
 () %7B%0D%0A  
@@ -1229,247 +1229,500 @@
     
-super.initView();%0D%0A%0D%0A        setGravity(Gravity.CENTER);%0D%0A        setClickable(true);%0D%0A        setTextColor(ColorStateList.valueOf(Color.WHITE));%0D%0A        if (isInEditMode()) %7B%0D%0A            setBackgroundColor(Color.BLUE);%0D%0A        %7D else %7B
+if (isInEditMode()) %7B%0D%0A            setBackgroundColor(Color.BLUE);%0D%0A        %7D else %7B%0D%0A            if (mButtonStyle == ROUND) %7B%0D%0A                setBackground(ResUtil.ripple(SkinHelper.getSkin().getThemeSubColor(),%0D%0A                        ResUtil.selector(%0D%0A                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeSubColor(), 300),%0D%0A                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeDarkColor(), 300)%0D%0A                        )));
 %0D%0A  
@@ -1723,32 +1723,39 @@
 );%0D%0A            
+%7D else 
 if (mButtonStyle
@@ -1755,32 +1755,39 @@
 onStyle == ROUND
+_BORDER
 ) %7B%0D%0A           
@@ -1817,20 +1817,55 @@
 til.
-select
+ripple(SkinHelper.getSkin().getThemeSubCol
 or()
-);
+,
 %0D%0A  
@@ -1878,190 +1878,805 @@
     
-%7D else if (mButtonStyle == ROUND_BORDER) %7B%0D%0A            %7D else %7B%0D%0A                setBackground(SkinHelper.getSkin().getThemeMaskBackgroundRoundSelector());%0D%0A            %7D%0D%0A        %7D
+            ResUtil.selector(%0D%0A                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeSubColor(), Color.TRANSPARENT, (int) (1 * density()), 300),%0D%0A                                ResUtil.createDrawable(SkinHelper.getSkin().getThemeDarkColor(), Color.TRANSPARENT, (int) (1 * density()), 300)%0D%0A                        )));%0D%0A                setTextColor(ColorStateList.valueOf(SkinHelper.getSkin().getThemeSubColor()));%0D%0A            %7D else %7B%0D%0A                setBackground(SkinHelper.getSkin().getThemeMaskBackgroundRoundSelector());%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    protected void initView() %7B%0D%0A        super.initView();%0D%0A%0D%0A        setGravity(Gravity.CENTER);%0D%0A        setClickable(true);%0D%0A        setTextColor(ColorStateList.valueOf(Color.WHITE));
 %0D%0A  

fix button