Skip to content

Commit 681b0c4

Browse files
committed
Bugfix: ripple effect not correct
1 parent 4c6589a commit 681b0c4

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

text-button/src/main/java/top/defaults/view/LayerDrawableProxy.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.graphics.drawable.Drawable;
44
import android.graphics.drawable.LayerDrawable;
5+
import android.graphics.drawable.RippleDrawable;
56
import android.os.Build;
67

78
import java.util.ArrayList;
@@ -35,9 +36,25 @@ public LayerDrawableProxy clear() {
3536

3637
public LayerDrawableProxy addLayer(Drawable layer) {
3738
if (layer == null) return this;
39+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
40+
// Use ripple drawable as layer-list and clear others
41+
if (layer instanceof RippleDrawable) {
42+
this.layers.clear();
43+
}
44+
}
45+
3846
this.layers.add(layer);
39-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
40-
layerDrawable.addLayer(layer);
47+
48+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
49+
if (layer instanceof RippleDrawable) {
50+
layerDrawable = (RippleDrawable) layer;
51+
} else {
52+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
53+
layerDrawable.addLayer(layer);
54+
} else {
55+
layerDrawable = new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
56+
}
57+
}
4158
} else {
4259
layerDrawable = new LayerDrawable(layers.toArray(new Drawable[layers.size()]));
4360
}

text-button/src/main/java/top/defaults/view/RippleEffect.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ public void init(TextButton textButton) {
3838

3939
ColorStateList colorStateList = new ColorStateList(
4040
new int[][]{
41-
new int[]{ android.R.attr.state_pressed },
4241
new int[]{} // this should be empty to make default color as we want
4342
},
4443
new int[]{
45-
textButton.pressedRippleColor,
46-
textButton.defaultRippleColor
44+
textButton.rippleColor
4745
}
4846
);
4947

50-
ownLayer = new RippleDrawableProxy(colorStateList, null, mask).get();
48+
ownLayer = new RippleDrawableProxy(colorStateList, background, mask).get();
5149
textButton.setBackgroundWithProxy(textButton.getBackgroundProxy().addLayer(ownLayer));
5250
}
5351

text-button/src/main/java/top/defaults/view/TextButton.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public class TextButton extends android.support.v7.widget.AppCompatTextView {
4343
@ColorInt int disabledBackgroundColor;
4444
@ColorInt int selectedBackgroundColor;
4545
int backgroundEffectType;
46-
@ColorInt int defaultRippleColor;
47-
@ColorInt int pressedRippleColor;
46+
@ColorInt int rippleColor;
4847
private EffectSet effects;
4948

5049
private Drawable instinctBackground;
@@ -120,8 +119,7 @@ public TextButton(Context context, @Nullable AttributeSet attrs, int defStyleAtt
120119
disabledBackgroundColor = getColor(typedArray, R.styleable.TextButton_disabledBackgroundColor, calculateDisabledColor(defaultBackgroundColor));
121120
selectedBackgroundColor = getColor(typedArray, R.styleable.TextButton_selectedBackgroundColor, calculateSelectedColor(defaultBackgroundColor));
122121
backgroundEffectType = getInt(typedArray, R.styleable.TextButton_backgroundEffect, BACKGROUND_EFFECT_NONE);
123-
defaultRippleColor = getColor(typedArray, R.styleable.TextButton_defaultRippleColor, defaultTextColor);
124-
pressedRippleColor = getColor(typedArray, R.styleable.TextButton_pressedRippleColor, pressedTextColor);
122+
rippleColor = getColor(typedArray, R.styleable.TextButton_rippleColor, defaultTextColor);
125123
typedArray.recycle();
126124

127125
instinctBackground = getBackground();

text-button/src/main/res/values/top_defaults_view_attrs.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<enum name="ripple" value="1"/>
2323
<enum name="animateColor" value="2"/>
2424
</attr>
25-
<attr name="defaultRippleColor" format="color"/>
26-
<attr name="pressedRippleColor" format="color"/>
25+
<attr name="rippleColor" format="color"/>
2726
</declare-styleable>
2827
</resources>

0 commit comments

Comments
 (0)