Skip to content

Commit e180343

Browse files
committed
Updated support for ripple effect
1 parent 86a7b6a commit e180343

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

widgetslib/src/main/kotlin/com/litekite/widget/CircleImageButton.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CircleImageButton @JvmOverloads constructor(
4343
isAntiAlias = true
4444
}
4545
private var bgDrawable: Drawable? = null
46+
private var rippleDrawable: Drawable? = null
4647
private var bgBitmap: Bitmap? = null
4748
private var imgX = 0f
4849
private var imgY = 0f
@@ -58,7 +59,11 @@ class CircleImageButton @JvmOverloads constructor(
5859
R.styleable.CircleImageButton_innerPadding,
5960
0
6061
)
62+
rippleDrawable = typedArray.getDrawable(R.styleable.CircleImageButton_rippleDrawable)
63+
// Recycles the TypedArray
6164
typedArray.recycle()
65+
// Sets ripple drawable as background
66+
super.setBackground(rippleDrawable)
6267
}
6368

6469
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@@ -89,11 +94,15 @@ class CircleImageButton @JvmOverloads constructor(
8994
}
9095

9196
override fun setBackground(background: Drawable?) {
92-
super.setBackground(if (background is RippleDrawable) background else null)
97+
super.setBackground(if (rippleDrawable is RippleDrawable) rippleDrawable else null)
9398
bgDrawable = background
9499
postInvalidate()
95100
}
96101

102+
override fun setForeground(foreground: Drawable?) {
103+
super.setForeground(null)
104+
}
105+
97106
override fun setImageDrawable(drawable: Drawable?) {
98107
super.setImageDrawable(drawable)
99108
postInvalidate()

widgetslib/src/main/res/values/attrs.xml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
1+
<?xml version="1.0" encoding="utf-8"?><!--
32
Copyright 2020 LiteKite Startup. All rights reserved.
43
54
Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +16,13 @@
1716
<resources>
1817

1918
<declare-styleable name="CircleImageButton">
19+
20+
<!--Ripple drawable-->
21+
<attr name="rippleDrawable" format="reference" />
22+
23+
<!--Padding set between background source and image source-->
2024
<attr name="innerPadding" format="dimension" />
25+
2126
</declare-styleable>
2227

2328
</resources>

0 commit comments

Comments
 (0)