Skip to content

Instantly share code, notes, and snippets.

View akexorcist's full-sized avatar
🔥

Akexorcist akexorcist

🔥
View GitHub Profile
@akexorcist
akexorcist / CouponLayout.kt
Last active January 21, 2021 18:15
Build Coupon UI - Setup paint
class CouponLayout : FrameLayout {
private var borderWidth = /* ... */
private var backgroundPathColor = /* ... */
private var backgroundPathColorStateList: ColorStateList? = /* ... */
private var borderPathColor = /* ... */
private var borderPathColorStateList: ColorStateList? = /* ... */
/* ... */
private val borderPaint = Paint().apply { isAntiAlias = true }
private val backgroundPaint = Paint().apply { isAntiAlias = true }
/* ... */
@akexorcist
akexorcist / CouponLayout.kt
Last active January 21, 2021 17:37
Build Coupon UI - Setup view attribute
class CouponLayout : FrameLayout {
companion object {
const val SEMI_CIRCLE_NONE = 0x00
const val SEMI_CIRCLE_LEFT = 0x01
const val SEMI_CIRCLE_TOP = 0x02
const val SEMI_CIRCLE_RIGHT = 0x04
const val SEMI_CIRCLE_BOTTOM = 0x08
const val SEMI_CIRCLE_HORIZONTAL = SEMI_CIRCLE_LEFT or SEMI_CIRCLE_RIGHT
const val SEMI_CIRCLE_VERTICAL = SEMI_CIRCLE_TOP or SEMI_CIRCLE_BOTTOM
const val SEMI_CIRCLE_ALL = SEMI_CIRCLE_HORIZONTAL or SEMI_CIRCLE_VERTICAL
@akexorcist
akexorcist / activity_coupon_book.xml
Last active January 21, 2021 19:38
Build Coupon UI - View implementation
<LinearLayout>
<com.lmwn.library.ui.CouponLayout
android:layout_width="300dp"
android:layout_height="200dp"
app:coupon_backgroundColor="#EEEEEE"
app:coupon_borderColor="#20000000"
app:coupon_borderWidth="4dp"
app:coupon_cornerDirection="top"
app:coupon_cornerRadius="16dp"
app:coupon_semiCircleDirection="horizontal"
@akexorcist
akexorcist / attrs.xml
Last active January 21, 2021 16:59
Build Coupon UI - View attributes
<!-- res/values/attrs.xml -->
<resources>
<declare-styleable name="CouponLayout">
<attr name="coupon_borderWidth" format="dimension" />
<attr name="coupon_cornerRadius" format="dimension" />
<attr name="coupon_semiCircleRadius" format="dimension" />
<attr name="coupon_backgroundColor" format="color|reference" />
<attr name="coupon_borderColor" format="color|reference" />
<attr name="coupon_cornerDirection" format="enum">
<enum name="none" value="0x00" />
@akexorcist
akexorcist / CouponLayout.kt
Last active February 1, 2021 14:56
Build Coupon UI - Prepare the class
class CouponLayout : FrameLayout {
constructor(context: Context) : super(context) {
setup(context, null, 0)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
setup(context, attrs, 0)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
### Start point
x = area_width - (corner_radius + (border_width / 2))
y = border_width / 2
### Top right corner
x1 = area_width - ((corner_radius * 2) + (border_width / 2))
y1 = border_width / 2
x2 = area_width - (border_width / 2)
y2 = (corner_radius * 2) + (border_width / 2)
start_angle = 270
val canvas: Canvas = /* ... */
val areaWidth = canvas.width
val areaHeight = canvas.height
val borderWidth = 2
val cornerRadius = 10
val semiCircleRadius = 20
val path = Path().apply {
/* ... */
// Right edge semi circle
x1 = area_width - ((semi_circle_radius / 2) + (border_width / 2))
y1 = (area_height / 2) - (semi_circle_radius / 2)
x2 = area_width + ((semi_circle_radius / 2) - (border_width / 2))
y2 = (area_height / 2) + (semi_circle_radius / 2)
start_angle = 270
sweep_angle = -180
start_angle = 270
sweep_angle = 90
x1 = area_width - ((corner_radius * 2) + (border_width / 2))
y1 = border_width / 2
x2 = area_width - (border_width / 2)
y2 = (corner_radius * 2) + (border_width / 2)