Skip to content

Commit

Permalink
Updated support for ripple effect
Browse files Browse the repository at this point in the history
  • Loading branch information
svignesh93 committed Sep 27, 2020
1 parent 86a7b6a commit e180343
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CircleImageButton @JvmOverloads constructor(
isAntiAlias = true
}
private var bgDrawable: Drawable? = null
private var rippleDrawable: Drawable? = null
private var bgBitmap: Bitmap? = null
private var imgX = 0f
private var imgY = 0f
Expand All @@ -58,7 +59,11 @@ class CircleImageButton @JvmOverloads constructor(
R.styleable.CircleImageButton_innerPadding,
0
)
rippleDrawable = typedArray.getDrawable(R.styleable.CircleImageButton_rippleDrawable)
// Recycles the TypedArray
typedArray.recycle()
// Sets ripple drawable as background
super.setBackground(rippleDrawable)
}

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

override fun setBackground(background: Drawable?) {
super.setBackground(if (background is RippleDrawable) background else null)
super.setBackground(if (rippleDrawable is RippleDrawable) rippleDrawable else null)
bgDrawable = background
postInvalidate()
}

override fun setForeground(foreground: Drawable?) {
super.setForeground(null)
}

override fun setImageDrawable(drawable: Drawable?) {
super.setImageDrawable(drawable)
postInvalidate()
Expand Down
9 changes: 7 additions & 2 deletions widgetslib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 LiteKite Startup. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,7 +16,13 @@
<resources>

<declare-styleable name="CircleImageButton">

<!--Ripple drawable-->
<attr name="rippleDrawable" format="reference" />

<!--Padding set between background source and image source-->
<attr name="innerPadding" format="dimension" />

</declare-styleable>

</resources>

0 comments on commit e180343

Please sign in to comment.