Skip to content

Commit c776a17

Browse files
author
ivan.navas
committed
Add new xml attributes and fix problem in checkbox
1 parent eb929c9 commit c776a17

File tree

8 files changed

+56
-2
lines changed

8 files changed

+56
-2
lines changed

AndroidStudio/MaterialDesign/app/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ protected void setDefaultProperties(){
3333
super.minHeight = 36;
3434
super.background = R.drawable.background_button_rectangle;
3535
super.setDefaultProperties();
36-
rippleSpeed = Utils.dpToPx(3, getResources());
3736
}
3837

3938

@@ -97,6 +96,9 @@ protected void setAttributes(AttributeSet attrs){
9796
// textView.setLayoutParams(params);
9897

9998
}
99+
100+
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML,
101+
"rippleSpeed", Utils.dpToPx(6, getResources()));
100102
}
101103

102104
// /**

AndroidStudio/MaterialDesign/app/src/main/java/com/gc/materialdesign/views/CheckBox.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public void setBackgroundColor(int color) {
154154

155155
public void setChecked(boolean check) {
156156
this.check = check;
157+
setPressed(false);
158+
changeBackgroundColor(getResources().getColor(
159+
android.R.color.transparent));
157160
if (check) {
158161
step = 0;
159162
}

AndroidStudio/MaterialDesign/app/src/main/java/com/gc/materialdesign/views/LayoutRipple.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ protected void setAttributes(AttributeSet attrs) {
4646
else
4747
setBackgroundColor(this.backgroundColor);
4848
}
49+
// Set background Color
50+
// Color by resource
51+
int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML,
52+
"rippleColor", -1);
53+
if (rippleColor != -1) {
54+
setRippleColor(getResources().getColor(rippleColor));
55+
} else {
56+
// Color by hexadecimal
57+
String background = attrs.getAttributeValue(MATERIALDESIGNXML,
58+
"rippleColor");
59+
if (background != null)
60+
setRippleColor(Color.parseColor(background));
61+
else
62+
setRippleColor(makePressColor());
63+
}
64+
65+
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML,
66+
"rippleSpeed", 20f);
4967
}
5068

5169
// Set color of background

AndroidStudio/MaterialDesign/app/src/main/res/values/attributes.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<attr name="iconFloat" format="integer" />
1818
<!-- in float button indicate if must start with animation -->
1919
<attr name="animate" format="boolean" />
20+
<!-- Speed of ripple animation -->
21+
<attr name="rippleSpeed" format="float" />
22+
<!-- in float button indicate if must start with animation -->
23+
<attr name="rippleColor" format="color|reference" />
2024
</declare-styleable>
2125

2226

MaterialDesign/res/values/attributes.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<attr name="iconFloat" format="integer" />
1818
<!-- in float button indicate if must start with animation -->
1919
<attr name="animate" format="boolean" />
20+
<!-- Speed of ripple animation -->
21+
<attr name="rippleSpeed" format="float" />
22+
<!-- in float button indicate if must start with animation -->
23+
<attr name="rippleColor" format="color|reference" />
2024
</declare-styleable>
2125

2226

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ protected void setDefaultProperties(){
3333
super.minHeight = 36;
3434
super.background = R.drawable.background_button_rectangle;
3535
super.setDefaultProperties();
36-
rippleSpeed = Utils.dpToPx(3, getResources());
3736
}
3837

3938

@@ -97,6 +96,9 @@ protected void setAttributes(AttributeSet attrs){
9796
// textView.setLayoutParams(params);
9897

9998
}
99+
100+
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML,
101+
"rippleSpeed", Utils.dpToPx(6, getResources()));
100102
}
101103

102104
// /**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public void setBackgroundColor(int color) {
154154

155155
public void setChecked(boolean check) {
156156
this.check = check;
157+
setPressed(false);
158+
changeBackgroundColor(getResources().getColor(
159+
android.R.color.transparent));
157160
if (check) {
158161
step = 0;
159162
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ protected void setAttributes(AttributeSet attrs) {
4646
else
4747
setBackgroundColor(this.backgroundColor);
4848
}
49+
// Set background Color
50+
// Color by resource
51+
int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML,
52+
"rippleColor", -1);
53+
if (rippleColor != -1) {
54+
setRippleColor(getResources().getColor(rippleColor));
55+
} else {
56+
// Color by hexadecimal
57+
String background = attrs.getAttributeValue(MATERIALDESIGNXML,
58+
"rippleColor");
59+
if (background != null)
60+
setRippleColor(Color.parseColor(background));
61+
else
62+
setRippleColor(makePressColor());
63+
}
64+
65+
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML,
66+
"rippleSpeed", 20f);
4967
}
5068

5169
// Set color of background

0 commit comments

Comments
 (0)