Skip to content

Commit 525b7a9

Browse files
author
Ivan Navas
committed
Fix Bugs and add new attributes Button Rectangle
I've fixed the bug with the xml background in the FloatButton and I've added textColor and TextSize attributes to the ButtonRectangle
1 parent 1d5cbfa commit 525b7a9

File tree

9 files changed

+59
-38
lines changed

9 files changed

+59
-38
lines changed

MaterialDesign/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
defaultConfig {
2626
minSdkVersion 8
2727
targetSdkVersion 21
28-
versionCode 6
29-
versionName '1.4'
28+
versionCode 7
29+
versionName '1.5'
3030
}
3131
}
3232

MaterialDesign/src/com/gc/materialdesign/views/Button.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ public abstract class Button extends CustomView {
3030
OnClickListener onClickListener;
3131
boolean clickAfterRipple = true;
3232
int backgroundColor = Color.parseColor("#1E88E5");
33+
TextView textButton;
3334

3435
public Button(Context context, AttributeSet attrs) {
3536
super(context, attrs);
3637
setDefaultProperties();
37-
clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", true);
38+
clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
39+
"animate", true);
3840
setAttributes(attrs);
3941
beforeBackground = backgroundColor;
40-
if(rippleColor==null)
41-
rippleColor = makePressColor();
42+
if (rippleColor == null)
43+
rippleColor = makePressColor();
4244
}
4345

4446
protected void setDefaultProperties() {
@@ -49,7 +51,6 @@ protected void setDefaultProperties() {
4951
setBackgroundResource(background);
5052
setBackgroundColor(backgroundColor);
5153
}
52-
5354

5455
// Set atributtes of XML to View
5556
abstract protected void setAttributes(AttributeSet attrs);
@@ -82,18 +83,18 @@ public boolean onTouchEvent(MotionEvent event) {
8283
if ((event.getX() <= getWidth() && event.getX() >= 0)
8384
&& (event.getY() <= getHeight() && event.getY() >= 0)) {
8485
radius++;
85-
if(!clickAfterRipple && onClickListener != null){
86+
if (!clickAfterRipple && onClickListener != null) {
8687
onClickListener.onClick(this);
8788
}
8889
} else {
8990
isLastTouch = false;
9091
x = -1;
9192
y = -1;
9293
}
93-
}else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
94-
isLastTouch = false;
95-
x = -1;
96-
y = -1;
94+
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
95+
isLastTouch = false;
96+
x = -1;
97+
y = -1;
9798
}
9899
}
99100
return true;
@@ -130,7 +131,7 @@ public Bitmap makeCircle() {
130131
x = -1;
131132
y = -1;
132133
radius = getHeight() / rippleSize;
133-
if (onClickListener != null&& clickAfterRipple)
134+
if (onClickListener != null && clickAfterRipple)
134135
onClickListener.onClick(this);
135136
}
136137
return output;
@@ -172,13 +173,27 @@ public void setBackgroundColor(int color) {
172173
}
173174
}
174175

175-
abstract public TextView getTextView();
176-
177176
public void setRippleSpeed(float rippleSpeed) {
178177
this.rippleSpeed = rippleSpeed;
179178
}
180179

181180
public float getRippleSpeed() {
182181
return this.rippleSpeed;
183182
}
183+
184+
public void setText(String text) {
185+
textButton.setText(text);
186+
}
187+
188+
public void setTextColor(int color) {
189+
textButton.setTextColor(color);
190+
}
191+
192+
public TextView getTextView() {
193+
return textButton;
194+
}
195+
196+
public String getText() {
197+
return textButton.getText().toString();
198+
}
184199
}

MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import android.graphics.Rect;
1717
import android.graphics.Bitmap.Config;
1818
import android.graphics.drawable.Drawable;
19+
import android.graphics.drawable.GradientDrawable;
20+
import android.graphics.drawable.LayerDrawable;
1921
import android.util.AttributeSet;
2022
import android.view.animation.BounceInterpolator;
2123
import android.widget.ImageView;
@@ -43,6 +45,7 @@ public class ButtonFloat extends Button{
4345
public ButtonFloat(Context context, AttributeSet attrs) {
4446
super(context, attrs);
4547
setBackgroundResource(R.drawable.background_button_float);
48+
setBackgroundColor(backgroundColor);
4649
sizeRadius = 28;
4750
setDefaultProperties();
4851
icon = new ImageView(context);
@@ -202,4 +205,5 @@ public void hide(){
202205
public boolean isShow(){
203206
return isShow;
204207
}
208+
205209
}

MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.gc.materialdesign.utils.Utils;
55

66
import android.content.Context;
7+
import android.content.res.TypedArray;
78
import android.graphics.Canvas;
89
import android.graphics.Color;
910
import android.graphics.Rect;
@@ -94,7 +95,23 @@ protected void setAttributes(AttributeSet attrs){
9495
// params.width = getWidth();
9596
// params.gravity = Gravity.CENTER_HORIZONTAL;
9697
//// params.setMargins(paddingLeft, paddingTop, paddingRight, paddingRight);
97-
// textView.setLayoutParams(params);
98+
// textView.setLayoutParams(params);textColor
99+
int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1);
100+
if(textColor != -1){
101+
textButton.setTextColor(textColor);
102+
}else{
103+
// Color by hexadecimal
104+
// Color by hexadecimal
105+
textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1);
106+
if (textColor != -1)
107+
textButton.setTextColor(textColor);
108+
}
109+
int[] array = {android.R.attr.textSize};
110+
TypedArray values = getContext().obtainStyledAttributes(attrs, array);
111+
float textSize = values.getDimension(0, -1);
112+
values.recycle();
113+
if(textSize != -1)
114+
textButton.setTextSize(textSize);
98115

99116
}
100117

@@ -130,20 +147,4 @@ protected void onDraw(Canvas canvas) {
130147
}
131148
}
132149

133-
public void setText(String text){
134-
textButton.setText(text);
135-
}
136-
137-
public void setTextColor(int color){
138-
textButton.setTextColor(color);
139-
}
140-
@Override
141-
public TextView getTextView() {
142-
return textButton;
143-
}
144-
145-
public String getText(){
146-
return textButton.getText().toString();
147-
}
148-
149150
}

MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public boolean onTouchEvent(MotionEvent event) {
102102
isLastTouch = false;
103103
check = !check;
104104
if (onCheckListener != null)
105-
onCheckListener.onCheck(check);
105+
onCheckListener.onCheck(CheckBox.this, check);
106106
if (check) {
107107
step = 0;
108108
}
@@ -235,7 +235,7 @@ public void setOncheckListener(OnCheckListener onCheckListener) {
235235
}
236236

237237
public interface OnCheckListener {
238-
public void onCheck(boolean check);
238+
public void onCheck(CheckBox view, boolean check);
239239
}
240240

241241
}

MaterialDesign/src/com/gc/materialdesign/views/Slider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ protected void setAttributes(AttributeSet attrs) {
9494

9595
@Override
9696
public void invalidate() {
97-
ball.invalidate();
97+
if(ball != null)
98+
ball.invalidate();
9899
super.invalidate();
99100
}
100101

MaterialDesign/src/com/gc/materialdesign/views/Switch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public boolean onTouchEvent(MotionEvent event) {
108108
if (eventCheck != check) {
109109
eventCheck = check;
110110
if (onCheckListener != null)
111-
onCheckListener.onCheck(check);
111+
onCheckListener.onCheck(Switch.this,check);
112112
}
113113
if ((event.getX() <= getWidth() && event.getX() >= 0)) {
114114
ball.animateCheck();
@@ -244,7 +244,7 @@ public void setOncheckListener(OnCheckListener onCheckListener) {
244244
}
245245

246246
public interface OnCheckListener {
247-
public void onCheck(boolean check);
247+
public void onCheck(Switch view,boolean check);
248248
}
249249

250250
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repositories {
3838
}
3939

4040
dependencies {
41-
compile 'com.github.navasmdc:MaterialDesign:1.+@aar'
41+
compile 'com.github.navasmdc:MaterialDesign:1.5@aar'
4242
}
4343
```
4444

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ allprojects {
1919
}
2020

2121
group = "com.github.navasmdc"
22-
version = "1.4"
22+
version = "1.5"
2323
}
2424

0 commit comments

Comments
 (0)