Skip to content

Commit

Permalink
fixed issues: #23 #30 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
xcelder committed Nov 7, 2016
1 parent b11cdc7 commit 5583f69
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()));
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// */
Expand All @@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"

android:textColor="#ffffff"
android:text="Button" />
</RelativeLayout>
Expand All @@ -68,7 +69,7 @@

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="72dp" >
android:layout_height="wrap_content" >

<com.gc.materialdesign.views.ButtonRectangle
android:id="@+id/button"
Expand Down
2 changes: 1 addition & 1 deletion MaterialDesignLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.+'
classpath 'com.android.tools.build:gradle:2.2.2'
// COMMENT TO DEVELOPER MODE / UNCOMMENT TO UPLOAD TO BINTARRAY
// classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Aug 22 18:02:59 CEST 2015
#Mon Nov 07 19:27:37 CET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 comments on commit 5583f69

Please sign in to comment.