diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java index b1664c9..0d63559 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java @@ -16,6 +16,8 @@ public class ButtonFlat extends Button { TextView textButton; + int paddingTop, paddingBottom, paddingLeft, paddingRight; + public ButtonFlat(Context context, AttributeSet attrs) { super(context, attrs); @@ -25,6 +27,10 @@ protected void setDefaultProperties(){ minHeight = 36; minWidth = 88; rippleSize = 3; + paddingBottom = Utils.dpToPx(16, getResources()); + paddingLeft = Utils.dpToPx(16, getResources()); + paddingRight = Utils.dpToPx(16, getResources()); + paddingTop = Utils.dpToPx(16, getResources()); // Min size setMinimumHeight(Utils.dpToPx(minHeight, getResources())); setMinimumWidth(Utils.dpToPx(minWidth, getResources())); @@ -33,6 +39,27 @@ protected void setDefaultProperties(){ @Override protected void setAttributes(AttributeSet attrs) { + + // Set Padding + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddingBottom = Utils.dpToPx(padding, getResources()); + paddingLeft = Utils.dpToPx(padding, getResources()); + paddingRight = Utils.dpToPx(padding, getResources()); + paddingTop = Utils.dpToPx(padding, getResources()); + } else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); + } + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + // Set text button String text = null; int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); @@ -41,8 +68,8 @@ protected void setAttributes(AttributeSet attrs) { }else{ text = attrs.getAttributeValue(ANDROIDXML,"text"); } + textButton = new TextView(getContext()); if(text != null){ - textButton = new TextView(getContext()); textButton.setText(text.toUpperCase()); textButton.setTextColor(backgroundColor); textButton.setTypeface(null, Typeface.BOLD); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java index e261c7d..d5e5175 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java @@ -14,111 +14,112 @@ import android.widget.TextView; public class ButtonRectangle extends Button { - - TextView textButton; - - int paddingTop,paddingBottom, paddingLeft, paddingRight; - - - public ButtonRectangle(Context context, AttributeSet attrs) { - super(context, attrs); - setDefaultProperties(); - } - @Override - protected void setDefaultProperties(){ -// paddingBottom = Utils.dpToPx(16, getResources()); -// paddingLeft = Utils.dpToPx(16, getResources()); -// paddingRight = Utils.dpToPx(16, getResources()); -// paddingTop = Utils.dpToPx(16, getResources()); - super.minWidth = 80; - super.minHeight = 36; - super.background = R.drawable.background_button_rectangle; - super.setDefaultProperties(); - } - - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ - - //Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - // Set Padding - String value = attrs.getAttributeValue(ANDROIDXML,"padding"); -// if(value != null){ -// float padding = Float.parseFloat(value.replace("dip", "")); -// paddingBottom = Utils.dpToPx(padding, getResources()); -// paddingLeft = Utils.dpToPx(padding, getResources()); -// paddingRight = Utils.dpToPx(padding, getResources()); -// paddingTop = Utils.dpToPx(padding, getResources()); -// }else{ -// value = attrs.getAttributeValue(ANDROIDXML,"paddingLeft"); -// paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingTop"); -// paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingRight"); -// paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingBottom"); -// paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); -// } - - - // Set text button - String text = null; - int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); - if(textResource != -1){ - text = getResources().getString(textResource); - }else{ - text = attrs.getAttributeValue(ANDROIDXML,"text"); - } - if(text != null){ - textButton = new TextView(getContext()); - textButton.setText(text); - textButton.setTextColor(Color.WHITE); - textButton.setTypeface(null, Typeface.BOLD); - LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); - textButton.setLayoutParams(params); - addView(textButton); + + TextView textButton; + + int paddingTop, paddingBottom, paddingLeft, paddingRight; + + + public ButtonRectangle(Context context, AttributeSet attrs) { + super(context, attrs); + setDefaultProperties(); + } + + @Override + protected void setDefaultProperties() { + paddingBottom = Utils.dpToPx(16, getResources()); + paddingLeft = Utils.dpToPx(16, getResources()); + paddingRight = Utils.dpToPx(16, getResources()); + paddingTop = Utils.dpToPx(16, getResources()); + super.minWidth = 80; + super.minHeight = 36; + super.background = R.drawable.background_button_rectangle; + super.setDefaultProperties(); + } + + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs) { + + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + // Color by hexadecimal + background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + // Set Padding + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddingBottom = Utils.dpToPx(padding, getResources()); + paddingLeft = Utils.dpToPx(padding, getResources()); + paddingRight = Utils.dpToPx(padding, getResources()); + paddingTop = Utils.dpToPx(padding, getResources()); + } else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); + } + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + // Set text button + String text = null; + int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); + if (textResource != -1) { + text = getResources().getString(textResource); + } else { + text = attrs.getAttributeValue(ANDROIDXML, "text"); + } + + textButton = new TextView(getContext()); + if (text != null) { + textButton.setText(text); + textButton.setTextColor(Color.WHITE); + textButton.setTypeface(null, Typeface.BOLD); + LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); + textButton.setLayoutParams(params); + addView(textButton); // FrameLayout.LayoutParams params = (LayoutParams) textView.getLayoutParams(); // params.width = getWidth(); // params.gravity = Gravity.CENTER_HORIZONTAL; //// params.setMargins(paddingLeft, paddingTop, paddingRight, paddingRight); // textView.setLayoutParams(params);textColor - int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1); - if(textColor != -1){ - textButton.setTextColor(textColor); - }else{ - // Color by hexadecimal - // Color by hexadecimal - textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); - if (textColor != -1) - textButton.setTextColor(textColor); - } - int[] array = {android.R.attr.textSize}; - TypedArray values = getContext().obtainStyledAttributes(attrs, array); - float textSize = values.getDimension(0, -1); - values.recycle(); - if(textSize != -1) - textButton.setTextSize(textSize); - - } - - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", Utils.dpToPx(6, getResources())); - } - + int textColor = attrs.getAttributeResourceValue(ANDROIDXML, "textColor", -1); + if (textColor != -1) { + textButton.setTextColor(textColor); + } else { + // Color by hexadecimal + // Color by hexadecimal + textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); + if (textColor != -1) + textButton.setTextColor(textColor); + } + int[] array = {android.R.attr.textSize}; + TypedArray values = getContext().obtainStyledAttributes(attrs, array); + float textSize = values.getDimension(0, -1); + values.recycle(); + if (textSize != -1) + textButton.setTextSize(textSize); + + } + + rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, + "rippleSpeed", Utils.dpToPx(6, getResources())); + } + // /** // * Center text in button // */ @@ -131,20 +132,21 @@ protected void setAttributes(AttributeSet attrs){ // textButton.setY(getHeight()/2-textButton.getHeight()/2 - paddingLeft + paddingRight); // txtCenter = true; // } - - Integer height; - Integer width; - @Override - protected void onDraw(Canvas canvas) { + + Integer height; + Integer width; + + @Override + protected void onDraw(Canvas canvas) { // if(!txtCenter) // centrarTexto(); - super.onDraw(canvas); - if (x != -1) { - Rect src = new Rect(0, 0, getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources())); - Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources())); - canvas.drawBitmap(makeCircle(), src, dst, null); - invalidate(); - } - } - + super.onDraw(canvas); + if (x != -1) { + Rect src = new Rect(0, 0, getWidth() - Utils.dpToPx(6, getResources()), getHeight() - Utils.dpToPx(7, getResources())); + Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth() - Utils.dpToPx(6, getResources()), getHeight() - Utils.dpToPx(7, getResources())); + canvas.drawBitmap(makeCircle(), src, dst, null); + invalidate(); + } + } + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index 27b41de..89d5718 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -119,7 +119,8 @@ public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { changeBackgroundColor((check) ? makePressColor() : Color .parseColor("#446D6D6D")); - } else if (event.getAction() == MotionEvent.ACTION_UP) { + } else if ((event.getAction() == MotionEvent.ACTION_UP) + | (event.getAction() == MotionEvent.ACTION_CANCEL)){ changeBackgroundColor(getResources().getColor( android.R.color.transparent)); press = false; diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml index 9215203..d7ae500 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml @@ -43,6 +43,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" + android:textColor="#ffffff" android:text="Button" /> @@ -68,7 +69,7 @@ + android:layout_height="wrap_content" >