Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ with xml:
android:id="@+id/btn2"
android:text="Android button modified in layout"
app:buttonColor="@android:color/black"
app:rippleColor="@android:color/white"/>
app:rippleEffectColor="@android:color/white"/>

<!-- Edited programatically -->
<com.xgc1986.ripplebutton.widget.RippleButton
Expand All @@ -75,8 +75,8 @@ with java:
// Change color programatically
RippleButton rb = (RippleButton)findViewById(R.id.btn3);
int buttonColor = getResources().getColor(android.R.color.holo_red_light);
int rippleColor = getResources().getColor(android.R.color.holo_blue_light);
rb.setColors(buttonColor, rippleColor);
int rippleEffectColor = getResources().getColor(android.R.color.holo_blue_light);
rb.setColors(buttonColor, rippleEffectColor);
}
```

Expand Down
10 changes: 5 additions & 5 deletions docs/RippleButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inherits from [android.widget.Button](http://developer.android.com/reference/and
| Attribute | Type | Description |
| ------------- | ------------- | ------------- |
| app:buttonColor | color | The color of the button. |
| app:rippleColor | color | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| app:rippleEffectColor | color | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |

###Style
| Attribute | Type | Description |
Expand All @@ -30,8 +30,8 @@ Inherits from [android.widget.Button](http://developer.android.com/reference/and
| Method | Description |
| ------------- | ------------- |
| setButtonColor(int color) | The color of the button. |
| setRippleColor(int color) | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setColors(int buttonColor, int rippleColor) | The color of the button and the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setrippleEffectColor(int color) | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setColors(int buttonColor, int rippleEffectColor) | The color of the button and the ripple effect in v21, in previous versions is the color of the button while pressed. |

##Examples
From java
Expand All @@ -49,7 +49,7 @@ From java

//java
int buttonColor = 0xff33b5e5; //holo_blue_light
int rippleColor = 0x80ffffff; //transparent white
int rippleEffectColor = 0x80ffffff; //transparent white
final RippleButton rb = (RippleButton)findViewById(R.id.rippleButton);
rb.setColors(colors[1], colors[2]);
```
Expand All @@ -63,7 +63,7 @@ From xml
android:layout_height="wrap_content"
android:id="@+id/rippleButton"
android:text="Click me!"
app:rippleColor="#ff33b5e5"
app:rippleEffectColor="#ff33b5e5"
app:buttonColor="#80ffffff"
app:/>
```
Expand Down
10 changes: 5 additions & 5 deletions docs/RippleImageButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inherits from [android.widget.ImageButton](http://developer.android.com/referenc
| Attribute | Type | Description |
| ------------- | ------------- | ------------- |
| app:buttonColor | color | The color of the button. |
| app:rippleColor | color | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| app:rippleEffectColor | color | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |

###Style
| Attribute | Type | Description |
Expand All @@ -30,8 +30,8 @@ Inherits from [android.widget.ImageButton](http://developer.android.com/referenc
| Method | Description |
| ------------- | ------------- |
| setButtonColor(int color) | The color of the button. |
| setRippleColor(int color) | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setColors(int buttonColor, int rippleColor) | The color of the button and the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setrippleEffectColor(int color) | The color of the ripple effect in v21, in previous versions is the color of the button while pressed. |
| setColors(int buttonColor, int rippleEffectColor) | The color of the button and the ripple effect in v21, in previous versions is the color of the button while pressed. |

##Examples
From java
Expand All @@ -49,7 +49,7 @@ From java

//java
int buttonColor = 0xff33b5e5; //holo_blue_light
int rippleColor = 0x80ffffff; //transparent white
int rippleEffectColor = 0x80ffffff; //transparent white
final RippleImageButton rib = (RippleImageButton)findViewById(R.id.rippleImageButton);
rib.setColors(colors[1], colors[2]);
```
Expand All @@ -63,7 +63,7 @@ From xml
android:layout_height="wrap_content"
android:id="@+id/rippleImageButton"
android:text="Click me!"
app:rippleColor="#ff33b5e5"
app:rippleEffectColor="#ff33b5e5"
app:buttonColor="#80ffffff"
app:/>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public RippleButton(Context context) {

// TODO get style color;
private int buttonColor = 0xffd6d7d7;
private int rippleColor = 0x40000000;
private int rippleEffectColor = 0x40000000;

public RippleButton(Context context, AttributeSet attrs) {
super(context, attrs);
Expand All @@ -45,16 +45,16 @@ public RippleButton(Context context, AttributeSet attrs, int defStyleAttr, int d
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setColors(int buttonColor, int controlHighlightColor) {
this.buttonColor = buttonColor;
rippleColor = controlHighlightColor;
rippleEffectColor = controlHighlightColor;
setButtonColor(buttonColor);
setRippleColor(controlHighlightColor);
setRippleEffectColor(controlHighlightColor);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setRippleColor(final int color) {
rippleColor = color;
public void setRippleEffectColor(final int color) {
rippleEffectColor = color;

if (rippleColor == 0) {
if (rippleEffectColor == 0) {
return;
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand All @@ -68,7 +68,7 @@ public void setRippleColor(final int color) {
new int[]{0}
},
new int[]{
rippleColor,
rippleEffectColor,
buttonColor
}
);
Expand Down Expand Up @@ -115,28 +115,28 @@ private void manageAttibuteSet(AttributeSet attrs) {
int[] tAttrs = {android.R.attr.colorControlHighlight, android.R.attr.colorButtonNormal};
TypedArray ta = getContext().getTheme().obtainStyledAttributes(tAttrs);
buttonColor = ta.getColor(1, 0);
rippleColor = ta.getColor(0, 0);
rippleEffectColor = ta.getColor(0, 0);
ta.recycle();
} else {
int[] tAttrs = {R.attr.colorControlHighlight, R.attr.colorButtonNormal};
TypedArray ta = getContext().getTheme().obtainStyledAttributes(s, tAttrs);
buttonColor = ta.getColor(1, 0);
rippleColor = ta.getColor(0, 0);
rippleEffectColor = ta.getColor(0, 0);
ta.recycle();

}

TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RippleButton);

int nColor = a.getColor(R.styleable.RippleButton_buttonColor, buttonColor);
int hColor = a.getColor(R.styleable.RippleButton_rippleColor, rippleColor);
int hColor = a.getColor(R.styleable.RippleButton_rippleEffectColor, rippleEffectColor);

a.recycle();

buttonColor = nColor;
rippleColor = hColor;
rippleEffectColor = hColor;
setButtonColor(nColor);
setRippleColor(hColor);
setRippleEffectColor(hColor);
}
}

Expand All @@ -152,9 +152,9 @@ public boolean onTouchEvent(MotionEvent event) {
getBackground().clearColorFilter();
}
} else {
if (rippleColor != 0) {
if (rippleEffectColor != 0) {
setBackground(getResources().getDrawable(R.drawable.btn_default_normal_ripple));
getBackground().setColorFilter(rippleColor, PorterDuff.Mode.MULTIPLY);
getBackground().setColorFilter(rippleEffectColor, PorterDuff.Mode.MULTIPLY);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.ImageButton;

import com.xgc1986.ripplebutton.R;
Expand All @@ -23,7 +22,7 @@ public class RippleImageButton extends ImageButton {

// TODO get style color;
private int buttonColor = 0xffd6d7d7;
private int rippleColor = 0x40000000;
private int rippleEffectColor = 0x40000000;

public RippleImageButton(Context context) {
super(context);
Expand All @@ -48,12 +47,12 @@ public RippleImageButton(Context context, AttributeSet attrs, int defStyleAttr,
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setColors(int buttonColor, int controlHighlightColor) {
setButtonColor(buttonColor);
setRippleColor(controlHighlightColor);
setRippleEffectColor(controlHighlightColor);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setRippleColor(final int color) {
rippleColor = color;
public void setRippleEffectColor(final int color) {
rippleEffectColor = color;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Drawable drawable = getBackground();

Expand All @@ -65,7 +64,7 @@ public void setRippleColor(final int color) {
new int[]{android.R.attr.state_pressed}
},
new int[]{
rippleColor
rippleEffectColor
}
);

Expand Down Expand Up @@ -102,10 +101,10 @@ private void manageAttibuteSet(AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RippleButton);

int nColor = a.getInt(R.styleable.RippleButton_buttonColor, buttonColor);
int hColor = a.getInt(R.styleable.RippleButton_rippleColor, rippleColor);
int hColor = a.getInt(R.styleable.RippleButton_rippleEffectColor, rippleEffectColor);

setButtonColor(nColor);
setRippleColor(hColor);
setRippleEffectColor(hColor);

a.recycle();
}
Expand All @@ -123,9 +122,9 @@ public boolean onTouchEvent(MotionEvent event) {
getBackground().clearColorFilter();
}
} else {
if (rippleColor != 0) {
if (rippleEffectColor != 0) {
setBackground(getResources().getDrawable(R.drawable.btn_default_normal_ripple));
getBackground().setColorFilter(rippleColor, PorterDuff.Mode.MULTIPLY);
getBackground().setColorFilter(rippleEffectColor, PorterDuff.Mode.MULTIPLY);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ripplebutton/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</declare-styleable>

<declare-styleable name="RippleButton">
<attr name="rippleColor" format="color"/>
<attr name="rippleEffectColor" format="color"/>
<attr name="buttonColor" format="color"/>
</declare-styleable>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:id="@+id/btn2"
android:text="Click me!"
android:textColor="#ff000000"
app:rippleColor="#ffff4444"/>
app:rippleEffectColor="#ffff4444"/>

<!-- Edited programatically -->
<com.xgc1986.ripplebutton.widget.RippleButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:layout_height="wrap_content"
android:id="@+id/btn2"
android:src="@android:drawable/stat_sys_headset"
app:rippleColor="#ffff4444"/>
app:rippleEffectColor="#ffff4444"/>

<!-- Edited programatically -->
<com.xgc1986.ripplebutton.widget.RippleImageButton
Expand Down